2
# Copyright 2015 Canonical Ltd.
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU Lesser General Public License as published by
6
# the Free Software Foundation; version 2.1.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU Lesser General Public License for more details.
13
# You should have received a copy of the GNU Lesser General Public License
14
# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
# Author: Benjamin Zeller <benjamin.zeller@canonical.com>
20
from pprint import pprint
22
class MyCounter(dict):
23
def __missing__(self, key):
26
if __name__ == '__main__':
27
col = babeltrace.TraceCollection()
28
if col.add_traces_recursive(sys.argv[1], 'ctf') is None:
29
raise RuntimeError('Cannot add trace')
33
events_in_iteration = 4
35
minNumbers = MyCounter()
36
maxNumbers = MyCounter()
38
for event in col.events:
39
if (event.name == "app:invokeApplauncher"):
40
if (events_in_iteration != 4):
41
raise RuntimeError("Wrong Nr of events: "+str(events_in_iteration))
43
events_in_iteration = 1
44
first_event = event.timestamp
45
print("Event "+event.name+" occurs after: "+str(0))
48
events_in_iteration += 1
49
duration = event.timestamp-first_event
50
numbers[event.name] += duration
52
if minNumbers[event.name] == 0:
53
minNumbers[event.name] = duration
54
elif minNumbers[event.name] > duration:
55
minNumbers[event.name] = duration
57
if maxNumbers[event.name] < duration:
58
maxNumbers[event.name] = duration
60
print("Event "+event.name+" occurs after: "+str((event.timestamp-first_event)/1000/1000/1000))
63
print("---------- Event "+event+" ----------")
64
print("Min: "+str(minNumbers[event] /1000/1000/1000))
65
print("Max: "+str(maxNumbers[event] /1000/1000/1000))
66
print("Avg: "+str(numbers[event] / iterations /1000/1000/1000))