* 3. Measure the time between 1 and 2.
*/
+
+/* This table is created to send data to python script.
+Script will use it for .csv creation or output on std.
+*/
+
+BPF_PERF_OUTPUT(timestamp_out);
+
/* This hashmap contains mapping from a message pointer to a timestamp.
* It is meant to keep timestamps of detection of message receiving. */
BPF_HASH(msg_on_worker_received, key_pointer_t, timestamp_value_t);
timings.increment(bpf_log2l(ns_to_us(timestamp)));
average_add(timestamp);
+ timestamp_value_t timestamp_s;
+ timestamp_s.timestamp = timestamp;
+ timestamp_out.perf_submit(ctx, ×tamp_s, sizeof(timestamp_s));
+
return 0;
}
timings.increment(bpf_log2l(ns_to_us(timestamp)));
average_add(timestamp);
+ timestamp_value_t timestamp_s;
+ timestamp_s.timestamp = timestamp;
+ timestamp_out.perf_submit(ctx, ×tamp_s, sizeof(timestamp_s));
+
return 0;
}
timings.increment(bpf_log2l(ns_to_us(timestamp)));
average_add(timestamp);
+ timestamp_value_t timestamp_s;
+ timestamp_s.timestamp = timestamp;
+ timestamp_out.perf_submit(ctx, ×tamp_s, sizeof(timestamp_s));
+
return 0;
}
#!/usr/bin/python3
+from asyncore import write
from bcc import BPF
from time import sleep
import argparse
help="disable detecting D-Bus method returns and errors")
parser.add_argument("--no-signals", action="store_true",
help="disable detecting D-Bus signals")
+parser.add_argument("--raw", action="store_true",
+ help="put data into .csv file")
+parser.add_argument("-o", "--output", default=None)
parser.add_argument("interval", nargs="?", default=2,
help="output interval, in seconds")
parser.add_argument("count", nargs="?", default=-1,
args = parser.parse_args()
interval = int(args.interval)
+
loop = 0
count = int(args.count)
# thus, it records only timings for the very first subscriber that receives the signal
b.attach_uprobe(name="gio-2.0", sym="emit_signal_instance_in_idle_cb", fn_name="handle_emit_signal")
-# GO!
-print("Hit Ctrl-C to end.")
+# ***** Create .csv with data
+# process event put data into .csv file while in --raw mode.
+def new_timestamp_to_file(cpu, data, size):
+ # this func is triggered when new timestamp is put into timestamp_out
+ # buffer. Data is then put into .csv file
+ event = b["timestamp_out"].event(data)
+ global f
+ f.write(str(event.timestamp) + '\n')
+
+def new_timestamp_to_std(cpu, data, size):
+ # this func is triggered when new timestamp is put into timestamp_out
+ # buffer. Data is displayed on std output.
+ event = b["timestamp_out"].event(data)
+ print("Measured Latency: " + str(event.timestamp) + "\n")
+
+print("Hit Ctrl-C to end.\n")
+
+if args.raw :
+ # loop with callback to print_event
+ if args.output != None :
+ print("File mode active\n")
+ b["timestamp_out"].open_perf_buffer(new_timestamp_to_file)
+ with open(args.output, "w") as f:
+ f.write("Latency\n")
+ while (1):
+ b.perf_buffer_poll()
+ else:
+ print("STD mode active\n")
+ b["timestamp_out"].open_perf_buffer(new_timestamp_to_std)
+
+ while (1):
+ b.perf_buffer_poll()
while (1):
sleep(interval)