def __init__(self, filename, max_events=0):
if not os.path.exists("/proc/iotracer"):
raise AssertionError('iotracer kernel module is not loaded')
self._filename = filename
cmd = 'readlink -e $(df --output=source ' + filename + ' | tail -1)'
cmd += ' | cut -d/ -f3'
try:
out = subprocess.check_output(cmd, stderr=subprocess.DEVNULL,
universal_newlines=True,
shell=True)
except subprocess.SubprocessError:
print('fail to get block device for %s' % filename)
raise
else:
bdev = out.rstrip(b'\n')
try:
ino = os.stat(filename).st_ino
with open('/proc/iotracer/control', 'w') as fctl:
cmd = 'add %s' % self._filename
if max_events:
cmd += ' %s' % max_events
print(cmd, file=fctl)
except OSError:
print('fail to add %s to iotracer monitoring' % filename)
raise
else:
self._procdir = '/proc/iotracer/%s_%s' % (bdev, ino)
IoTracerLog.__init__(self, self._procdir + '/log')
评论列表
文章目录