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