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