Replace Pyasciigraph by termgraph in cputop, display prios
authorAntoine Busque <abusque@efficios.com>
Fri, 15 Jan 2016 21:47:00 +0000 (16:47 -0500)
committerAntoine Busque <abusque@efficios.com>
Thu, 11 Feb 2016 18:58:52 +0000 (13:58 -0500)
Signed-off-by: Antoine Busque <abusque@efficios.com>
lttnganalyses/cli/cputop.py

index 38e9d7ca4a1f4e710064d8b691ab3e8afd5fc1ae..ff24f80ed45123b76b7ce61e30bc972989d2f25f 100644 (file)
@@ -25,8 +25,8 @@
 import operator
 from .command import Command
 from ..core import cputop
-from ..ascii_graph import Pyasciigraph
 from . import mi
+from . import termgraph
 
 
 class Cputop(Command):
@@ -169,37 +169,37 @@ class Cputop(Command):
         return result_table
 
     def _print_per_tid_usage(self, result_table):
-        graph = Pyasciigraph()
-        values = []
-
-        for row in result_table.rows:
-            process_do = row.process
-            migration_count = row.migrations.value
-            if row.priority.value is not None:
-                prio_str = 'prio: %d' % row.priority.value
-            else:
-                prio_str = 'prio: ?'
-            output_str = '%s (%d) (%s)' % (process_do.name, process_do.tid,
-                                           prio_str)
-
-            if migration_count > 0:
-                output_str += ', %d migrations' % (migration_count)
+        row_format = '{:<25} {:>10} {}'
+        label_header = row_format.format('Process', 'Migrations', 'Priorities')
+
+        def format_label(row):
+            return row_format.format(
+                '%s (%d)' % (row.process.name, row.process.tid),
+                row.migrations.value,
+                row.prio_list.value,
+            )
 
-            values.append((output_str, row.usage.to_percentage()))
+        graph = termgraph.BarGraph(
+            title='Per-TID Usage',
+            unit='%',
+            get_value=lambda row: row.usage.to_percentage(),
+            get_label=format_label,
+            label_header=label_header,
+            data=result_table.rows
+        )
 
-        for line in graph.graph('Per-TID CPU Usage', values, unit=' %'):
-            print(line)
+        graph.print_graph()
 
     def _print_per_cpu_usage(self, result_table):
-        graph = Pyasciigraph()
-        values = []
-
-        for row in result_table.rows:
-            cpu = row.cpu
-            values.append(('CPU %d' % cpu.id, row.usage.to_percentage()))
+        graph = termgraph.BarGraph(
+            title='Per-CPU Usage',
+            unit='%',
+            get_value=lambda row: row.usage.to_percentage(),
+            get_label=lambda row: 'CPU %d' % row.cpu.id,
+            data=result_table.rows
+        )
 
-        for line in graph.graph('Per-CPU Usage', values, unit=' %'):
-            print(line)
+        graph.print_graph()
 
     def _print_total_cpu_usage(self, result_table):
         usage_percent = result_table.rows[0].usage.to_percentage()
@@ -215,11 +215,9 @@ def _run(mi_mode):
     cputopcmd.run()
 
 
-# entry point (human)
 def run():
     _run(mi_mode=False)
 
 
-# entry point (MI)
 def run_mi():
     _run(mi_mode=True)
This page took 0.0241710000000001 seconds and 5 git commands to generate.