一,工具简介

vfsreadlat.py工具用于跟踪VFS读取延迟分布情况,示例的运行结果是一个函数延迟分布直方图。

二,代码示例

#!/usr/bin/python

# USAGE: vfsreadlat.py [interval [count]]
#
# The default interval is 5 seconds. A Ctrl-C will print the partially
# gathered histogram then exit.
#
# Copyright (c) 2015 Brendan Gregg.
# Licensed under the Apache License, Version 2.0 (the "License")
#
# 15-Aug-2015	Brendan Gregg	Created this.

from __future__ import print_function
from bcc import BPF
from time import sleep
from sys import argv

def usage():
	print("USAGE: %s [interval [count]]" % argv[0])
	exit()

# 参数
interval = 5
count = -1
if len(argv) > 1:
	try:
		interval = int(argv[1])
		if interval == 0:
			raise
		if len(argv) > 2:
			count = int(argv[2])
	except:	# also catches -h, --help
		usage()

# 加载BPF程序
b = BPF(src_file = "vfsreadlat.c")
b.attach_kprobe(event="vfs_read
02-19 22:46