Browse Source

Fix python3 compatibility

Samuel Thibault 8 years ago
parent
commit
018fd21ea5
1 changed files with 82 additions and 82 deletions
  1. 82 82
      tools/starpu_trace_state_stats.py

+ 82 - 82
tools/starpu_trace_state_stats.py

@@ -1,4 +1,4 @@
-#!/usr/bin/python2.7
+#!/usr/bin/python
 
 ##
 # StarPU --- Runtime system for heterogeneous multicore architectures.
@@ -49,7 +49,7 @@ class EventStats():
 
     def show(self):
         if not self._name == None and not self._category == None:
-            print "\"" + self._name + "\"," + str(self._count) + ",\"" + self._category + "\"," + str(round(self._duration_time, 6))
+            print("\"" + self._name + "\"," + str(self._count) + ",\"" + self._category + "\"," + str(round(self._duration_time, 6)))
 
 class Worker():
     def __init__(self, id):
@@ -57,7 +57,7 @@ class Worker():
         self._events    = []
         self._stats     = []
         self._stack     = []
-	self._current_state = None
+        self._current_state = None
 
     def get_event_stats(self, name):
         for stat in self._stats:
@@ -69,75 +69,75 @@ class Worker():
         self._events.append(Event(type, name, category, start_time))
 
     def add_event_to_stats(self, curr_event):
-	if curr_event._type == "PushState":
-	    self._stack.append(curr_event)
-	    return # Will look later to find a PopState event.
-	elif curr_event._type == "PopState":
-	    if len(self._stack) == 0:
-		sys.exit("ERROR: The trace is most likely corrupted "
-			 "because a PopState event has been found without "
-			 "a PushState!")
-	    next_event = curr_event
-	    curr_event = self._stack.pop()
-	elif curr_event._type == "SetState":
-	    if self._current_state == None:
-		# First SetState event found
-		self._current_state = curr_event
-		return
-	    saved_state = curr_event
-	    next_event = curr_event
-	    curr_event = self._current_state
-	    self._current_state = saved_state
-	else:
-	    sys.exit("ERROR: Invalid event type!")
+        if curr_event._type == "PushState":
+            self._stack.append(curr_event)
+            return # Will look later to find a PopState event.
+        elif curr_event._type == "PopState":
+            if len(self._stack) == 0:
+                sys.exit("ERROR: The trace is most likely corrupted "
+                         "because a PopState event has been found without "
+                         "a PushState!")
+            next_event = curr_event
+            curr_event = self._stack.pop()
+        elif curr_event._type == "SetState":
+            if self._current_state == None:
+                # First SetState event found
+                self._current_state = curr_event
+                return
+            saved_state = curr_event
+            next_event = curr_event
+            curr_event = self._current_state
+            self._current_state = saved_state
+        else:
+            sys.exit("ERROR: Invalid event type!")
 
         # Compute duration with the next event.
         a = curr_event._start_time
         b = next_event._start_time
 
-	# Add the event to the list of stats.
-	for i in xrange(len(self._stats)):
-	    if self._stats[i]._name == curr_event._name:
-		self._stats[i].aggregate(b - a)
-		return
+        # Add the event to the list of stats.
+        for i in range(len(self._stats)):
+            if self._stats[i]._name == curr_event._name:
+                self._stats[i].aggregate(b - a)
+                return
         self._stats.append(EventStats(curr_event._name, b - a,
-				      curr_event._category))
+                                      curr_event._category))
 
     def calc_stats(self, start_profiling_times, stop_profiling_times):
         num_events = len(self._events)
-	use_start_stop = len(start_profiling_times) != 0
-	for i in xrange(0, num_events):
-	    event = self._events[i]
-	    if i > 0 and self._events[i-1]._name == "Deinitializing":
-		# Drop all events after the Deinitializing event is found
-		# because they do not make sense.
-		break
+        use_start_stop = len(start_profiling_times) != 0
+        for i in range(0, num_events):
+            event = self._events[i]
+            if i > 0 and self._events[i-1]._name == "Deinitializing":
+                # Drop all events after the Deinitializing event is found
+                # because they do not make sense.
+                break
 
             if not use_start_stop:
                 self.add_event_to_stats(event)
-		continue
+                continue
 
             # Check if the event is inbetween start/stop profiling events
-            for t in xrange(len(start_profiling_times)):
-		if (event._start_time > start_profiling_times[t] and
-		    event._start_time < stop_profiling_times[t]):
-		    self.add_event_to_stats(event)
-		    break
+            for t in range(len(start_profiling_times)):
+                if (event._start_time > start_profiling_times[t] and
+                    event._start_time < stop_profiling_times[t]):
+                    self.add_event_to_stats(event)
+                    break
 
         if not use_start_stop:
-	    return
-
-	# Special case for SetState events which need a next one for computing
-	# the duration.
-	curr_event = self._events[-1]
-	if curr_event._type == "SetState":
-            for i in xrange(len(start_profiling_times)):
-		if (curr_event._start_time > start_profiling_times[i] and
-		    curr_event._start_time < stop_profiling_times[i]):
-		    curr_event = Event(curr_event._type, curr_event._name,
-				       curr_event._category,
-				       stop_profiling_times[i])
-	    self.add_event_to_stats(curr_event)
+            return
+
+        # Special case for SetState events which need a next one for computing
+        # the duration.
+        curr_event = self._events[-1]
+        if curr_event._type == "SetState":
+            for i in range(len(start_profiling_times)):
+                if (curr_event._start_time > start_profiling_times[i] and
+                    curr_event._start_time < stop_profiling_times[i]):
+                    curr_event = Event(curr_event._type, curr_event._name,
+                                       curr_event._category,
+                                       stop_profiling_times[i])
+            self.add_event_to_stats(curr_event)
 
 def read_blocks(input_file):
     empty_lines = 0
@@ -171,8 +171,8 @@ def insert_worker_event(workers, prog_events, block):
     category = None
 
     for line in block:
-	key   = line[:2]
-	value = read_field(line, 2)
+        key   = line[:2]
+        value = read_field(line, 2)
         if key == "E:": # EventType
             event_type = value
         elif key == "C:": # Category
@@ -186,8 +186,8 @@ def insert_worker_event(workers, prog_events, block):
 
     # Program events don't belong to workers, they are globals.
     if category == "Program":
-	prog_events.append(Event(event_type, name, category, start_time))
-	return
+        prog_events.append(Event(event_type, name, category, start_time))
+        return
 
     for worker in workers:
         if worker._id == worker_id:
@@ -217,7 +217,7 @@ def calc_times(stats):
         elif stat._category == "Other":
             ti += stat._duration_time
         else:
-	    print "WARNING: Unknown category '" + stat._category + "'!"
+            print("WARNING: Unknown category '" + stat._category + "'!")
     return (ti, tr, tt, ts)
 
 def save_times(ti, tr, tt, ts):
@@ -264,26 +264,26 @@ def save_efficiencies(e, ep, er, et, es):
     f.close()
 
 def usage():
-    print "USAGE:"
-    print "starpu_trace_state_stats.py [ -te -s=<time> ] <trace.rec>"
+    print("USAGE:")
+    print("starpu_trace_state_stats.py [ -te -s=<time> ] <trace.rec>")
     print
-    print "OPTIONS:"
-    print " -t or --time            Compute and dump times to times.csv"
+    print("OPTIONS:")
+    print(" -t or --time            Compute and dump times to times.csv")
     print
-    print " -e or --efficiency      Compute and dump efficiencies to efficiencies.csv"
+    print(" -e or --efficiency      Compute and dump efficiencies to efficiencies.csv")
     print
-    print " -s or --seq_task_time   Used to compute task efficiency between sequential and parallel times"
-    print "                         (if not set, task efficiency will be 1.0)"
+    print(" -s or --seq_task_time   Used to compute task efficiency between sequential and parallel times")
+    print("                         (if not set, task efficiency will be 1.0)")
     print
-    print "EXAMPLES:"
-    print "# Compute event statistics and report them to stdout:"
-    print "python starpu_trace_state_stats.py trace.rec"
+    print("EXAMPLES:")
+    print("# Compute event statistics and report them to stdout:")
+    print("python starpu_trace_state_stats.py trace.rec")
     print
-    print "# Compute event stats, times and efficiencies:"
-    print "python starpu_trace_state_stats.py -te trace.rec"
+    print("# Compute event stats, times and efficiencies:")
+    print("python starpu_trace_state_stats.py -te trace.rec")
     print
-    print "# Compute correct task efficiency with the sequential task time:"
-    print "python starpu_trace_state_stats.py -s=60093.950614 trace.rec"
+    print("# Compute correct task efficiency with the sequential task time:")
+    print("python starpu_trace_state_stats.py -s=60093.950614 trace.rec")
 
 def main():
     try:
@@ -334,13 +334,13 @@ def main():
     start_profiling_times = []
     stop_profiling_times = []
     for prog_event in prog_events:
-	if prog_event._name == "start_profiling":
-	    start_profiling_times.append(prog_event._start_time)
-	if prog_event._name == "stop_profiling":
-	    stop_profiling_times.append(prog_event._start_time)
+        if prog_event._name == "start_profiling":
+            start_profiling_times.append(prog_event._start_time)
+        if prog_event._name == "stop_profiling":
+            stop_profiling_times.append(prog_event._start_time)
 
     if len(start_profiling_times) != len(stop_profiling_times):
-	sys.exit("Mismatch number of start/stop profiling events!")
+        sys.exit("Mismatch number of start/stop profiling events!")
 
     # Compute worker statistics.
     stats = []
@@ -356,7 +356,7 @@ def main():
                 stats.append(EventStats(stat._name, 0.0, stat._category, 0))
 
     # Compute global statistics for all workers.
-    for i in xrange(0, len(workers)):
+    for i in range(0, len(workers)):
         for stat in stats:
             s = workers[i].get_event_stats(stat._name)
             if not s == None:
@@ -365,7 +365,7 @@ def main():
                 stat._count += s._count
 
     # Output statistics.
-    print "\"Name\",\"Count\",\"Type\",\"Duration\""
+    print("\"Name\",\"Count\",\"Type\",\"Duration\"")
     for stat in stats:
         stat.show()