From 4fae0a4507523e3a207674b46b18a5d169f6586a Mon Sep 17 00:00:00 2001 From: Hubert Kowalski Date: Mon, 7 Feb 2022 16:39:25 +0100 Subject: [PATCH] dbus-glib-receiving: new options: --raw and --output Change-Id: Ie63bcea512ff33565b7be2fb87adb063b9244da7 --- tools/dbus-glib-receiving.c | 19 ++++++++++++++++++ tools/dbus-glib-receiving.py | 39 ++++++++++++++++++++++++++++++++++-- 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/tools/dbus-glib-receiving.c b/tools/dbus-glib-receiving.c index b07ed2fe..2b7c9837 100644 --- a/tools/dbus-glib-receiving.c +++ b/tools/dbus-glib-receiving.c @@ -17,6 +17,13 @@ * 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); @@ -122,6 +129,10 @@ int handle_call_in_idle_cb(struct pt_regs *ctx, void *user_data) { 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; } @@ -188,6 +199,10 @@ int handle_task_return_now(struct pt_regs *ctx, void *task) { 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; } @@ -235,5 +250,9 @@ int handle_emit_signal(struct pt_regs *ctx, void *user_data) { 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; } diff --git a/tools/dbus-glib-receiving.py b/tools/dbus-glib-receiving.py index f19c5859..4279f911 100755 --- a/tools/dbus-glib-receiving.py +++ b/tools/dbus-glib-receiving.py @@ -1,5 +1,6 @@ #!/usr/bin/python3 +from asyncore import write from bcc import BPF from time import sleep import argparse @@ -13,6 +14,9 @@ parser.add_argument("--no-method-returns-and-errors", action="store_true", 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, @@ -20,6 +24,7 @@ parser.add_argument("count", nargs="?", default=-1, args = parser.parse_args() interval = int(args.interval) + loop = 0 count = int(args.count) @@ -71,8 +76,38 @@ if not args.no_method_returns_and_errors: # 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) -- 2.34.1