# the COPYING file in the top-level directory.
import curses
-import sys, os, time, optparse, ctypes
-from ctypes import *
+import sys
+import os
+import time
+import optparse
+import ctypes
+import fcntl
+import resource
+import struct
+import re
+from collections import defaultdict
class DebugfsProvider(object):
def __init__(self):
if exit_reasons:
filters['kvm_exit'] = ('exit_reason', invert(exit_reasons))
-import struct, array
-
libc = ctypes.CDLL('libc.so.6')
syscall = libc.syscall
get_errno = libc.__errno_location
-get_errno.restype = POINTER(c_int)
+get_errno.restype = ctypes.POINTER(ctypes.c_int)
class perf_event_attr(ctypes.Structure):
_fields_ = [('type', ctypes.c_uint32),
PERF_FORMAT_ID = 1 << 2
PERF_FORMAT_GROUP = 1 << 3
-import re
-
sys_tracing = '/sys/kernel/debug/tracing'
class Group(object):
err = get_errno()[0]
raise Exception('perf_event_open failed, errno = ' + err.__str__())
if filter:
- import fcntl
fcntl.ioctl(fd, ioctl_numbers['SET_FILTER'], filter)
self.fd = fd
def enable(self):
- import fcntl
fcntl.ioctl(self.fd, ioctl_numbers['ENABLE'], 0)
def disable(self):
- import fcntl
fcntl.ioctl(self.fd, ioctl_numbers['DISABLE'], 0)
def reset(self):
- import fcntl
fcntl.ioctl(self.fd, ioctl_numbers['RESET'], 0)
class TracepointProvider(object):
def _setup(self, _fields):
self._fields = _fields
cpus = self._online_cpus()
- import resource
nfiles = len(cpus) * 1000
resource.setrlimit(resource.RLIMIT_NOFILE, (nfiles, nfiles))
events = []
else:
event.disable()
def read(self):
- from collections import defaultdict
ret = defaultdict(int)
for group in self.group_leaders:
for name, val in group.read().iteritems():
self._update()
def _update(self):
def wanted(key):
- import re
if not self.fields_filter:
return True
return re.match(self.fields_filter, key) is not None
if options.log:
log(stats)
elif not options.once:
- import curses.wrapper
curses.wrapper(tui, stats)
else:
batch(stats)