4 # Babeltrace event count list 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 prints a count and rate of events.
21 # It also outputs a bar graph of count per event, using the cairoplot module.
24 from babeltrace
import *
25 from output_format_modules
import cairoplot
26 from output_format_modules
.pprint_table
import pprint_table
as pprint
30 raise TypeError("Usage: python eventcountlist.py path/to/trace")
33 ret
= ctx
.add_trace(sys
.argv
[1], "ctf")
35 raise IOError("Error adding trace")
37 # Events and their assossiated count
38 # will be stored as a dict:
42 bp
= IterPos(SEEK_BEGIN
)
43 ctf_it
= ctf
.Iterator(ctx
,bp
)
46 event
= ctf_it
.read_event()
48 start_time
= event
.get_timestamp()
51 while(event
is not None):
52 if event
.get_name() in events_count
:
53 events_count
[event
.get_name()] += 1
55 events_count
[event
.get_name()] = 1
62 event
= ctf_it
.read_event()
65 total_time
= event
.get_timestamp() - start_time
67 total_time
= prev_event
.get_timestamp() - start_time
71 # Printing encountered events with respective count and rate:
72 print("Total time: {} ns".format(total_time
))
73 table
= [["EVENT", "COUNT", "RATE (Hz)"]]
74 for item
in sorted(events_count
.iterkeys()):
75 tmp
= [item
, events_count
[item
],
76 events_count
[item
]/(total_time
/1000000000.0)]
80 # Exporting data as bar graph
81 cairoplot
.vertical_bar_plot ( 'eventcountlist.svg', events_count
, 50+85*len(events_count
),
82 800, border
= 20, display_values
= True, grid
= True,
83 rounded_corners
= True,
84 x_labels
= sorted(events_count
.keys()) )
This page took 0.032651 seconds and 5 git commands to generate.