Project

General

Profile

Bug #589 » patch-babeltrace-events-discarded.patch

Mathieu Desnoyers, 11/06/2013 09:41 AM

View differences:

formats/ctf-text/ctf-text.c
return -EINVAL;
}
/* Print events discarded */
if (stream->events_discarded) {
fflush(pos->fp);
ctf_print_discarded(stderr, stream, 0);
stream->events_discarded = 0;
}
if (stream->has_timestamp) {
set_field_names_print(pos, ITEM_HEADER);
if (pos->print_names)
formats/ctf/ctf.c
uint64_t oldval, newval, updateval;
if (unlikely(integer_declaration->len == 64)) {
stream->prev_cycles_timestamp = stream->cycles_timestamp;
stream->cycles_timestamp = integer_definition->value._unsigned;
stream->prev_real_timestamp = ctf_get_real_timestamp(stream,
stream->prev_cycles_timestamp);
stream->real_timestamp = ctf_get_real_timestamp(stream,
stream->cycles_timestamp);
return;
......
updateval = stream->cycles_timestamp;
updateval &= ~((1ULL << integer_declaration->len) - 1);
updateval += newval;
stream->prev_cycles_timestamp = stream->cycles_timestamp;
stream->cycles_timestamp = updateval;
/* convert to real timestamp */
stream->prev_real_timestamp = ctf_get_real_timestamp(stream,
stream->prev_cycles_timestamp);
stream->real_timestamp = ctf_get_real_timestamp(stream,
stream->cycles_timestamp);
}
......
fprintf(fp, "%x", (unsigned int) uuid[i]);
}
void ctf_print_discarded(FILE *fp, struct ctf_stream_definition *stream,
int end_stream)
/*
* Discarded events can be either:
* - discarded after end of previous buffer due to buffer full:
* happened within range: [ prev_timestamp_end, timestamp_begin ]
* - discarded within current buffer due to either event too large or
* nested wrap-around:
* happened within range: [ timestamp_begin, timestamp_end ]
*
* Given we have discarded counters of those two types merged into the
* events_discarded counter, we need to use the union of those ranges:
* [ prev_timestamp_end, timestamp_end ]
*/
void ctf_print_discarded(FILE *fp, struct ctf_stream_definition *stream)
{
fprintf(fp, "[warning] Tracer discarded %" PRIu64 " events %sbetween [",
stream->events_discarded,
end_stream ? "at end of stream " : "");
fprintf(fp, "[warning] Tracer discarded %" PRIu64 " events between [",
stream->events_discarded_diff);
if (opt_clock_cycles) {
ctf_print_timestamp(fp, stream,
stream->prev_cycles_timestamp);
stream->prev_cycles_timestamp_end);
fprintf(fp, "] and [");
ctf_print_timestamp(fp, stream,
stream->prev_cycles_timestamp_end);
stream->cycles_timestamp_end);
} else {
ctf_print_timestamp(fp, stream,
stream->prev_real_timestamp);
stream->prev_real_timestamp_end);
fprintf(fp, "] and [");
ctf_print_timestamp(fp, stream,
stream->prev_real_timestamp_end);
stream->real_timestamp_end);
}
fprintf(fp, "] in trace UUID ");
print_uuid(fp, stream->stream_class->trace->uuid);
......
switch (whence) {
case SEEK_CUR:
{
uint64_t events_discarded_diff;
if (pos->offset == EOF) {
return;
}
assert(pos->cur_index < pos->packet_cycles_index->len);
assert(pos->cur_index < pos->packet_real_index->len);
/* For printing discarded event count */
packet_index = &g_array_index(pos->packet_cycles_index,
struct packet_index, pos->cur_index);
file_stream->parent.prev_cycles_timestamp_end =
packet_index->timestamp_end;
file_stream->parent.prev_cycles_timestamp =
packet_index->timestamp_begin;
packet_index = &g_array_index(pos->packet_real_index,
struct packet_index, pos->cur_index);
file_stream->parent.prev_real_timestamp_end =
packet_index->timestamp_end;
file_stream->parent.prev_real_timestamp =
packet_index->timestamp_begin;
events_discarded_diff = packet_index->events_discarded;
if (pos->cur_index > 0) {
packet_index = &g_array_index(pos->packet_real_index,
struct packet_index,
pos->cur_index - 1);
events_discarded_diff -= packet_index->events_discarded;
/*
* Deal with 32-bit wrap-around if the
* tracer provided a 32-bit field.
*/
if (packet_index->events_discarded_len == 32) {
events_discarded_diff = (uint32_t) events_discarded_diff;
}
}
file_stream->parent.events_discarded = events_discarded_diff;
file_stream->parent.prev_real_timestamp = file_stream->parent.real_timestamp;
file_stream->parent.prev_cycles_timestamp = file_stream->parent.cycles_timestamp;
/* The reader will expect us to skip padding */
++pos->cur_index;
break;
......
}
packet_index = &g_array_index(pos->packet_cycles_index,
struct packet_index, index);
pos->last_events_discarded = packet_index->events_discarded;
pos->cur_index = index;
file_stream->parent.prev_real_timestamp = 0;
file_stream->parent.prev_real_timestamp_end = 0;
file_stream->parent.prev_cycles_timestamp = 0;
file_stream->parent.prev_cycles_timestamp_end = 0;
break;
default:
assert(0);
}
if (pos->cur_index >= pos->packet_real_index->len) {
/*
* We need to check if we are in trace read or
* called from packet indexing. In this last
* case, the collection is not there, so we
* cannot print the timestamps.
*/
if ((&file_stream->parent)->stream_class->trace->parent.collection) {
/*
* When a stream reaches the end of the
* file, we need to show the number of
* events discarded ourselves, because
* there is no next event scheduled to
* be printed in the output.
*/
if (file_stream->parent.events_discarded) {
fflush(stdout);
ctf_print_discarded(stderr,
&file_stream->parent,
1);
file_stream->parent.events_discarded = 0;
}
}
pos->offset = EOF;
return;
}
/*
* We need to check if we are in trace read or called
* from packet indexing. In this last case, the
* collection is not there, so we cannot print the
* timestamps.
*/
packet_index = &g_array_index(pos->packet_real_index,
struct packet_index, pos->cur_index);
if ((&file_stream->parent)->stream_class->trace->parent.collection
&& packet_index->events_discarded_diff) {
/* For printing discarded event count: current packet */
packet_index = &g_array_index(pos->packet_cycles_index,
struct packet_index, pos->cur_index);
file_stream->parent.cycles_timestamp_end =
packet_index->timestamp_end;
file_stream->parent.cycles_timestamp_begin =
packet_index->timestamp_begin;
packet_index = &g_array_index(pos->packet_real_index,
struct packet_index, pos->cur_index);
file_stream->parent.prev_real_timestamp_end =
packet_index->timestamp_end;
file_stream->parent.prev_real_timestamp_begin =
packet_index->timestamp_begin;
file_stream->parent.events_discarded_diff =
packet_index->events_discarded_diff;
/* For iterator */
file_stream->pos.events_discarded_diff =
packet_index->events_discarded_diff;
if (pos->cur_index > 0) {
/* For printing discarded event count: previous packet */
packet_index = &g_array_index(pos->packet_cycles_index,
struct packet_index, pos->cur_index - 1);
file_stream->parent.prev_cycles_timestamp_end =
packet_index->timestamp_end;
file_stream->parent.prev_cycles_timestamp_begin =
packet_index->timestamp_begin;
packet_index = &g_array_index(pos->packet_real_index,
struct packet_index, pos->cur_index - 1);
file_stream->parent.prev_real_timestamp_end =
packet_index->timestamp_end;
file_stream->parent.prev_real_timestamp_begin =
packet_index->timestamp_begin;
} else {
/* For printing discarded event count: start of stream */
file_stream->parent.prev_cycles_timestamp_end =
file_stream->parent.cycles_timestamp_end;
file_stream->parent.prev_cycles_timestamp_begin =
file_stream->parent.cycles_timestamp_begin;
file_stream->parent.prev_real_timestamp_end =
file_stream->parent.prev_real_timestamp_end;
file_stream->parent.prev_real_timestamp_begin =
file_stream->parent.prev_real_timestamp_begin;
}
fflush(stdout);
ctf_print_discarded(stderr, &file_stream->parent);
}
packet_index = &g_array_index(pos->packet_cycles_index,
struct packet_index,
pos->cur_index);
......
packet_index.timestamp_end = 0;
packet_index.events_discarded = 0;
packet_index.events_discarded_len = 0;
packet_index.events_discarded_diff = 0;
/* read and check header, set stream id (and check) */
if (file_stream->parent.trace_packet_header) {
......
len_index = bt_struct_declaration_lookup_field_index(file_stream->parent.stream_packet_context->declaration, g_quark_from_static_string("events_discarded"));
if (len_index >= 0) {
struct bt_definition *field;
uint64_t events_discarded_diff;
field = bt_struct_definition_get_field_from_index(file_stream->parent.stream_packet_context, len_index);
packet_index.events_discarded = bt_get_unsigned_int(field);
packet_index.events_discarded_len = bt_get_int_len(field);
events_discarded_diff = packet_index.events_discarded;
if (file_stream->pos.packet_cycles_index->len > 0) {
struct packet_index *last_packet_index;
last_packet_index = &g_array_index(pos->packet_cycles_index,
struct packet_index,
file_stream->pos.packet_cycles_index->len - 1);
events_discarded_diff -= last_packet_index->events_discarded;
/*
* Deal with 32-bit wrap-around if the
* tracer provided a 32-bit field.
*/
if (last_packet_index->events_discarded_len == 32) {
events_discarded_diff = (uint32_t) events_discarded_diff;
}
}
packet_index.events_discarded_diff = events_discarded_diff;
}
} else {
/* Use file size for packet size */
formats/ctf/iterator.c
packet_index = &g_array_index(file_stream->pos.packet_cycles_index,
struct packet_index, file_stream->pos.cur_index);
iter->events_lost = 0;
if (packet_index && packet_index->events_discarded >
file_stream->pos.last_events_discarded) {
if (packet_index && file_stream->pos.events_discarded_diff) {
if (flags)
*flags |= BT_ITER_FLAG_LOST_EVENTS;
iter->events_lost += packet_index->events_discarded -
file_stream->pos.last_events_discarded;
file_stream->pos.last_events_discarded =
packet_index->events_discarded;
iter->events_lost += file_stream->pos.events_discarded_diff;
file_stream->pos.events_discarded_diff = 0;
}
if (ret->parent->stream->stream_id > iter->callbacks->len)
include/babeltrace/ctf-ir/metadata.h
struct ctf_clock *current_clock;
/* Event discarded information */
uint64_t events_discarded;
uint64_t prev_real_timestamp; /* Start-of-last-packet timestamp in ns */
uint64_t events_discarded_diff;
/* Current packet */
uint64_t real_timestamp_begin; /* Start-of-current-packet timestamp in ns */
uint64_t real_timestamp_end; /* End-of-current-packet timestamp in ns */
uint64_t cycles_timestamp_begin; /* Start-of-current-packet timestamp in cycles */
uint64_t cycles_timestamp_end; /* End-of-current-packet timestamp in cycles */
/* Last packet */
uint64_t prev_real_timestamp_begin; /* Start-of-last-packet timestamp in ns */
uint64_t prev_real_timestamp_end; /* End-of-last-packet timestamp in ns */
uint64_t prev_cycles_timestamp; /* Start-of-last-packet timestamp in cycles */
uint64_t prev_cycles_timestamp_begin; /* Start-of-last-packet timestamp in cycles */
uint64_t prev_cycles_timestamp_end; /* End-of-last-packet timestamp in cycles */
char path[PATH_MAX]; /* Path to stream. '\0' for mmap traces */
};
include/babeltrace/ctf/events-internal.h
uint64_t events_lost;
};
void ctf_print_discarded(FILE *fp, struct ctf_stream_definition *stream,
int end_stream);
void ctf_print_discarded(FILE *fp, struct ctf_stream_definition *stream);
#endif /*_BABELTRACE_CTF_EVENTS_INTERNAL_H */
include/babeltrace/ctf/types.h
uint64_t timestamp_end;
uint64_t events_discarded;
uint64_t events_discarded_len; /* length of the field, in bits */
uint64_t events_discarded_diff;
};
/*
......
int64_t offset; /* offset from base, in bits. EOF for end of file. */
int64_t last_offset; /* offset before the last read_event */
uint64_t cur_index; /* current index in packet index */
uint64_t last_events_discarded; /* last known amount of event discarded */
void (*packet_seek)(struct bt_stream_pos *pos, size_t index,
int whence); /* function called to switch packet */
int dummy; /* dummy position, for length calculation */
struct bt_stream_callbacks *cb; /* Callbacks registered for iterator. */
uint64_t events_discarded_diff;
};
static inline
lib/iterator.c
stream_pos->offset = saved_pos->offset;
stream_pos->last_offset = LAST_OFFSET_POISON;
stream->prev_real_timestamp = 0;
stream->real_timestamp_begin = 0;
stream->real_timestamp_end = 0;
stream->cycles_timestamp_begin = 0;
stream->cycles_timestamp_end = 0;
stream->prev_real_timestamp_begin = 0;
stream->prev_real_timestamp_end = 0;
stream->prev_cycles_timestamp = 0;
stream->prev_cycles_timestamp_begin = 0;
stream->prev_cycles_timestamp_end = 0;
printf_debug("restored to cur_index = %" PRId64 " and "
(4-4/5)