[lttng-dev] [BABELTRACE PATCH] Use default if there is no clock declaration

Juha Niskanen juniskane at gmail.com
Sun Feb 12 16:57:25 EST 2012


In absence of clock description in metadata, use a default clock
source which increments once per nanosecond.

Without this patch, the converter crashes when given old traces
that are lacking clock description block.

Signed-off-by: Juha Niskanen <juniskane at gmail.com>
---
 .../ctf/metadata/ctf-visitor-generate-io-struct.c  |   29 +++++++++++++++----
 1 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/formats/ctf/metadata/ctf-visitor-generate-io-struct.c b/formats/ctf/metadata/ctf-visitor-generate-io-struct.c
index 2d3361c..8de2cae 100644
--- a/formats/ctf/metadata/ctf-visitor-generate-io-struct.c
+++ b/formats/ctf/metadata/ctf-visitor-generate-io-struct.c
@@ -2302,6 +2302,20 @@ error:
 }
 
 static
+void clock_default_monotonic(struct ctf_trace *trace)
+{
+	struct ctf_clock *clock;
+
+	clock = g_new0(struct ctf_clock, 1);
+	/* Default clock frequency is set to 1000000000 */
+	clock->freq = 1000000000ULL;
+	clock->name = g_quark_from_string("monotonic");
+
+	trace->single_clock = clock;
+	g_hash_table_insert(trace->clocks, (gpointer) (unsigned long) clock->name, clock);
+}
+
+static
 void clock_free(gpointer data)
 {
 	struct ctf_clock *clock = data;
@@ -2516,12 +2530,15 @@ retry:
 			 * declarations need to query clock hash table,
 			 * so clock need to be treated first.
 			 */
-			cds_list_for_each_entry(iter, &node->u.root.clock, siblings) {
-				ret = ctf_clock_visit(fd, depth + 1, iter,
-						      trace);
-				if (ret) {
-					fprintf(fd, "[error] %s: clock declaration error\n", __func__);
-					goto error;
+			if (cds_list_empty(&node->u.root.clock))
+				clock_default_monotonic(trace);
+			else {
+				cds_list_for_each_entry(iter, &node->u.root.clock, siblings) {
+					ret = ctf_clock_visit(fd, depth + 1, iter, trace);
+					if (ret) {
+						fprintf(fd, "[error] %s: clock declaration error\n", __func__);
+						goto error;
+					}
 				}
 			}
 			env_clock_done = 1;
-- 
1.7.4.1




More information about the lttng-dev mailing list