7 Star 13 Fork 3

Gitee 极速下载/bcc

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/iovisor/bcc
克隆/下载
bitesize.py 1.14 KB
一键复制 编辑 原始数据 按行查看 历史
#!/usr/bin/env python
#
# bitehist.py Block I/O size histogram.
# For Linux, uses BCC, eBPF. See .c file.
#
# USAGE: bitesize
#
# Ctrl-C will print the partially gathered histogram then exit.
#
# Copyright (c) 2016 Allan McAleavy
# Licensed under the Apache License, Version 2.0 (the "License")
#
# 05-Feb-2016 Allan McAleavy ran pep8 against file
# 19-Mar-2019 Brendan Gregg Switched to use tracepoints.
from bcc import BPF
from time import sleep
bpf_text = """
#include <uapi/linux/ptrace.h>
#include <linux/blkdev.h>
struct proc_key_t {
char name[TASK_COMM_LEN];
u64 slot;
};
BPF_HISTOGRAM(dist, struct proc_key_t);
TRACEPOINT_PROBE(block, block_rq_issue)
{
struct proc_key_t key = {.slot = bpf_log2l(args->bytes / 1024)};
bpf_probe_read_kernel(&key.name, sizeof(key.name), args->comm);
dist.atomic_increment(key);
return 0;
}
"""
# load BPF program
b = BPF(text=bpf_text)
print("Tracing block I/O... Hit Ctrl-C to end.")
# trace until Ctrl-C
dist = b.get_table("dist")
try:
sleep(99999999)
except KeyboardInterrupt:
dist.print_log2_hist("Kbytes", "Process Name",
section_print_fn=bytes.decode)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C/C++
1
https://gitee.com/mirrors/bcc.git
git@gitee.com:mirrors/bcc.git
mirrors
bcc
bcc
master

搜索帮助