per-tid syscalls
authorJulien Desfossez <jdesfossez@efficios.com>
Mon, 3 Mar 2014 23:12:31 +0000 (18:12 -0500)
committerJulien Desfossez <jdesfossez@efficios.com>
Mon, 3 Mar 2014 23:12:31 +0000 (18:12 -0500)
Signed-off-by: Julien Desfossez <jdesfossez@efficios.com>
LTTngAnalyzes/sched_switch.py
LTTngAnalyzes/syscalls.py
LTTngAnalyzes/textreport.py
sched_switch.py

index c68c77eacc0aa103dd17b94bd9eadcd87b617c29..590650f67bd017a47254a939d3a056cb24cbc6fc 100644 (file)
@@ -41,6 +41,7 @@ class SchedSwitch():
             p.comm = next_comm
             p.cpu_ns = 0
             p.migrate_count = 0
+            p.syscalls = {}
             self.tids[next_tid] = p
         else:
             p = self.tids[next_tid]
index abe9188b3a129534ab1d3f5de2c05395abd91077..4f7f769da341bf7573d987a163c4fabc8e5a5297 100644 (file)
@@ -6,9 +6,7 @@ class Syscalls():
         self.tids = tids
         self.syscalls = syscalls
 
-    def entry(self, event):
-        name = event.name
-        cpu_id = event["cpu_id"]
+    def global_syscall_entry(self, name):
         if not name in self.syscalls:
             s = Syscall()
             s.name = name
@@ -18,6 +16,29 @@ class Syscalls():
             s = self.syscalls[name]
         s.count += 1
 
+    def per_tid_syscall_entry(self, name, cpu_id):
+        # we don't know which process is currently on this CPU
+        if not cpu_id in self.cpus:
+            return
+        c = self.cpus[cpu_id]
+        if c.current_tid == -1:
+            return
+        t = self.tids[c.current_tid]
+        if not name in t.syscalls:
+            s = Syscall()
+            s.name = name
+            s.count = 0
+            t.syscalls[name] = s
+        else:
+            s = t.syscalls[name]
+        s.count += 1
+
+    def entry(self, event):
+        name = event.name
+        cpu_id = event["cpu_id"]
+        self.global_syscall_entry(name)
+        self.per_tid_syscall_entry(name, cpu_id)
+
     def exit(self, event):
         cpu_id = event["cpu_id"]
         pass
index 9fdd6d28a6dc9fe76b9a96dfa48c399cc076ebcd..373632b9d8f1833d361c84f78549dc0046b3adfd 100644 (file)
@@ -40,7 +40,8 @@ class TextReport():
             self.text_per_cpu_report(total_ns)
             print("")
         if args.tid:
-            self.text_per_tid_report(total_ns, args.display_proc_list, limit=args.top)
+            self.text_per_tid_report(total_ns, args.display_proc_list,
+                    limit=args.top, syscalls=args.tid_syscalls)
             print("")
         if args.global_syscalls:
             self.text_global_syscall_report()
@@ -52,9 +53,9 @@ class TextReport():
                 key=operator.attrgetter("count"), reverse=True):
             if syscall.count == 0:
                 continue
-            print("%s (%d)" % (syscall.name[4:], syscall.count))
+            print("%s : %d" % (syscall.name[4:], syscall.count))
 
-    def text_per_tid_report(self, total_ns, proc_list, limit=0):
+    def text_per_tid_report(self, total_ns, proc_list, limit=0, syscalls=0):
         print("### Per-TID Usage ###")
         count = 0
         for tid in sorted(self.tids.values(),
@@ -68,6 +69,12 @@ class TextReport():
             else:
                 print("")
             count = count + 1
+            if syscalls:
+                for syscall in sorted(tid.syscalls.values(),
+                        key=operator.attrgetter('count'), reverse=True):
+                    if syscall.count == 0:
+                        continue
+                    print(" - %s : %d" % (syscall.name[4:], syscall.count))
             if limit > 0 and count >= limit:
                 break
 
index 126eeeccce49a76c93085f010df752d3cd20e3e8..e534ff2bcb58223a6dfcd77bdc61e28caad53e5f 100755 (executable)
@@ -68,6 +68,8 @@ class CPUAnalyzes():
         for tid in self.tids.keys():
             self.tids[tid].cpu_ns = 0
             self.tids[tid].migrate_count = 0
+            for syscall in self.tids[tid].syscalls.keys():
+                self.tids[tid].syscalls[syscall].count = 0
 
         for syscall in self.syscalls.keys():
             self.syscalls[syscall].count = 0
@@ -107,9 +109,11 @@ class CPUAnalyzes():
                 sched_switch.add(event)
             elif event.name == "sched_migrate_task":
                 migrate_task.add(event)
-            elif event.name[0:4] == "sys_":
+            elif event.name[0:4] == "sys_" and \
+                    (args.global_syscalls or args.tid_syscalls):
                 syscall.entry(event)
-            elif event.name == "exit_syscall":
+            elif event.name == "exit_syscall" and \
+                    (args.global_syscalls or args.tid_syscalls):
                 syscall.exit(event)
         if args.refresh == 0:
             # stats for the whole trace
@@ -151,6 +155,8 @@ if __name__ == "__main__":
     if not args.json:
         args.text = True
 
+    if args.tid_syscalls:
+        args.tid = True
     if not (args.cpu or args.tid or args.overall or args.info or \
             args.global_syscalls or args.tid_syscalls):
         args.cpu = True
@@ -159,6 +165,8 @@ if __name__ == "__main__":
         args.info = True
         args.global_syscalls = True
         args.tid_syscalls = True
+    if args.name:
+        args.global_syscalls = False
     args.display_proc_list = []
     if args.name:
         args.display_proc_list = args.name.split(",")
This page took 0.027185 seconds and 5 git commands to generate.