]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
rtla: Count missed trace events
authorTomas Glozar <tglozar@redhat.com>
Thu, 23 Jan 2025 14:23:36 +0000 (15:23 +0100)
committerSteven Rostedt (Google) <rostedt@goodmis.org>
Fri, 24 Jan 2025 18:46:16 +0000 (13:46 -0500)
Add function collect_missed_events to trace.c to act as a callback for
tracefs_follow_missed_events, summing the number of total missed events
into a new field missing_events of struct trace_instance.

In case record->missed_events is negative, trace->missed_events is set
to UINT64_MAX to signify an unknown number of events was missed.

The callback is activated on initialization of the trace instance.

Cc: John Kacur <jkacur@redhat.com>
Cc: Luis Goncalves <lgoncalv@redhat.com>
Cc: Gabriele Monaco <gmonaco@redhat.com>
Link: https://lore.kernel.org/20250123142339.990300-2-tglozar@redhat.com
Signed-off-by: Tomas Glozar <tglozar@redhat.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
tools/tracing/rtla/src/trace.c
tools/tracing/rtla/src/trace.h

index 80b14b8a3c2ed7a26fd40c9a4c66a75f1b1ee8a3..94e490782f1414e24f64d37e61ae04489f3f7b4b 100644 (file)
@@ -126,6 +126,31 @@ collect_registered_events(struct tep_event *event, struct tep_record *record,
        return 0;
 }
 
+/*
+ * collect_missed_events - record number of missed events
+ *
+ * If rtla cannot keep up with events generated by tracer, events are going
+ * to fall out of the ring buffer.
+ * Collect how many events were missed so it can be reported to the user.
+ */
+static int
+collect_missed_events(struct tep_event *event, struct tep_record *record,
+                     int cpu, void *context)
+{
+       struct trace_instance *trace = context;
+
+       if (trace->missed_events == UINT64_MAX)
+               return 0;
+
+       if (record->missed_events > 0)
+               trace->missed_events += record->missed_events;
+       else
+               /* Events missed but no data on how many */
+               trace->missed_events = UINT64_MAX;
+
+       return 0;
+}
+
 /*
  * trace_instance_destroy - destroy and free a rtla trace instance
  */
@@ -181,6 +206,15 @@ int trace_instance_init(struct trace_instance *trace, char *tool_name)
         */
        tracefs_trace_off(trace->inst);
 
+       /*
+        * Collect the number of events missed due to tracefs buffer
+        * overflow.
+        */
+       trace->missed_events = 0;
+       tracefs_follow_missed_events(trace->inst,
+                                    collect_missed_events,
+                                    trace);
+
        return 0;
 
 out_err:
index c3e03f7df770d5af20264e7e619c8f55189a8556..a6e88709604b0433e096b765371c7aa3f1f354e3 100644 (file)
@@ -17,6 +17,7 @@ struct trace_instance {
        struct tracefs_instance         *inst;
        struct tep_handle               *tep;
        struct trace_seq                *seq;
+       unsigned long long              missed_events;
 };
 
 int trace_instance_init(struct trace_instance *trace, char *tool_name);