diff mbox

[v1,14/19] tools/kvm_stat: add new interactive command 'h'

Message ID 20170607190843.76869-15-raspl@linux.vnet.ibm.com (mailing list archive)
State New, archived
Headers show

Commit Message

Stefan Raspl June 7, 2017, 7:08 p.m. UTC
Display interactive commands reference on 'h'.
While at it, sort interactive commands alphabetically in various places.

Signed-off-by: Stefan Raspl <raspl@linux.vnet.ibm.com>
---
 tools/kvm/kvm_stat/kvm_stat     | 37 ++++++++++++++++++++++++++++++++-----
 tools/kvm/kvm_stat/kvm_stat.txt |  2 ++
 2 files changed, 34 insertions(+), 5 deletions(-)

Comments

Paolo Bonzini June 8, 2017, 4:19 p.m. UTC | #1
On 07/06/2017 21:08, Stefan Raspl wrote:
> +        """Display help with list of interactive commands"""
> +        msg = ('   c     clear filter',
> +               '   f     filter by regular expression',
> +               '   g     filter by guest name',
> +               '   h     display interactive commands reference',
> +               '   p     filter by PID',
> +               '   q     quit',
> +               '   r     reset stats',
> +               '   x     toggle reporting of stats for individual child trace'
> +               ' events',
> +               'Any other key refreshes statistics immediately')

> @@ -1237,10 +1263,11 @@ description_text = """
>     c     clear filter
>     f     filter by regular expression
>     g     filter by guest name
> +   h     display interactive commands reference
>     p     filter by PID
>     q     quit
> -   x     toggle reporting of stats for individual child trace events
>     r     reset stats
> +   x     toggle reporting of stats for individual child trace events
>  Press any other key to refresh statistics immediately.
>  """

Some duplication here... want to eliminate it as a follow-up patch, by
creating a global string or array for this part of description_text?

Paolo
Stefan Raspl June 20, 2017, 9:10 a.m. UTC | #2
On 08.06.2017 18:19, Paolo Bonzini wrote:
> 
> 
> On 07/06/2017 21:08, Stefan Raspl wrote:
>> +        """Display help with list of interactive commands"""
>> +        msg = ('   c     clear filter',
>> +               '   f     filter by regular expression',
>> +               '   g     filter by guest name',
>> +               '   h     display interactive commands reference',
>> +               '   p     filter by PID',
>> +               '   q     quit',
>> +               '   r     reset stats',
>> +               '   x     toggle reporting of stats for individual child trace'
>> +               ' events',
>> +               'Any other key refreshes statistics immediately')
> 
>> @@ -1237,10 +1263,11 @@ description_text = """
>>     c     clear filter
>>     f     filter by regular expression
>>     g     filter by guest name
>> +   h     display interactive commands reference
>>     p     filter by PID
>>     q     quit
>> -   x     toggle reporting of stats for individual child trace events
>>     r     reset stats
>> +   x     toggle reporting of stats for individual child trace events
>>  Press any other key to refresh statistics immediately.
>>  """
> 
> Some duplication here... want to eliminate it as a follow-up patch, by
> creating a global string or array for this part of description_text?

I was annoyed by this, too. Couldn't figure an obvious way
immediately to re-use the string, will give it some more thought.

Ciao,
Stefan
Paolo Bonzini June 20, 2017, 12:34 p.m. UTC | #3
On 20/06/2017 11:10, Stefan Raspl wrote:
> On 08.06.2017 18:19, Paolo Bonzini wrote:
>>
>>
>> On 07/06/2017 21:08, Stefan Raspl wrote:
>>> +        """Display help with list of interactive commands"""
>>> +        msg = ('   c     clear filter',
>>> +               '   f     filter by regular expression',
>>> +               '   g     filter by guest name',
>>> +               '   h     display interactive commands reference',
>>> +               '   p     filter by PID',
>>> +               '   q     quit',
>>> +               '   r     reset stats',
>>> +               '   x     toggle reporting of stats for individual child trace'
>>> +               ' events',
>>> +               'Any other key refreshes statistics immediately')
>>
>>> @@ -1237,10 +1263,11 @@ description_text = """
>>>     c     clear filter
>>>     f     filter by regular expression
>>>     g     filter by guest name
>>> +   h     display interactive commands reference
>>>     p     filter by PID
>>>     q     quit
>>> -   x     toggle reporting of stats for individual child trace events
>>>     r     reset stats
>>> +   x     toggle reporting of stats for individual child trace events
>>>  Press any other key to refresh statistics immediately.
>>>  """
>>
>> Some duplication here... want to eliminate it as a follow-up patch, by
>> creating a global string or array for this part of description_text?
> 
> I was annoyed by this, too. Couldn't figure an obvious way
> immediately to re-use the string, will give it some more thought.

Ok, I'll give it a shot then.

Paolo
diff mbox

Patch

diff --git a/tools/kvm/kvm_stat/kvm_stat b/tools/kvm/kvm_stat/kvm_stat
index a9e7ea612e7f..6838de38ecb5 100755
--- a/tools/kvm/kvm_stat/kvm_stat
+++ b/tools/kvm/kvm_stat/kvm_stat
@@ -1018,6 +1018,30 @@  class Tui(object):
             self.screen.addstr(4, 1, 'No matching events reported yet')
         self.screen.refresh()
 
+    def show_help_interactive(self):
+        """Display help with list of interactive commands"""
+        msg = ('   c     clear filter',
+               '   f     filter by regular expression',
+               '   g     filter by guest name',
+               '   h     display interactive commands reference',
+               '   p     filter by PID',
+               '   q     quit',
+               '   r     reset stats',
+               '   x     toggle reporting of stats for individual child trace'
+               ' events',
+               'Any other key refreshes statistics immediately')
+        curses.cbreak()
+        self.screen.erase()
+        self.screen.addstr(0, 0, "Interactive commands reference",
+                           curses.A_BOLD)
+        self.screen.addstr(2, 0, "Press any key to exit", curses.A_STANDOUT)
+        row = 4
+        for line in msg:
+            self.screen.addstr(row, 0, line)
+            row += 1
+        self.screen.getkey()
+        self.refresh_header()
+
     def show_filter_selection(self):
         """Draws filter selection mask.
 
@@ -1142,10 +1166,6 @@  class Tui(object):
             sleeptime = DELAY_REGULAR
             try:
                 char = self.screen.getkey()
-                if char == 'x':
-                    self.update_drilldown()
-                if char == 'q':
-                    break
                 if char == 'c':
                     self.stats.fields_filter = DEFAULT_REGEX
                     self.refresh_header(0)
@@ -1160,13 +1180,19 @@  class Tui(object):
                     self.show_vm_selection_by_guest_name()
                     curses.curs_set(0)
                     sleeptime = DELAY_INITIAL
+                if char == 'h':
+                    self.show_help_interactive()
                 if char == 'p':
                     curses.curs_set(1)
                     self.show_vm_selection_by_pid()
                     curses.curs_set(0)
                     sleeptime = DELAY_INITIAL
+                if char == 'q':
+                    break
                 if char == 'r':
                     self.stats.reset()
+                if char == 'x':
+                    self.update_drilldown()
             except KeyboardInterrupt:
                 break
             except curses.error:
@@ -1237,10 +1263,11 @@  Interactive Commands:
    c     clear filter
    f     filter by regular expression
    g     filter by guest name
+   h     display interactive commands reference
    p     filter by PID
    q     quit
-   x     toggle reporting of stats for individual child trace events
    r     reset stats
+   x     toggle reporting of stats for individual child trace events
 Press any other key to refresh statistics immediately.
 """
 
diff --git a/tools/kvm/kvm_stat/kvm_stat.txt b/tools/kvm/kvm_stat/kvm_stat.txt
index 109431bdc63c..2bad6f22183b 100644
--- a/tools/kvm/kvm_stat/kvm_stat.txt
+++ b/tools/kvm/kvm_stat/kvm_stat.txt
@@ -35,6 +35,8 @@  INTERACTIVE COMMANDS
 
 *g*::	filter by guest name
 
+*h*::	display interactive commands reference
+
 *p*::	filter by PID
 
 *q*::	quit