09618cb7daa83300f98c15ee2d4f6d001f3b5827
4 # Babeltrace histogram 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.
26 from babeltrace
import *
27 from output_format_modules
import cairoplot
28 from output_format_modules
.pprint_table
import pprint_table
as pprint
30 # ------------------------------------------------
33 # number of intervals:
34 nbDiv
= 25 # Should not be over 150
35 # for usable graph output
37 # table output stream (file-like object):
39 # -------------------------------------------------
41 if len(sys
.argv
) < 2 or len(sys
.argv
) > 4:
42 raise TypeError("Usage: python histogram.py [ start_time [end_time] ] path/to/trace")
45 ret
= ctx
.add_trace(sys
.argv
[len(sys
.argv
)-1], "ctf")
47 raise IOError("Error adding trace")
49 # Check when to start/stop graphing
54 beginTime
= float(sys
.argv
[1])
56 if len(sys
.argv
) == 4:
60 bp
= IterPos(SEEK_BEGIN
)
61 ctf_it
= ctf
.Iterator(ctx
, bp
)
64 event
= ctf_it
.read_event()
65 start_time
= event
.get_timestamp()
69 while(event
is not None):
71 time
= (event
.get_timestamp() - start_time
)/1000.0
80 event
= ctf_it
.read_event()
83 if time
> float(sys
.argv
[2]):
86 # Counting events per timestamp:
96 event
= ctf_it
.read_event()
100 # Setting data for output
101 interval
= (time
- beginTime
)/nbDiv
102 div_begin_time
= beginTime
103 div_end_time
= beginTime
+ interval
106 # Prefix for string sorting, considering
107 # there should not be over 150 intervals.
108 # This would work up to 9999 intervals.
109 # If needed, add zeros.
112 while div_end_time
<= time
:
113 key
= str(prefix
) + '[' + str(div_begin_time
) + ';' + str(div_end_time
) + '['
115 if tmp
>= div_begin_time
and tmp
< div_end_time
:
117 data
[key
] += count
[tmp
]
119 data
[key
] = count
[tmp
]
122 div_begin_time
= div_end_time
123 div_end_time
+= interval
129 for key
in sorted(data
):
130 table
.append([key
[key
.find('['):], data
[key
]])
131 x_labels
.append(key
[key
.find('['):])
134 table
.insert(0, ["INTERVAL (us)", "COUNT"])
135 pprint(table
, 1, out
)
138 cairoplot
.vertical_bar_plot ( 'histogram.svg', data
, 50 + 150*nbDiv
, 50*nbDiv
,
139 border
= 20, display_values
= True, grid
= True,
140 x_labels
= x_labels
, rounded_corners
= True )
This page took 0.038165 seconds and 3 git commands to generate.