iotracer.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:iotracer 作者: b-com 项目源码 文件源码
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')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号