Patchwork [v7,05/11] trace: [tracetool] Do not precompute the event number

login
register
mail settings
Submitter Lluís Vilanova
Date March 21, 2012, 9:52 p.m.
Message ID <20120321215255.3272.63777.stgit@ginnungagap.bsc.es>
Download mbox | patch
Permalink /patch/148079/
State New
Headers show

Comments

Lluís Vilanova - March 21, 2012, 9:52 p.m.
An event number is implicit in its position on the list of events.

Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
Signed-off-by: Harsh Prateek Bora <harsh@linux.vnet.ibm.com>
---
 scripts/tracetool.py |   21 +++++++++------------
 1 files changed, 9 insertions(+), 12 deletions(-)

Patch

diff --git a/scripts/tracetool.py b/scripts/tracetool.py
index 4f9060f..c2d5c24 100755
--- a/scripts/tracetool.py
+++ b/scripts/tracetool.py
@@ -106,14 +106,14 @@  def simple_h(events):
     print '#include "trace/simple.h"'
     print
 
-    for event in events:
+    for num, event in enumerate(events):
         if event.argc:
             argstr = event.argnames.split()
             arg_prefix = '(uint64_t)(uintptr_t)'
             cast_args = arg_prefix + arg_prefix.join(argstr)
-            simple_args = (str(event.num) + ', ' + cast_args)
+            simple_args = (str(num) + ', ' + cast_args)
         else:
-            simple_args = str(event.num)
+            simple_args = str(num)
 
         print '''static inline void trace_%(name)s(%(args)s)
 {
@@ -125,7 +125,7 @@  def simple_h(events):
     'trace_args': simple_args
 }
         print
-    print '#define NR_TRACE_EVENTS %d' % (event.num + 1)
+    print '#define NR_TRACE_EVENTS %d' % len(events)
     print 'extern TraceEvent trace_list[NR_TRACE_EVENTS];'
 
 
@@ -154,7 +154,7 @@  def stderr_h(events):
 #include "trace/stderr.h"
 
 extern TraceEvent trace_list[];'''
-    for event in events:
+    for num, event in enumerate(events):
         argnames = event.argnames
         if event.argc > 0:
             argnames = ', ' + event.argnames
@@ -169,12 +169,12 @@  static inline void trace_%(name)s(%(args)s)
 }''' % {
     'name': event.name,
     'args': event.args,
-    'event_num': event.num,
+    'event_num': num,
     'fmt': event.fmt,
     'argnames': argnames
 }
     print
-    print '#define NR_TRACE_EVENTS %d' % (event.num + 1)
+    print '#define NR_TRACE_EVENTS %d' % len(events)
 
 def stderr_c(events):
     print '''#include "trace.h"
@@ -382,8 +382,7 @@  trace_gen = {
 cre = re.compile("(?P<name>[^(\s]+)\((?P<args>[^)]*)\)\s*(?P<fmt>\".*)?")
 
 class Event(object):
-    def __init__(self, num, line):
-        self.num = num
+    def __init__(self, line):
         m = cre.match(line)
         assert m is not None
         groups = m.groupdict('')
@@ -400,15 +399,13 @@  class Event(object):
 
 # Generator that yields Event objects given a trace-events file object
 def read_events(fobj):
-    event_num = 0
     res = []
     for line in fobj:
         if not line.strip():
             continue
         if line.lstrip().startswith('#'):
 	    continue
-        res.append(Event(event_num, line))
-        event_num += 1
+        res.append(Event(line))
     return res
 
 binary = ""