From: Antoine Busque Date: Fri, 15 Jan 2016 21:47:00 +0000 (-0500) Subject: Replace Pyasciigraph by termgraph in cputop, display prios X-Git-Url: http://git.efficios.com/?p=deliverable%2Flttng-analyses.git;a=commitdiff_plain;h=fc3af3f848df2bec9f658266522ac0d6147c575c Replace Pyasciigraph by termgraph in cputop, display prios Signed-off-by: Antoine Busque --- diff --git a/lttnganalyses/cli/cputop.py b/lttnganalyses/cli/cputop.py index 38e9d7c..ff24f80 100644 --- a/lttnganalyses/cli/cputop.py +++ b/lttnganalyses/cli/cputop.py @@ -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)