Fix: create CPU during sched switch if it doesn't exist
authorAntoine Busque <antoinebusque@gmail.com>
Wed, 13 Aug 2014 20:10:24 +0000 (16:10 -0400)
committerAntoine Busque <antoinebusque@gmail.com>
Wed, 13 Aug 2014 20:10:24 +0000 (16:10 -0400)
A previous commit made the sched_switch event handling return early if
the CPU hadn't yet been entered into the self.cpus dictionary, which
meant that the newly scheduled TID would not be added to the self.tids
dictionary, thereby raising a KeyError on the subsequent event that
expected this TID to exist (e.g. the following exit_syscall).

Instead, the CPU is simply created as needed, and execution follows as
expected.

LTTngAnalyzes/sched.py

index 1aa07ca06ad19c467b0a0f92c6eadf0735ae19bf..f3f6003ad0645f0309219704b346cc5b6bffb814 100644 (file)
@@ -20,23 +20,26 @@ class Sched():
                 c.start_task_ns = 0
                 c.current_tid = -1
         else:
-            c = CPU()
-            c.cpu_id = cpu_id
-            c.current_tid = next_tid
-            # when we schedule a real task (not swapper)
-            c.start_task_ns = ts
-            # first activity on the CPU
-            self.cpus[cpu_id] = c
-            self.cpus[cpu_id].total_per_cpu_pc_list = []
+            self.add_cpu(cpu_id, ts, next_tid)
         for context in event.keys():
             if context.startswith("perf_"):
                 c.perf[context] = event[context]
 
+    def add_cpu(self, cpu_id, ts, next_tid):
+        c = CPU()
+        c.cpu_id = cpu_id
+        c.current_tid = next_tid
+        # when we schedule a real task (not swapper)
+        c.start_task_ns = ts
+        # first activity on the CPU
+        self.cpus[cpu_id] = c
+        self.cpus[cpu_id].total_per_cpu_pc_list = []
+
     def sched_switch_per_tid(self, ts, prev_tid, next_tid, next_comm, cpu_id, event, ret):
         """Compute per-tid usage"""
         # if we don't know yet the CPU, skip this
         if not cpu_id in self.cpus.keys():
-            return ret
+            self.add_cpu(cpu_id, ts, next_tid)
         c = self.cpus[cpu_id]
         # per-tid usage
         if prev_tid in self.tids:
This page took 0.02551 seconds and 5 git commands to generate.