| 1 |
#!/usr/bin/env python3 |
| 2 |
# Copyright 2015 Canonical Ltd. |
| 3 |
# |
| 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. |
| 7 |
# |
| 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. |
| 12 |
# |
| 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/>. |
| 15 |
# |
| 16 |
# Author: Benjamin Zeller <[email protected]> |
| 17 |
|
| 18 |
import babeltrace |
| 19 |
import sys |
| 20 |
import getopt |
| 21 |
|
| 22 |
|
| 23 |
class MyCounter(dict): |
| 24 |
def __missing__(self, key): |
| 25 |
return 0 |
| 26 |
|
| 27 |
if __name__ == '__main__': |
| 28 |
verbose_mode = False |
| 29 |
try: |
| 30 |
opts, args = getopt.getopt(sys.argv[1:], "hi:v", ["help", |
| 31 |
"inputdata="]) |
| 32 |
except getopt.GetoptError: |
| 33 |
print("lomiri-app-launch-profiler-lttng -i <inputdata>") |
| 34 |
sys.exit(2) |
| 35 |
for opt, arg in opts: |
| 36 |
if opt == '-h': |
| 37 |
print("lomiri-app-launch-profiler-lttng -i <inputdata>") |
| 38 |
sys.exit() |
| 39 |
elif opt in ("-i", "--idata"): |
| 40 |
inputdata = arg |
| 41 |
elif opt in ("-v", "--verbose"): |
| 42 |
verbose_mode = True |
| 43 |
else: |
| 44 |
assert False, "unhandled option" |
| 45 |
sys.exit(2) |
| 46 |
col = babeltrace.TraceCollection() |
| 47 |
if col.add_traces_recursive(inputdata, 'ctf') is None: |
| 48 |
raise RuntimeError('Cannot add trace') |
| 49 |
first_event = -1 |
| 50 |
iterations = 0 |
| 51 |
events_in_iteration = 2 |
| 52 |
numbers = MyCounter() |
| 53 |
minNumbers = MyCounter() |
| 54 |
maxNumbers = MyCounter() |
| 55 |
|
| 56 |
for event in col.events: |
| 57 |
if (event.name == "app:invokeApplauncher"): |
| 58 |
if (events_in_iteration != 2): |
| 59 |
raise RuntimeError("Wrong Nr of events: " + |
| 60 |
str(events_in_iteration)) |
| 61 |
|
| 62 |
events_in_iteration = 1 |
| 63 |
first_event = event.timestamp |
| 64 |
# print("Event "+event.name+" occurs after: "+str(0)) |
| 65 |
iterations += 1 |
| 66 |
else: |
| 67 |
events_in_iteration += 1 |
| 68 |
duration = event.timestamp-first_event |
| 69 |
numbers[event.name] += duration |
| 70 |
|
| 71 |
if minNumbers[event.name] == 0: |
| 72 |
minNumbers[event.name] = duration |
| 73 |
elif minNumbers[event.name] > duration: |
| 74 |
minNumbers[event.name] = duration |
| 75 |
|
| 76 |
if maxNumbers[event.name] < duration: |
| 77 |
maxNumbers[event.name] = duration |
| 78 |
|
| 79 |
# print("Event "+event.name+" occurs after: " + |
| 80 |
# str((event.timestamp-first_event) / 1000 / 1000 / 1000)) |
| 81 |
|
| 82 |
for event in numbers: |
| 83 |
if (verbose_mode): |
| 84 |
print("---------- Event "+event+" ----------") |
| 85 |
print("Min: " + str(round(minNumbers[event] / |
| 86 |
1000 / 1000 / 1000, 4))) |
| 87 |
print("Max: " + str(round(maxNumbers[event] / |
| 88 |
1000 / 1000 / 1000, 4))) |
| 89 |
print("Avg: " + str(round(numbers[event] / iterations / |
| 90 |
1000000/1000, 4))) |
| 91 |
else: |
| 92 |
print(str(round(numbers[event]/iterations/1000000/1000, 4))) |