4 # Babeltrace event count example script
6 # Copyright 2012 EfficiOS Inc.
8 # Author: Danny Serres <danny.serres@efficios.com>
10 # Permission is hereby granted, free of charge, to any person obtaining a copy
11 # of this software and associated documentation files (the "Software"), to deal
12 # in the Software without restriction, including without limitation the rights
13 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 # copies of the Software, and to permit persons to whom the Software is
15 # furnished to do so, subject to the following conditions:
17 # The above copyright notice and this permission notice shall be included in
18 # all copies or substantial portions of the Software.
20 # The script prints a count of specified events and
21 # their related tid's in a given trace.
22 # The trace needs TID context (lttng add-context -k -t tid)
25 from babeltrace
import *
26 from output_format_modules
.pprint_table
import pprint_table
as pprint
29 raise TypeError("Usage: python eventcount.py event1 [event2 ...] path/to/trace")
32 ret
= ctx
.add_trace(sys
.argv
[len(sys
.argv
)-1], "ctf")
34 raise IOError("Error adding trace")
39 bp
= IterPos(SEEK_BEGIN
)
40 ctf_it
= ctf
.Iterator(ctx
, bp
)
43 event
= ctf_it
.read_event()
44 while(event
is not None):
45 for event_type
in sys
.argv
[1:len(sys
.argv
)-1]:
46 if event_type
== event
.get_name():
48 # Getting scope definition
49 sco
= event
.get_top_level_scope(ctf
.scope
.STREAM_EVENT_CONTEXT
)
51 print("ERROR: Cannot get definition scope for {}".format(
56 tid_field
= event
.get_field(sco
, "_tid")
57 tid
= tid_field
.get_int64()
60 print("ERROR: Missing TID info for {}".format(
64 tmp
= (tid
, event
.get_name())
75 event
= ctf_it
.read_event()
79 # Appending data to table for output
82 table
.append([item
[0], item
[1], counts
[item
]])
84 table
.insert(0,["TID", "EVENT", "COUNT"])
This page took 0.035781 seconds and 4 git commands to generate.