From: Julien Desfossez Date: Thu, 5 Apr 2012 15:49:40 +0000 (-0400) Subject: API fix : fill the values for timestamp begin and end X-Git-Tag: v1.0.0-rc1~11 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=30c276af575248a4f83e594c987264f6caa238ba API fix : fill the values for timestamp begin and end The API functions were defined and exported but not implemented. Signed-off-by: Julien Desfossez Signed-off-by: Mathieu Desnoyers --- diff --git a/formats/ctf/ctf.c b/formats/ctf/ctf.c index 91fc20c3..32206166 100644 --- a/formats/ctf/ctf.c +++ b/formats/ctf/ctf.c @@ -87,6 +87,12 @@ void ctf_set_handle(struct trace_descriptor *descriptor, static void ctf_close_trace(struct trace_descriptor *descriptor); +static +uint64_t ctf_timestamp_begin(struct trace_descriptor *descriptor, + struct bt_trace_handle *handle); +static +uint64_t ctf_timestamp_end(struct trace_descriptor *descriptor, + struct bt_trace_handle *handle); static rw_dispatch read_dispatch_table[] = { @@ -119,8 +125,97 @@ struct format ctf_format = { .close_trace = ctf_close_trace, .set_context = ctf_set_context, .set_handle = ctf_set_handle, + .timestamp_begin = ctf_timestamp_begin, + .timestamp_end = ctf_timestamp_end, }; +static +uint64_t ctf_timestamp_begin(struct trace_descriptor *descriptor, + struct bt_trace_handle *handle) +{ + struct ctf_trace *tin; + uint64_t begin = ULLONG_MAX; + int i, j; + + tin = container_of(descriptor, struct ctf_trace, parent); + + if (!tin) + goto error; + + /* for each stream_class */ + for (i = 0; i < tin->streams->len; i++) { + struct ctf_stream_declaration *stream_class; + + stream_class = g_ptr_array_index(tin->streams, i); + /* for each file_stream */ + for (j = 0; j < stream_class->streams->len; j++) { + struct ctf_stream_definition *stream; + struct ctf_file_stream *cfs; + struct ctf_stream_pos *stream_pos; + struct packet_index *index; + + stream = g_ptr_array_index(stream_class->streams, j); + cfs = container_of(stream, struct ctf_file_stream, + parent); + stream_pos = &cfs->pos; + + index = &g_array_index(stream_pos->packet_index, + struct packet_index, 0); + if (index->timestamp_begin < begin) + begin = index->timestamp_begin; + } + } + + return begin; + +error: + return -1ULL; +} + +static +uint64_t ctf_timestamp_end(struct trace_descriptor *descriptor, + struct bt_trace_handle *handle) +{ + struct ctf_trace *tin; + uint64_t end = 0; + int i, j; + + tin = container_of(descriptor, struct ctf_trace, parent); + + if (!tin) + goto error; + + /* for each stream_class */ + for (i = 0; i < tin->streams->len; i++) { + struct ctf_stream_declaration *stream_class; + + stream_class = g_ptr_array_index(tin->streams, i); + /* for each file_stream */ + for (j = 0; j < stream_class->streams->len; j++) { + struct ctf_stream_definition *stream; + struct ctf_file_stream *cfs; + struct ctf_stream_pos *stream_pos; + struct packet_index *index; + + stream = g_ptr_array_index(stream_class->streams, j); + cfs = container_of(stream, struct ctf_file_stream, + parent); + stream_pos = &cfs->pos; + + index = &g_array_index(stream_pos->packet_index, + struct packet_index, + stream_pos->packet_index->len - 1); + if (index->timestamp_end > end) + end = index->timestamp_end; + } + } + + return end; + +error: + return -1ULL; +} + /* * Update stream current timestamp, keep at clock frequency. */ diff --git a/include/babeltrace/format.h b/include/babeltrace/format.h index b67dd5dc..c3e7a209 100644 --- a/include/babeltrace/format.h +++ b/include/babeltrace/format.h @@ -62,6 +62,10 @@ struct format { struct bt_context *ctx); void (*set_handle)(struct trace_descriptor *descriptor, struct bt_trace_handle *handle); + uint64_t (*timestamp_begin)(struct trace_descriptor *descriptor, + struct bt_trace_handle *handle); + uint64_t (*timestamp_end)(struct trace_descriptor *descriptor, + struct bt_trace_handle *handle); }; extern struct format *bt_lookup_format(bt_intern_str qname); diff --git a/include/babeltrace/trace-handle.h b/include/babeltrace/trace-handle.h index 31877ee1..65171e70 100644 --- a/include/babeltrace/trace-handle.h +++ b/include/babeltrace/trace-handle.h @@ -39,14 +39,14 @@ struct bt_ctf_event; const char *bt_trace_handle_get_path(struct bt_context *ctx, int handle_id); /* - * bt_trace_handle_get_timestamp_begin : returns the beginning timestamp + * bt_trace_handle_get_timestamp_begin : returns the creation time of the buffers * of a trace. */ uint64_t bt_trace_handle_get_timestamp_begin(struct bt_context *ctx, int handle_id); /* - * bt_trace_handle_get_timestamp_end : returns the end timestamp of a - * trace. + * bt_trace_handle_get_timestamp_end : returns the destruction timestamp of the + * buffers of a trace. */ uint64_t bt_trace_handle_get_timestamp_end(struct bt_context *ctx, int handle_id); diff --git a/lib/context.c b/lib/context.c index dbab3375..d3232fe9 100644 --- a/lib/context.c +++ b/lib/context.c @@ -104,6 +104,8 @@ int bt_context_add_trace(struct bt_context *ctx, const char *path, } handle->format = fmt; handle->td = td; + handle->timestamp_begin = fmt->timestamp_begin(td, handle); + handle->timestamp_end = fmt->timestamp_end(td, handle); strncpy(handle->path, path, PATH_MAX); handle->path[PATH_MAX - 1] = '\0';