4 # Babeltrace syscall by pid example script
6 # Copyright 2012 EfficiOS Inc.
8 # Author: Danny Serres <danny.serres@efficios.com>
10 # Permission is hereby granted, free of charge, to any person obtaining a copy
11 # of this software and associated documentation files (the "Software"), to deal
12 # in the Software without restriction, including without limitation the rights
13 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 # copies of the Software, and to permit persons to whom the Software is
15 # furnished to do so, subject to the following conditions:
17 # The above copyright notice and this permission notice shall be included in
18 # all copies or substantial portions of the Software.
20 # The script checks the number of events in the trace
21 # and outputs a table and a .svg histogram for the specified
22 # range (microseconds) or the total trace if no range specified.
23 # The graph is generated using the cairoplot module.
25 # The script checks all syscall in the trace and prints a list
26 # showing the number of systemcalls executed by each PID
27 # ordered from greatest to least number of syscalls.
28 # The trace needs PID context (lttng add-context -k -t pid)
31 from babeltrace
import *
32 from output_format_modules
.pprint_table
import pprint_table
as pprint
34 if len(sys
.argv
) < 2 :
35 raise TypeError("Usage: python syscalls_by_pid.py path/to/trace")
38 ret
= ctx
.add_trace(sys
.argv
[1], "ctf")
40 raise IOError("Error adding trace")
45 bp
= IterPos(SEEK_BEGIN
)
46 ctf_it
= ctf
.Iterator(ctx
, bp
)
49 event
= ctf_it
.read_event()
50 while event
is not None:
51 if event
.get_name().find("sys") >= 0:
52 # Getting scope definition
53 sco
= event
.get_top_level_scope(ctf
.scope
.STREAM_EVENT_CONTEXT
)
55 print("ERROR: Cannot get definition scope for {}".format(
59 pid_field
= event
.get_field(sco
, "_pid")
60 pid
= pid_field
.get_int64()
63 print("ERROR: Missing PID info for sched_switch".format(
73 event
= ctf_it
.read_event()
77 # Setting table for output
80 table
.append([data
[item
], item
]) # [count, pid]
81 table
.sort(reverse
= True) # [big count first, pid]
82 for i
in range(len(table
)):
83 table
[i
].reverse() # [pid, big count first]
84 table
.insert(0, ["PID", "SYSCALL COUNT"])
This page took 0.03174 seconds and 4 git commands to generate.