dbus-glib-receiving: new options: --raw and --output 63/271463/5 accepted/tizen_7.0_unified accepted/tizen_7.0_unified_hotfix tizen_7.0 tizen_7.0_hotfix accepted/tizen/7.0/unified/20221110.062846 accepted/tizen/7.0/unified/hotfix/20221116.110623 accepted/tizen/unified/20220713.144350 submit/tizen/20220713.022109 tizen_7.0_m2_release
authorHubert Kowalski <h.kowalski@samsung.com>
Mon, 7 Feb 2022 15:39:25 +0000 (16:39 +0100)
committerAdrian Szyndela <adrian.s@samsung.com>
Wed, 9 Mar 2022 13:48:57 +0000 (14:48 +0100)
Change-Id: Ie63bcea512ff33565b7be2fb87adb063b9244da7

tools/dbus-glib-receiving.c
tools/dbus-glib-receiving.py

index b07ed2f..2b7c983 100644 (file)
  * 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, &timestamp_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, &timestamp_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, &timestamp_s, sizeof(timestamp_s));
+
        return 0;
 }
index f19c585..4279f91 100755 (executable)
@@ -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)