From: Janosch Frank <frankja@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: cornelia.huck@de.ibm.com, frankja@linux.vnet.ibm.com
Subject: [Qemu-devel] [PATCH 03/34] scripts/kvm/kvm_stat: Make constants uppercase
Date: Thu, 10 Dec 2015 13:12:33 +0100 [thread overview]
Message-ID: <1449749584-23214-4-git-send-email-frankja@linux.vnet.ibm.com> (raw)
In-Reply-To: <1449749584-23214-1-git-send-email-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>
---
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
--
2.3.0
next prev parent reply other threads:[~2015-12-10 12:14 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-10 12:12 [Qemu-devel] [PATCH 00/34] kvm_stat: Cleanup and fixup Janosch Frank
2015-12-10 12:12 ` [Qemu-devel] [PATCH 01/34] scripts/kvm/kvm_stat: Cleanup of multiple imports Janosch Frank
2015-12-10 12:12 ` [Qemu-devel] [PATCH 02/34] scripts/kvm/kvm_stat: Replaced os.listdir with os.walk Janosch Frank
2015-12-10 12:12 ` Janosch Frank [this message]
2015-12-10 12:12 ` [Qemu-devel] [PATCH 04/34] scripts/kvm/kvm_stat: Removed unneeded PERF constants Janosch Frank
2015-12-10 12:12 ` [Qemu-devel] [PATCH 05/34] scripts/kvm/kvm_stat: Mark globals in functions Janosch Frank
2015-12-10 12:12 ` [Qemu-devel] [PATCH 06/34] scripts/kvm/kvm_stat: Invert dictionaries Janosch Frank
2015-12-10 12:12 ` [Qemu-devel] [PATCH 07/34] scripts/kvm/kvm_stat: Cleanup of path variables Janosch Frank
2016-01-07 14:56 ` Paolo Bonzini
2016-01-07 16:58 ` Janosch Frank
2015-12-10 12:12 ` [Qemu-devel] [PATCH 08/34] scripts/kvm/kvm_stat: Improve debugfs access checking Janosch Frank
2015-12-10 12:12 ` [Qemu-devel] [PATCH 09/34] scripts/kvm/kvm_stat: Introduce main function Janosch Frank
2015-12-10 12:12 ` [Qemu-devel] [PATCH 10/34] scripts/kvm/kvm_stat: Fix spaces around keyword assignments Janosch Frank
2015-12-10 12:12 ` [Qemu-devel] [PATCH 11/34] scripts/kvm/kvm_stat: Rename variables that redefine globals Janosch Frank
2015-12-10 12:12 ` [Qemu-devel] [PATCH 12/34] scripts/kvm/kvm_stat: Moved DebugfsProvider Janosch Frank
2015-12-10 12:12 ` [Qemu-devel] [PATCH 13/34] scripts/kvm/kvm_stat: Fixup syscall error reporting Janosch Frank
2015-12-10 12:12 ` [Qemu-devel] [PATCH 14/34] scripts/kvm/kvm_stat: Set sensible no. files rlimit Janosch Frank
2015-12-10 12:12 ` [Qemu-devel] [PATCH 15/34] scripts/kvm/kvm_stat: Cleanup of platform detection Janosch Frank
2015-12-10 12:12 ` [Qemu-devel] [PATCH 16/34] scripts/kvm/kvm_stat: Make cpu detection a function Janosch Frank
2015-12-10 12:12 ` [Qemu-devel] [PATCH 17/34] scripts/kvm/kvm_stat: Rename _perf_event_open Janosch Frank
2015-12-10 12:12 ` [Qemu-devel] [PATCH 18/34] scripts/kvm/kvm_stat: Introduce properties for providers Janosch Frank
2015-12-10 12:12 ` [Qemu-devel] [PATCH 19/34] scripts/kvm/kvm_stat: Cleanup of TracepointProvider Janosch Frank
2015-12-10 12:12 ` [Qemu-devel] [PATCH 20/34] scripts/kvm/kvm_stat: Cleanup cpu list retrieval Janosch Frank
2016-01-07 15:21 ` Paolo Bonzini
2016-01-07 16:56 ` Janosch Frank
2016-01-07 17:02 ` Paolo Bonzini
2015-12-10 12:12 ` [Qemu-devel] [PATCH 21/34] scripts/kvm/kvm_stat: Encapsulate filters variable Janosch Frank
2015-12-10 12:12 ` [Qemu-devel] [PATCH 22/34] scripts/kvm/kvm_stat: Cleanup of Stats class Janosch Frank
2015-12-10 12:12 ` [Qemu-devel] [PATCH 23/34] scripts/kvm/kvm_stat: Cleanup of Groups class Janosch Frank
2015-12-10 12:12 ` [Qemu-devel] [PATCH 24/34] scripts/kvm/kvm_stat: Cleanup of Event class Janosch Frank
2016-01-07 15:25 ` Paolo Bonzini
2015-12-10 12:12 ` [Qemu-devel] [PATCH 25/34] scripts/kvm/kvm_stat: Group arch specific data Janosch Frank
2016-01-07 15:30 ` Paolo Bonzini
2015-12-10 12:12 ` [Qemu-devel] [PATCH 26/34] scripts/kvm/kvm_stat: Remove unneeded X86_EXIT_REASONS Janosch Frank
2015-12-10 12:12 ` [Qemu-devel] [PATCH 27/34] scripts/kvm/kvm_stat: Make tui function a class Janosch Frank
2016-01-07 15:40 ` Paolo Bonzini
2015-12-10 12:12 ` [Qemu-devel] [PATCH 28/34] scripts/kvm/kvm_stat: Fix output formatting Janosch Frank
2015-12-10 12:12 ` [Qemu-devel] [PATCH 29/34] scripts/kvm/kvm_stat: Move to argparse and add description Janosch Frank
2016-01-07 15:41 ` Paolo Bonzini
2016-01-07 15:54 ` Janosch Frank
2016-01-07 16:02 ` Paolo Bonzini
2015-12-10 12:13 ` [Qemu-devel] [PATCH 30/34] scripts/kvm/kvm_stat: Cleanup and pre-init perf_event_attr Janosch Frank
2015-12-10 12:13 ` [Qemu-devel] [PATCH 31/34] scripts/kvm/kvm_stat: Read event values as u64 Janosch Frank
2015-12-10 12:13 ` [Qemu-devel] [PATCH 32/34] scripts/kvm/kvm_stat: Fix rlimit for unprivileged users Janosch Frank
2015-12-10 12:13 ` [Qemu-devel] [PATCH 33/34] scripts/kvm/kvm_stat: Fixup filtering Janosch Frank
2015-12-10 12:13 ` [Qemu-devel] [PATCH 34/34] scripts/kvm/kvm_stat: Add interactive filtering Janosch Frank
2015-12-15 9:56 ` [Qemu-devel] [PATCH 00/34] kvm_stat: Cleanup and fixup Cornelia Huck
2016-01-07 13:41 ` Cornelia Huck
2016-01-07 13:50 ` Paolo Bonzini
2016-01-07 15:44 ` Paolo Bonzini
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=1449749584-23214-4-git-send-email-frankja@linux.vnet.ibm.com \
--to=frankja@linux.vnet.ibm.com \
--cc=cornelia.huck@de.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).