Skip to content

Commit f101dd5

Browse files
committed
feat(plugin): issue warning if trace clock is not monotonic
We don't know for sure which trace clock is used by LTTng US, but if the trace.dat (ftrace) clock is not monotonic, it is likely that the traces are misaligned. Issue a warning in this case, but proceed. Signed-off-by: Felix Moessbauer <[email protected]>
1 parent f9bb29d commit f101dd5

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/bt-ftrace-source.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@ static void create_metadata_and_stream(bt_self_component *self_component,
215215
char NAME_BUF[32];
216216
const uint64_t mip_version =
217217
bt_self_component_get_graph_mip_version(self_component);
218+
/* assume monotonic clock if not provided otherwise */
219+
const char *traceclock = "mono";
220+
bt_bool clock_is_monotonic = true;
218221

219222
/* Create a default trace class */
220223
bt_trace_class *trace_class = bt_trace_class_create(self_component);
@@ -223,10 +226,19 @@ static void create_metadata_and_stream(bt_self_component *self_component,
223226
bt_stream_class *stream_class = bt_stream_class_create(trace_class);
224227
bt_stream_class_set_name(stream_class, "ftrace-stream");
225228

229+
#if WITH_TRACE_CMD_PRIVATE_SYMBOLS
230+
traceclock = tracecmd_get_trace_clock(ftrace_in->tc_input);
231+
#endif
226232
/* Create a default clock class (1 GHz frequency) */
227233
bt_clock_class *clock_class = bt_clock_class_create(self_component);
228-
bt_clock_class_set_name(clock_class, "monotonic");
229-
bt_clock_class_set_description(clock_class, "Monotonic Clock");
234+
if (strcmp(traceclock, "mono") == 0 ||
235+
strcmp(traceclock, "mono_raw") == 0) {
236+
bt_clock_class_set_name(clock_class, "monotonic");
237+
bt_clock_class_set_description(clock_class, "Monotonic Clock");
238+
} else {
239+
clock_is_monotonic = false;
240+
bt_clock_class_set_name(clock_class, traceclock);
241+
}
230242
/* make the clock compatible with an LTTng US clock definition */
231243
if (ftrace_in->clock_offset_ns) {
232244
bt_clock_class_set_offset(clock_class,
@@ -248,6 +260,12 @@ static void create_metadata_and_stream(bt_self_component *self_component,
248260
bt_clock_class_set_uid(clock_class, ftrace_in->clock_uid);
249261
#endif
250262
}
263+
if (!clock_is_monotonic) {
264+
BT_FTRACE_LOG_WARNING(
265+
ftrace_in->log_level,
266+
"ftrace used non-monotonic clock \"%s\". Traces are likely misaligned.",
267+
traceclock);
268+
}
251269
}
252270

253271
/*

src/trace-cmd-private.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@
1111
struct tracecmd_input;
1212

1313
const char *tracecmd_get_uname(struct tracecmd_input *handle);
14+
const char *tracecmd_get_trace_clock(struct tracecmd_input *handle);
1415

1516
#endif

0 commit comments

Comments
 (0)