Add 6 tools tracking dbus.
[platform/upstream/bcc.git] / tools / dbus-connection-message-size.py
1 #!/usr/bin/python
2
3 from bcc import BPF
4 from time import sleep
5 from ctypes import c_ushort, c_int
6 from sys import argv
7
8 def usage():
9         print("USAGE: %s [--process|histogram]" % argv[0])
10         exit()
11
12 display_mode = 0
13 if len(argv) != 2:
14         usage()
15 if argv[1] == "--histogram":
16         display_mode = 1
17 elif argv[1] != "--process":
18         usage()
19
20
21 b=BPF(src_file="dbus-connection-message-size.c", debug=0)
22 b.attach_uprobe(name="dbus-1", sym="_dbus_connection_message_sent_unlocked", fn_name="dbus_message_size")
23 b.attach_uprobe(name="gio-2.0", sym="g_dbus_message_to_blob", fn_name="g_get_size_pointer")
24 b.attach_uretprobe(name="gio-2.0", sym="g_dbus_message_to_blob", fn_name="g_get_message_size")
25
26 interval = 5
27 loops = 100
28 count = 0
29
30 while (1):
31         count += 1
32         if count == loops:
33                 exit()
34         sleep(interval)
35         print ("\n%d:\n" % count)
36         if display_mode == 0:
37                 stats = b["msg_size"]
38                 for v, p in sorted(stats.items(), key=lambda stats: stats[1].bytes, reverse=True):
39                         print("%10d %20s %20ld" %(v.pid, v.comm.encode('string-escape'), int(p.bytes)))
40         else:
41                 b["msg_size_hist"].print_log2_hist("bytes")