3 # Babeltrace time of softirqs 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 the trace for the amount of time
25 # spent from each softirq_raise to softirq_exit.
26 # It prints out the min, max (with timestamp),
27 # average times, the standard deviation and the total count.
28 # Using the cairoplot module, a .svg graph is also outputted
29 # showing the taken time in function of the time since the
30 # beginning of the trace.
33 from output_format_modules
import cairoplot
34 from babeltrace
import *
37 raise TypeError("Usage: python softirqtimes.py path/to/trace")
40 ret
= ctx
.add_trace(sys
.argv
[1], "ctf")
42 raise IOError("Error adding trace")
46 max_time
= (0.0, 0.0) # (val, ts)
48 # tmp template: {(cpu_id, vec):TS raise}
53 bp
= IterPos(SEEK_BEGIN
)
54 ctf_it
= ctf
.Iterator(ctx
, bp
)
57 event
= ctf_it
.read_event()
58 start_time
= event
.get_timestamp()
59 while(event
is not None):
61 event_name
= event
.get_name()
65 if event_name
== 'softirq_raise' or event_name
== 'softirq_exit':
66 # Recover cpu_id and vec values to make a key to tmp
68 scope
= event
.get_top_level_scope(ctf
.scope
.STREAM_PACKET_CONTEXT
)
69 field
= event
.get_field(scope
, "cpu_id")
70 cpu_id
= field
.get_uint64()
72 print("ERROR: Missing cpu_id info for {}".format(
76 scope
= event
.get_top_level_scope(ctf
.scope
.EVENT_FIELDS
)
77 field
= event
.get_field(scope
, "_vec")
78 vec
= field
.get_uint64()
80 print("ERROR: Missing vec info for {}".format(
85 if event_name
== 'softirq_raise' and not error
:
86 # Add timestamp to tmp
88 # If key already exists
92 key
= (cpu_id
, vec
, i
)
100 tmp
[key
] = event
.get_timestamp()
102 if event_name
== 'softirq_exit' and not error
:
103 # Saving data for output
107 while i
<= largest_val
:
108 key
= (key
[0], key
[1], i
)
113 raise_timestamp
= tmp
[key
]
114 time_data
= event
.get_timestamp() - tmp
.pop(key
)
115 if time_data
> max_time
[0]:
116 # max_time = (val, ts)
117 max_time
= (time_data
, raise_timestamp
)
118 time_taken
.append(time_data
)
119 graph_data
.append((raise_timestamp
- start_time
, time_data
))
125 event
= ctf_it
.read_event()
130 # Standard dev. calc.
132 mean
= sum(time_taken
)/float(len(time_taken
))
133 except ZeroDivisionError:
134 raise TypeError("empty data")
135 deviations_squared
= []
137 deviations_squared
.append(math
.pow((x
- mean
), 2))
139 stddev
= math
.sqrt(sum(deviations_squared
) / (len(deviations_squared
) - 1))
140 except ZeroDivisionError:
144 print("AVG TIME: {} ns".format(mean
))
145 print("MIN TIME: {} ns".format(min(time_taken
)))
146 print("MAX TIME: {} ns, TS: {}".format(max_time
[0], max_time
[1]))
147 print("STD DEV: {}".format(stddev
))
148 print("TOTAL COUNT: {}".format(len(time_taken
)))
151 cairoplot
.scatter_plot ( 'softirqtimes.svg', data
= graph_data
,
152 width
= 5000, height
= 4000, border
= 20, axis
= True,
153 grid
= True, series_colors
= ["red"] )
This page took 0.034364 seconds and 5 git commands to generate.