Add a new option to kvmstat that allows to filter by PID

Review Request #72 — Created July 10, 2015 and updated

tuxillo
illumos-gate
general

kvmstat - Add -p to filter by PID

[root@sm01 /opt/custom/bin/b]# ./kvmstat
   pid vcpu |  exits :  haltx   irqx  irqwx    iox  mmiox |   irqs   emul   eptv
 32020    0 |    542 :     69      3      0     14    141 |     69    363      0
 32020    1 |    435 :     72      4      2     29    145 |     77    242      0
 18743    0 |   8683 :   1180     42      9     23   2368 |   1198   6189      0
 18743    1 |   6775 :   1185     28      9     21   2384 |   1209   4169      0
   pid vcpu |  exits :  haltx   irqx  irqwx    iox  mmiox |   irqs   emul   eptv
 32020    0 |    553 :     73      3      0     14    148 |     73    368      0
 32020    1 |    425 :     69      7      2     24    138 |     74    244      0
 18743    0 |   8927 :   1216     71      5     31   2440 |   1244   6325      0
 18743    1 |   6908 :   1177     36      7      7   2372 |   1211   4301      0
   pid vcpu |  exits :  haltx   irqx  irqwx    iox  mmiox |   irqs   emul   eptv
 32020    0 |    543 :     72      1      0      6    147 |     72    371      0
 32020    1 |    451 :     72      2      2     37    145 |     78    256      0
 18743    0 |   8939 :   1201     52     13     31   2439 |   1232   6370      0
 18743    1 |   7089 :   1209     35      7     27   2466 |   1249   4404      0
^C
[root@sm01 /opt/custom/bin/b]# ./kvmstat -h
Usage: kvmstat [-p pid] [interval [count]]

  Displays statistics for running kernel virtual machines, with one line
  per virtual CPU.  All statistics are reported as per-second rates.

  The columns are as follows:

    pid    =>  identifier of process controlling the virtual CPU
    vcpu   =>  virtual CPU identifier relative to its virtual machine
    exits  =>  virtual machine exits for the virtual CPU
    haltx  =>  virtual machine exits due to the HLT instruction
    irqx   =>  virtual machine exits due to a pending external interrupt
    irqwx  =>  virtual machine exits due to an open interrupt window
    iox    =>  virtual machine exits due to an I/O instruction
    mmiox  =>  virtual machine exits due to memory mapped I/O
    irqs   =>  interrupts injected into the virtual CPU
    emul   =>  instructions emulated in the kernel
    eptv   =>  extended page table violations

[root@sm01 /opt/custom/bin/b]# ./kvmstat -p 32020
   pid vcpu |  exits :  haltx   irqx  irqwx    iox  mmiox |   irqs   emul   eptv
 32020    0 |    548 :     69      9      0      6    141 |     70    375      0
 32020    1 |    436 :     71      4      3     32    143 |     79    243      0
   pid vcpu |  exits :  haltx   irqx  irqwx    iox  mmiox |   irqs   emul   eptv
 32020    0 |    534 :     70      3      0      6    142 |     70    364      0
 32020    1 |    443 :     72      3      2     37    144 |     78    246      0
^C
  • 4
  • 0
  • 0
  • 0
  • 4
Description From Last Updated
Rather than having pidfilter as a boolean, you can just use pid > 0 in all of the places that ... rm rm
This is incorrect. To use strtol correctly you need to do the following: first set errno to zero before calling ... rm rm
You should give a more useful error message here. For example, that the value was invalid for -p. rm rm
This should be in an explicit options section, not in the general description. rm rm
rm
  1. 
      
  2. usr/src/cmd/kvmstat/kvmstat.c (Diff revision 1)
     
     

    Rather than having pidfilter as a boolean, you can just use pid > 0 in all of the places that you're evaluating pidfilter, this way you also avoid the unitialized variable.

  3. usr/src/cmd/kvmstat/kvmstat.c (Diff revision 1)
     
     

    This is incorrect. To use strtol correctly you need to do the following:

    • first set errno to zero before calling strtol
    • Next, you'll also want to check explicitly in the if statement for errno != 0 and if pid equals LONG_MAX.
    • You also want to check the upper bound of the pid is greater than PID_MAX from limits.h. No sense allowing them to specify something they can't use
    • In addition, the current check here is using interval instead of pid
  4. usr/src/cmd/kvmstat/kvmstat.c (Diff revision 1)
     
     

    You should give a more useful error message here. For example, that the value was invalid for -p.

  5. usr/src/man/man1/kvmstat.1 (Diff revision 1)
     
     

    This should be in an explicit options section, not in the general description.

  6. 
      
Loading...