~ubuntu-sdk-team/ubuntu-ui-toolkit/trunk-ota14

« back to all changes in this revision

Viewing changes to app-launch-profiler/app-launch-profiler-lttng.py

  • Committer: Zoltán Balogh
  • Date: 2015-09-22 10:29:24 UTC
  • mto: (1000.623.16 staging)
  • mto: This revision was merged to the branch mainline in revision 1231.
  • Revision ID: zoltan@bakter.hu-20150922102924-dgrqcgmblzpbnmtx
Integrated application startup time profiling tool

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 <benjamin.zeller@canonical.com>
 
17
 
 
18
import babeltrace
 
19
import sys
 
20
from pprint import pprint
 
21
 
 
22
class MyCounter(dict):
 
23
    def __missing__(self, key):
 
24
        return 0
 
25
 
 
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')
 
30
 
 
31
    first_event = -1
 
32
    iterations  = 0
 
33
    events_in_iteration = 4
 
34
    numbers     = MyCounter()
 
35
    minNumbers  = MyCounter()
 
36
    maxNumbers  = MyCounter()
 
37
 
 
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))
 
42
 
 
43
            events_in_iteration = 1
 
44
            first_event = event.timestamp
 
45
            print("Event "+event.name+" occurs after: "+str(0))
 
46
            iterations+=1
 
47
        else:
 
48
            events_in_iteration += 1
 
49
            duration = event.timestamp-first_event
 
50
            numbers[event.name] += duration
 
51
 
 
52
            if minNumbers[event.name] == 0:
 
53
                minNumbers[event.name] = duration
 
54
            elif minNumbers[event.name] > duration:
 
55
                minNumbers[event.name] = duration
 
56
 
 
57
            if maxNumbers[event.name] < duration:
 
58
               maxNumbers[event.name] = duration
 
59
 
 
60
            print("Event "+event.name+" occurs after: "+str((event.timestamp-first_event)/1000/1000/1000))
 
61
 
 
62
    for event in numbers:
 
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))