From 7ec7896938417f9bc429a890199a0db219c43a8e Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Tue, 23 Apr 2013 09:48:26 -0400 Subject: [PATCH] Move clock to bt_trace_descriptor Signed-off-by: Mathieu Desnoyers --- formats/ctf/ctf.c | 4 ++-- formats/ctf/events-private.h | 2 +- .../metadata/ctf-visitor-generate-io-struct.c | 20 +++++++++---------- include/babeltrace/ctf-ir/metadata.h | 2 -- include/babeltrace/format-internal.h | 2 ++ lib/trace-collection.c | 12 ++++------- 6 files changed, 19 insertions(+), 23 deletions(-) diff --git a/formats/ctf/ctf.c b/formats/ctf/ctf.c index 6bb31e55..7b53dd6b 100644 --- a/formats/ctf/ctf.c +++ b/formats/ctf/ctf.c @@ -1655,7 +1655,7 @@ int ctf_open_file_stream_read(struct ctf_trace *td, const char *path, int flags, /* * For now, only a single clock per trace is supported. */ - file_stream->parent.current_clock = td->single_clock; + file_stream->parent.current_clock = td->parent.single_clock; ret = create_stream_packet_index(td, file_stream); if (ret) goto error_index; @@ -1896,7 +1896,7 @@ int ctf_open_mmap_stream_read(struct ctf_trace *td, /* * For now, only a single clock per trace is supported. */ - file_stream->parent.current_clock = td->single_clock; + file_stream->parent.current_clock = td->parent.single_clock; /* Add stream file to stream class */ g_ptr_array_add(file_stream->parent.stream_class->streams, diff --git a/formats/ctf/events-private.h b/formats/ctf/events-private.h index 770012f4..4906c02a 100644 --- a/formats/ctf/events-private.h +++ b/formats/ctf/events-private.h @@ -46,7 +46,7 @@ uint64_t ctf_get_real_timestamp(struct ctf_stream_definition *stream, if (tc->clock_use_offset_avg) tc_offset = tc->single_clock_offset_avg; else - tc_offset = trace->single_clock->offset; + tc_offset = trace->parent.single_clock->offset; ts_nsec = clock_cycles_to_ns(stream->current_clock, timestamp); ts_nsec += tc_offset; /* Add offset */ diff --git a/formats/ctf/metadata/ctf-visitor-generate-io-struct.c b/formats/ctf/metadata/ctf-visitor-generate-io-struct.c index 17479eba..0002fe4f 100644 --- a/formats/ctf/metadata/ctf-visitor-generate-io-struct.c +++ b/formats/ctf/metadata/ctf-visitor-generate-io-struct.c @@ -271,7 +271,7 @@ struct ctf_stream_declaration *trace_stream_lookup(struct ctf_trace *trace, uint static struct ctf_clock *trace_clock_lookup(struct ctf_trace *trace, GQuark clock_name) { - return g_hash_table_lookup(trace->clocks, (gpointer) (unsigned long) clock_name); + return g_hash_table_lookup(trace->parent.clocks, (gpointer) (unsigned long) clock_name); } static @@ -2450,13 +2450,13 @@ int ctf_clock_visit(FILE *fd, int depth, struct ctf_node *node, struct ctf_trace fprintf(fd, "[error] %s: missing name field in clock declaration\n", __func__); goto error; } - if (g_hash_table_size(trace->clocks) > 0) { + if (g_hash_table_size(trace->parent.clocks) > 0) { fprintf(fd, "[error] Only CTF traces with a single clock description are supported by this babeltrace version.\n"); ret = -EINVAL; goto error; } - trace->single_clock = clock; - g_hash_table_insert(trace->clocks, (gpointer) (unsigned long) clock->name, clock); + trace->parent.single_clock = clock; + g_hash_table_insert(trace->parent.clocks, (gpointer) (unsigned long) clock->name, clock); return 0; error: @@ -2490,8 +2490,8 @@ void ctf_clock_default(FILE *fd, int depth, struct ctf_trace *trace) clock->absolute = 0; /* Not an absolute reference across traces */ } - trace->single_clock = clock; - g_hash_table_insert(trace->clocks, (gpointer) (unsigned long) clock->name, clock); + trace->parent.single_clock = clock; + g_hash_table_insert(trace->parent.clocks, (gpointer) (unsigned long) clock->name, clock); } static @@ -2920,8 +2920,8 @@ int ctf_visitor_construct_metadata(FILE *fd, int depth, struct ctf_node *node, printf_verbose("CTF visitor: metadata construction...\n"); trace->byte_order = byte_order; - trace->clocks = g_hash_table_new_full(g_direct_hash, g_direct_equal, - NULL, clock_free); + trace->parent.clocks = g_hash_table_new_full(g_direct_hash, + g_direct_equal, NULL, clock_free); trace->callsites = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, callsite_free); @@ -3023,7 +3023,7 @@ retry: error: bt_free_declaration_scope(trace->root_declaration_scope); g_hash_table_destroy(trace->callsites); - g_hash_table_destroy(trace->clocks); + g_hash_table_destroy(trace->parent.clocks); return ret; } @@ -3122,7 +3122,7 @@ int ctf_destroy_metadata(struct ctf_trace *trace) bt_free_declaration_scope(trace->declaration_scope); g_hash_table_destroy(trace->callsites); - g_hash_table_destroy(trace->clocks); + g_hash_table_destroy(trace->parent.clocks); metadata_stream = container_of(trace->metadata, struct ctf_file_stream, parent); g_free(metadata_stream); diff --git a/include/babeltrace/ctf-ir/metadata.h b/include/babeltrace/ctf-ir/metadata.h index 87ca4923..3d684fb6 100644 --- a/include/babeltrace/ctf-ir/metadata.h +++ b/include/babeltrace/ctf-ir/metadata.h @@ -188,9 +188,7 @@ struct ctf_trace { struct ctf_stream_definition *metadata; char *metadata_string; int metadata_packetized; - GHashTable *clocks; GHashTable *callsites; - struct ctf_clock *single_clock; /* currently supports only one clock */ GPtrArray *event_declarations; /* Array of all the struct bt_ctf_event_decl */ struct declaration_struct *packet_header_decl; diff --git a/include/babeltrace/format-internal.h b/include/babeltrace/format-internal.h index 880a336e..7f3eb5ef 100644 --- a/include/babeltrace/format-internal.h +++ b/include/babeltrace/format-internal.h @@ -43,6 +43,8 @@ struct bt_trace_descriptor { struct bt_context *ctx; struct bt_trace_handle *handle; struct trace_collection *collection; /* Container of this trace */ + GHashTable *clocks; + struct ctf_clock *single_clock; /* currently supports only one clock */ }; #ifdef __cplusplus diff --git a/lib/trace-collection.c b/lib/trace-collection.c index 6743ce6b..b854c974 100644 --- a/lib/trace-collection.c +++ b/lib/trace-collection.c @@ -156,15 +156,11 @@ static void clock_add(gpointer key, gpointer value, gpointer user_data) * convert the index from cycles to real time. */ int bt_trace_collection_add(struct trace_collection *tc, - struct bt_trace_descriptor *td) + struct bt_trace_descriptor *trace) { - struct ctf_trace *trace; - - if (!tc || !td) + if (!tc || !trace) return -EINVAL; - trace = container_of(td, struct ctf_trace, parent); - if (tc->array->len > 1) { struct clock_match clock_match = { .clocks = tc->clocks, @@ -185,8 +181,8 @@ int bt_trace_collection_add(struct trace_collection *tc, } } - g_ptr_array_add(tc->array, td); - trace->parent.collection = tc; + g_ptr_array_add(tc->array, trace); + trace->collection = tc; { struct clock_match clock_match = { -- 2.34.1