3 # Babeltrace event count 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 of specified events and
20 # their related tid's in a given trace.
21 # The trace needs TID context (lttng add-context -k -t tid)
24 from babeltrace
import *
25 from output_format_modules
.pprint_table
import pprint_table
as pprint
28 raise TypeError("Usage: python eventcount.py event1 [event2 ...] path/to/trace")
31 ret
= ctx
.add_trace(sys
.argv
[len(sys
.argv
)-1], "ctf")
33 raise IOError("Error adding trace")
38 bp
= IterPos(SEEK_BEGIN
)
39 ctf_it
= ctf
.Iterator(ctx
, bp
)
42 event
= ctf_it
.read_event()
43 while(event
is not None):
44 for event_type
in sys
.argv
[1:len(sys
.argv
)-1]:
45 if event_type
== event
.get_name():
47 # Getting scope definition
48 sco
= event
.get_top_level_scope(ctf
.scope
.STREAM_EVENT_CONTEXT
)
50 print("ERROR: Cannot get definition scope for {}".format(
55 tid_field
= event
.get_field(sco
, "_tid")
56 tid
= tid_field
.get_int64()
59 print("ERROR: Missing TID info for {}".format(
63 tmp
= (tid
, event
.get_name())
74 event
= ctf_it
.read_event()
78 # Appending data to table for output
81 table
.append([item
[0], item
[1], counts
[item
]])
83 table
.insert(0,["TID", "EVENT", "COUNT"])
This page took 0.030647 seconds and 4 git commands to generate.