qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Janosch Frank <frankja@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PULL 09/49] scripts/kvm/kvm_stat: Make constants uppercase
Date: Tue, 26 Jan 2016 14:46:41 +0100	[thread overview]
Message-ID: <1453816041-36362-10-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1453816041-36362-1-git-send-email-pbonzini@redhat.com>

From: Janosch Frank <frankja@linux.vnet.ibm.com>

Constants should be uppercase with separating underscores, as
requested in PEP8. This helps identifying them when reading the code.

Reviewed-by: Jason J. Herne <jjherne@linux.vnet.ibm.com>
Signed-off-by: Janosch Frank <frankja@linux.vnet.ibm.com>
Message-Id: <1452525484-32309-4-git-send-email-frankja@linux.vnet.ibm.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 scripts/kvm/kvm_stat | 64 ++++++++++++++++++++++++++--------------------------
 1 file changed, 32 insertions(+), 32 deletions(-)

diff --git a/scripts/kvm/kvm_stat b/scripts/kvm/kvm_stat
index 6323276..c4bf900 100755
--- a/scripts/kvm/kvm_stat
+++ b/scripts/kvm/kvm_stat
@@ -36,7 +36,7 @@ class DebugfsProvider(object):
             return int(file(self.base + '/' + key).read())
         return dict([(key, val(key)) for key in self._fields])
 
-vmx_exit_reasons = {
+VMX_EXIT_REASONS = {
     0: 'EXCEPTION_NMI',
     1: 'EXTERNAL_INTERRUPT',
     2: 'TRIPLE_FAULT',
@@ -78,7 +78,7 @@ vmx_exit_reasons = {
     58: 'INVPCID',
 }
 
-svm_exit_reasons = {
+SVM_EXIT_REASONS = {
     0x000: 'READ_CR0',
     0x003: 'READ_CR3',
     0x004: 'READ_CR4',
@@ -154,7 +154,7 @@ svm_exit_reasons = {
 }
 
 # EC definition of HSR (from arch/arm64/include/asm/kvm_arm.h)
-aarch64_exit_reasons = {
+AARCH64_EXIT_REASONS = {
     0x00: 'UNKNOWN',
     0x01: 'WFI',
     0x03: 'CP15_32',
@@ -193,7 +193,7 @@ aarch64_exit_reasons = {
 }
 
 # From include/uapi/linux/kvm.h, KVM_EXIT_xxx
-userspace_exit_reasons = {
+USERSPACE_EXIT_REASONS = {
      0: 'UNKNOWN',
      1: 'EXCEPTION',
      2: 'IO',
@@ -221,15 +221,15 @@ userspace_exit_reasons = {
     24: 'SYSTEM_EVENT',
 }
 
-x86_exit_reasons = {
-    'vmx': vmx_exit_reasons,
-    'svm': svm_exit_reasons,
+X86_EXIT_REASONS = {
+    'vmx': VMX_EXIT_REASONS,
+    'svm': SVM_EXIT_REASONS,
 }
 
-sc_perf_evt_open = None
-exit_reasons = None
+SC_PERF_EVT_OPEN = None
+EXIT_REASONS = None
 
-ioctl_numbers = {
+IOCTL_NUMBERS = {
     'SET_FILTER' : 0x40082406,
     'ENABLE'     : 0x00002400,
     'DISABLE'    : 0x00002401,
@@ -238,19 +238,19 @@ ioctl_numbers = {
 
 def x86_init(flag):
     globals().update({
-        'sc_perf_evt_open' : 298,
-        'exit_reasons' : x86_exit_reasons[flag],
+        'SC_PERF_EVT_OPEN' : 298,
+        'EXIT_REASONS' : X86_EXIT_REASONS[flag],
     })
 
 def s390_init():
     globals().update({
-        'sc_perf_evt_open' : 331
+        'SC_PERF_EVT_OPEN' : 331
     })
 
 def ppc_init():
     globals().update({
-        'sc_perf_evt_open' : 319,
-        'ioctl_numbers' : {
+        'SC_PERF_EVT_OPEN' : 319,
+        'IOCTL_NUMBERS' : {
             'SET_FILTER' : 0x80002406 | (ctypes.sizeof(ctypes.c_char_p) << 16),
             'ENABLE'     : 0x20002400,
             'DISABLE'    : 0x20002401,
@@ -259,8 +259,8 @@ def ppc_init():
 
 def aarch64_init():
     globals().update({
-        'sc_perf_evt_open' : 241,
-        'exit_reasons' : aarch64_exit_reasons,
+        'SC_PERF_EVT_OPEN' : 241,
+        'EXIT_REASONS' : AARCH64_EXIT_REASONS,
     })
 
 def detect_platform():
@@ -274,7 +274,7 @@ def detect_platform():
     for line in file('/proc/cpuinfo').readlines():
         if line.startswith('flags'):
             for flag in line.split():
-                if flag in x86_exit_reasons:
+                if flag in X86_EXIT_REASONS:
                     x86_init(flag)
                     return
         elif line.startswith('vendor_id'):
@@ -298,9 +298,9 @@ def invert(d):
     return dict((x[1], x[0]) for x in d.iteritems())
 
 filters = {}
-filters['kvm_userspace_exit'] = ('reason', invert(userspace_exit_reasons))
-if exit_reasons:
-    filters['kvm_exit'] = ('exit_reason', invert(exit_reasons))
+filters['kvm_userspace_exit'] = ('reason', invert(USERSPACE_EXIT_REASONS))
+if EXIT_REASONS:
+    filters['kvm_exit'] = ('exit_reason', invert(EXIT_REASONS))
 
 libc = ctypes.CDLL('libc.so.6')
 syscall = libc.syscall
@@ -321,7 +321,7 @@ class perf_event_attr(ctypes.Structure):
                 ('bp_len', ctypes.c_uint64),
                 ]
 def _perf_event_open(attr, pid, cpu, group_fd, flags):
-    return syscall(sc_perf_evt_open, ctypes.pointer(attr), ctypes.c_int(pid),
+    return syscall(SC_PERF_EVT_OPEN, ctypes.pointer(attr), ctypes.c_int(pid),
                    ctypes.c_int(cpu), ctypes.c_int(group_fd),
                    ctypes.c_long(flags))
 
@@ -391,14 +391,14 @@ class Event(object):
             err = get_errno()[0]
             raise Exception('perf_event_open failed, errno = ' + err.__str__())
         if filter:
-            fcntl.ioctl(fd, ioctl_numbers['SET_FILTER'], filter)
+            fcntl.ioctl(fd, IOCTL_NUMBERS['SET_FILTER'], filter)
         self.fd = fd
     def enable(self):
-        fcntl.ioctl(self.fd, ioctl_numbers['ENABLE'], 0)
+        fcntl.ioctl(self.fd, IOCTL_NUMBERS['ENABLE'], 0)
     def disable(self):
-        fcntl.ioctl(self.fd, ioctl_numbers['DISABLE'], 0)
+        fcntl.ioctl(self.fd, IOCTL_NUMBERS['DISABLE'], 0)
     def reset(self):
-        fcntl.ioctl(self.fd, ioctl_numbers['RESET'], 0)
+        fcntl.ioctl(self.fd, IOCTL_NUMBERS['RESET'], 0)
 
 class TracepointProvider(object):
     def __init__(self):
@@ -505,8 +505,8 @@ if not os.access('/sys/kernel/debug/kvm', os.F_OK):
     print "and ensure the kvm modules are loaded"
     sys.exit(1)
 
-label_width = 40
-number_width = 10
+LABEL_WIDTH = 40
+NUMBER_WIDTH = 10
 
 def tui(screen, stats):
     curses.use_default_colors()
@@ -524,8 +524,8 @@ def tui(screen, stats):
         screen.erase()
         screen.addstr(0, 0, 'kvm statistics')
         screen.addstr(2, 1, 'Event')
-        screen.addstr(2, 1 + label_width + number_width - len('Total'), 'Total')
-        screen.addstr(2, 1 + label_width + number_width + 8 - len('Current'), 'Current')
+        screen.addstr(2, 1 + LABEL_WIDTH + NUMBER_WIDTH - len('Total'), 'Total')
+        screen.addstr(2, 1 + LABEL_WIDTH + NUMBER_WIDTH + 8 - len('Current'), 'Current')
         row = 3
         s = stats.get()
         def sortkey(x):
@@ -541,9 +541,9 @@ def tui(screen, stats):
                 break
             col = 1
             screen.addstr(row, col, key)
-            col += label_width
+            col += LABEL_WIDTH
             screen.addstr(row, col, '%10d' % (values[0],))
-            col += number_width
+            col += NUMBER_WIDTH
             if values[1] is not None:
                 screen.addstr(row, col, '%8d' % (values[1] / sleeptime,))
             row += 1
-- 
1.8.3.1

  parent reply	other threads:[~2016-01-26 13:47 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-26 13:46 [Qemu-devel] [PULL 00/49] chardev, NBD, cpus, scripts/ changes for 2015-01-26 Paolo Bonzini
2016-01-26 13:46 ` [Qemu-devel] [PULL 01/49] char: remove fixed length filename allocation Paolo Bonzini
2016-01-26 13:46 ` [Qemu-devel] [PULL 02/49] char: convert from GIOChannel to QIOChannel Paolo Bonzini
2016-01-26 13:46 ` [Qemu-devel] [PULL 03/49] char: don't assume telnet initialization will not block Paolo Bonzini
2016-01-26 13:46 ` [Qemu-devel] [PULL 04/49] char: introduce support for TLS encrypted TCP chardev backend Paolo Bonzini
2016-01-26 13:46 ` [Qemu-devel] [PULL 05/49] docs: Style the command and its options in the synopsis Paolo Bonzini
2016-01-26 13:46 ` [Qemu-devel] [PULL 06/49] qemu-char: avoid leak in qemu_chr_open_pp_fd Paolo Bonzini
2016-01-26 13:46 ` [Qemu-devel] [PULL 07/49] scripts/kvm/kvm_stat: Cleanup of multiple imports Paolo Bonzini
2016-01-26 13:46 ` [Qemu-devel] [PULL 08/49] scripts/kvm/kvm_stat: Replaced os.listdir with os.walk Paolo Bonzini
2016-01-26 13:46 ` Paolo Bonzini [this message]
2016-01-26 13:46 ` [Qemu-devel] [PULL 10/49] scripts/kvm/kvm_stat: Removed unneeded PERF constants Paolo Bonzini
2016-01-26 13:46 ` [Qemu-devel] [PULL 11/49] scripts/kvm/kvm_stat: Mark globals in functions Paolo Bonzini
2016-01-26 13:46 ` [Qemu-devel] [PULL 12/49] scripts/kvm/kvm_stat: Invert dictionaries Paolo Bonzini
2016-01-26 13:46 ` [Qemu-devel] [PULL 13/49] scripts/kvm/kvm_stat: Cleanup of path variables Paolo Bonzini
2016-01-26 13:46 ` [Qemu-devel] [PULL 14/49] scripts/kvm/kvm_stat: Improve debugfs access checking Paolo Bonzini
2016-02-02 14:02   ` Christian Borntraeger
2016-02-02 14:25     ` Paolo Bonzini
2016-01-26 13:46 ` [Qemu-devel] [PULL 15/49] scripts/kvm/kvm_stat: Introduce main function Paolo Bonzini
2016-01-26 13:46 ` [Qemu-devel] [PULL 16/49] scripts/kvm/kvm_stat: Fix spaces around keyword assignments Paolo Bonzini
2016-01-26 13:46 ` [Qemu-devel] [PULL 17/49] scripts/kvm/kvm_stat: Rename variables that redefine globals Paolo Bonzini
2016-01-26 13:46 ` [Qemu-devel] [PULL 18/49] scripts/kvm/kvm_stat: Moved DebugfsProvider Paolo Bonzini
2016-01-26 13:46 ` [Qemu-devel] [PULL 19/49] scripts/kvm/kvm_stat: Fixup syscall error reporting Paolo Bonzini
2016-01-26 13:46 ` [Qemu-devel] [PULL 20/49] scripts/kvm/kvm_stat: Set sensible no. files rlimit Paolo Bonzini
2016-01-26 13:46 ` [Qemu-devel] [PULL 21/49] scripts/kvm/kvm_stat: Cleanup of platform detection Paolo Bonzini
2016-01-26 13:46 ` [Qemu-devel] [PULL 22/49] scripts/kvm/kvm_stat: Make cpu detection a function Paolo Bonzini
2016-01-26 13:46 ` [Qemu-devel] [PULL 23/49] scripts/kvm/kvm_stat: Rename _perf_event_open Paolo Bonzini
2016-01-26 13:46 ` [Qemu-devel] [PULL 24/49] scripts/kvm/kvm_stat: Introduce properties for providers Paolo Bonzini
2016-01-26 13:46 ` [Qemu-devel] [PULL 25/49] scripts/kvm/kvm_stat: Cleanup of TracepointProvider Paolo Bonzini
2016-01-26 13:46 ` [Qemu-devel] [PULL 26/49] scripts/kvm/kvm_stat: Cleanup cpu list retrieval Paolo Bonzini
2016-01-26 13:46 ` [Qemu-devel] [PULL 27/49] scripts/kvm/kvm_stat: Encapsulate filters variable Paolo Bonzini
2016-01-26 13:47 ` [Qemu-devel] [PULL 28/49] scripts/kvm/kvm_stat: Cleanup of Stats class Paolo Bonzini
2016-01-26 13:47 ` [Qemu-devel] [PULL 29/49] scripts/kvm/kvm_stat: Cleanup of Groups class Paolo Bonzini
2016-01-26 13:47 ` [Qemu-devel] [PULL 30/49] scripts/kvm/kvm_stat: Cleanup of Event class Paolo Bonzini
2016-01-26 13:47 ` [Qemu-devel] [PULL 31/49] scripts/kvm/kvm_stat: Group arch specific data Paolo Bonzini
2016-01-26 13:47 ` [Qemu-devel] [PULL 32/49] scripts/kvm/kvm_stat: Remove unneeded X86_EXIT_REASONS Paolo Bonzini
2016-01-26 13:47 ` [Qemu-devel] [PULL 33/49] scripts/kvm/kvm_stat: Make tui function a class Paolo Bonzini
2016-01-26 13:47 ` [Qemu-devel] [PULL 34/49] scripts/kvm/kvm_stat: Fix output formatting Paolo Bonzini
2016-01-26 13:47 ` [Qemu-devel] [PULL 35/49] scripts/kvm/kvm_stat: Cleanup and pre-init perf_event_attr Paolo Bonzini
2016-01-26 13:47 ` [Qemu-devel] [PULL 36/49] scripts/kvm/kvm_stat: Read event values as u64 Paolo Bonzini
2016-01-26 13:47 ` [Qemu-devel] [PULL 37/49] scripts/kvm/kvm_stat: Fix rlimit for unprivileged users Paolo Bonzini
2016-01-26 13:47 ` [Qemu-devel] [PULL 38/49] scripts/kvm/kvm_stat: Fixup filtering Paolo Bonzini
2016-01-26 13:47 ` [Qemu-devel] [PULL 39/49] scripts/kvm/kvm_stat: Add interactive filtering Paolo Bonzini
2016-01-26 13:47 ` [Qemu-devel] [PULL 40/49] scripts/kvm/kvm_stat: Add optparse description Paolo Bonzini
2016-01-26 13:47 ` [Qemu-devel] [PULL 41/49] cpus: use broadcast on qemu_pause_cond Paolo Bonzini
2016-01-26 13:47 ` [Qemu-devel] [PULL 42/49] memory: exit when hugepage allocation fails if mem-prealloc Paolo Bonzini
2016-01-26 13:47 ` [Qemu-devel] [PULL 43/49] nbd: add missed aio_context_acquire in nbd_export_new Paolo Bonzini
2016-01-26 13:47 ` [Qemu-devel] [PULL 44/49] scripts/dump-guest-memory.py: Move constants to the top Paolo Bonzini
2016-01-26 13:47 ` [Qemu-devel] [PULL 45/49] scripts/dump-guest-memory.py: Make methods functions Paolo Bonzini
2016-01-26 13:47 ` [Qemu-devel] [PULL 46/49] scripts/dump-guest-memory.py: Improve python 3 compatibility Paolo Bonzini
2016-01-26 13:47 ` [Qemu-devel] [PULL 47/49] scripts/dump-guest-memory.py: Cleanup functions Paolo Bonzini
2016-01-26 13:47 ` [Qemu-devel] [PULL 48/49] scripts/dump-guest-memory.py: Introduce multi-arch support Paolo Bonzini
2016-01-26 13:47 ` [Qemu-devel] [PULL 49/49] scripts/dump-guest-memory.py: Fix module docstring Paolo Bonzini
2016-01-26 14:38 ` [Qemu-devel] [PULL 00/49] chardev, NBD, cpus, scripts/ changes for 2015-01-26 Peter Maydell
2016-01-26 15:29   ` Daniel P. Berrange
2016-01-26 16:06   ` [Qemu-devel] [PATCH] char: make io_channel_send be used unconditionally Daniel P. Berrange

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1453816041-36362-10-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=frankja@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).