Project

General

Profile

Bug #589 » fix-discarded-inaccuracy.patch

Mathieu Desnoyers, 02/25/2014 05:38 PM

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 ]
*/
static
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);
if (opt_clock_cycles) {
ctf_print_timestamp(fp, stream,
stream->prev_cycles_timestamp);
stream->prev.cycles.end);
fprintf(fp, "] and [");
ctf_print_timestamp(fp, stream,
stream->prev_cycles_timestamp_end);
stream->current.cycles.end);
} else {
ctf_print_timestamp(fp, stream,
stream->prev_real_timestamp);
stream->prev.real.end);
fprintf(fp, "] and [");
ctf_print_timestamp(fp, stream,
stream->prev_real_timestamp_end);
stream->current.real.end);
}
fprintf(fp, "] in trace UUID ");
print_uuid(fp, stream->stream_class->trace->uuid);
......
uint64_t events_discarded_diff;
/* Update packet index time information */
stream->prev_cycles_timestamp_end =
cur_index->ts_cycles.timestamp_end;
stream->prev_cycles_timestamp =
/* Current packet begin/end */
stream->current.real.begin =
cur_index->ts_real.timestamp_begin;
stream->current.cycles.begin =
cur_index->ts_cycles.timestamp_begin;
stream->prev_real_timestamp_end =
stream->current.real.end =
cur_index->ts_real.timestamp_end;
stream->prev_real_timestamp =
cur_index->ts_real.timestamp_begin;
stream->prev_real_timestamp =
stream->real_timestamp;
stream->prev_cycles_timestamp =
stream->cycles_timestamp;
stream->current.cycles.end =
cur_index->ts_cycles.timestamp_end;
/* Update packet index discarded event information */
events_discarded_diff = cur_index->events_discarded;
if (prev_index) {
/* Previous packet begin/end */
stream->prev.cycles.begin =
prev_index->ts_cycles.timestamp_begin;
stream->prev.real.begin =
prev_index->ts_real.timestamp_begin;
stream->prev.cycles.end =
prev_index->ts_cycles.timestamp_end;
stream->prev.real.end =
prev_index->ts_real.timestamp_end;
events_discarded_diff -= prev_index->events_discarded;
/*
* Deal with 32-bit wrap-around if the tracer provided a
......
if (prev_index->events_discarded_len == 32) {
events_discarded_diff = (uint32_t) events_discarded_diff;
}
} else {
/*
* First packet: use current packet info as limits for
* previous packet.
*/
stream->prev.cycles.begin =
stream->prev.cycles.end =
stream->current.cycles.begin;
stream->prev.real.begin =
stream->prev.real.end =
stream->current.real.begin;
}
stream->events_discarded = events_discarded_diff;
}
......
container_of(pos, struct ctf_file_stream, pos);
int ret;
off_t off;
struct packet_index *packet_index;
struct packet_index *packet_index, *prev_index;
switch (whence) {
case SEEK_CUR:
......
switch (whence) {
case SEEK_CUR:
{
struct packet_index *prev_index = NULL;
if (pos->offset == EOF) {
return;
}
assert(pos->cur_index < pos->packet_index->len);
packet_index = &g_array_index(pos->packet_index,
struct packet_index, pos->cur_index);
if (pos->cur_index > 0) {
prev_index = &g_array_index(pos->packet_index,
struct packet_index,
pos->cur_index - 1);
}
ctf_update_current_packet_index(&file_stream->parent,
prev_index, packet_index);
/* The reader will expect us to skip padding */
++pos->cur_index;
break;
}
case SEEK_SET:
{
if (index >= pos->packet_index->len) {
pos->offset = EOF;
return;
}
packet_index = &g_array_index(pos->packet_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);
}
packet_index = &g_array_index(pos->packet_index,
struct packet_index, pos->cur_index);
if (pos->cur_index > 0) {
prev_index = &g_array_index(pos->packet_index,
struct packet_index,
pos->cur_index - 1);
} else {
prev_index = NULL;
}
ctf_update_current_packet_index(&file_stream->parent,
prev_index, packet_index);
if (pos->cur_index >= pos->packet_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.
*/
if ((&file_stream->parent)->stream_class->trace->parent.collection) {
if (file_stream->parent.events_discarded) {
fflush(stdout);
ctf_print_discarded(stderr,
&file_stream->parent);
file_stream->parent.events_discarded = 0;
}
}
packet_index = &g_array_index(pos->packet_index,
struct packet_index,
pos->cur_index);
include/babeltrace/ctf-ir/metadata.h
struct ctf_callsite;
struct ctf_scanner;
struct ctf_stream_packet_limits {
uint64_t begin;
uint64_t end;
};
struct ctf_stream_packet_timestamp {
struct ctf_stream_packet_limits cycles;
struct ctf_stream_packet_limits real;
};
struct ctf_stream_definition {
struct ctf_stream_declaration *stream_class;
uint64_t real_timestamp; /* Current timestamp, in ns */
......
/* Event discarded information */
uint64_t events_discarded;
uint64_t prev_real_timestamp; /* 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_end; /* End-of-last-packet timestamp in cycles */
struct ctf_stream_packet_timestamp prev;
struct ctf_stream_packet_timestamp current;
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_update_current_packet_index(struct ctf_stream_definition *stream,
struct packet_index *prev_index,
struct packet_index *cur_index);
lib/iterator.c
stream_pos->offset = saved_pos->offset;
stream_pos->last_offset = LAST_OFFSET_POISON;
stream->prev_real_timestamp = 0;
stream->prev_real_timestamp_end = 0;
stream->prev_cycles_timestamp = 0;
stream->prev_cycles_timestamp_end = 0;
stream->current.real.begin = 0;
stream->current.real.end = 0;
stream->current.cycles.begin = 0;
stream->current.cycles.end = 0;
stream->prev.real.begin = 0;
stream->prev.real.end = 0;
stream->prev.cycles.begin = 0;
stream->prev.cycles.end = 0;
printf_debug("restored to cur_index = %" PRId64 " and "
"offset = %" PRId64 ", timestamp = %" PRIu64 "\n",
(5-5/5)