Commit a4645289 authored by Brenden Blanco's avatar Brenden Blanco

Merge pull request #346 from brendangregg/master

biosnoop.py: use one map instead of two
parents aa1e6ca3 31cd1041
...@@ -21,23 +21,21 @@ b = BPF(text=""" ...@@ -21,23 +21,21 @@ b = BPF(text="""
#include <linux/blkdev.h> #include <linux/blkdev.h>
struct val_t { struct val_t {
u32 pid;
char name[TASK_COMM_LEN]; char name[TASK_COMM_LEN];
}; };
BPF_HASH(start, struct request *); BPF_HASH(start, struct request *);
BPF_HASH(pidbyreq, struct request *, u32); BPF_HASH(infobyreq, struct request *, struct val_t);
BPF_HASH(commbyreq, struct request *, struct val_t);
// cache PID and comm by-req // cache PID and comm by-req
int trace_pid_start(struct pt_regs *ctx, struct request *req) int trace_pid_start(struct pt_regs *ctx, struct request *req)
{ {
u32 pid;
struct val_t val = {}; struct val_t val = {};
pid = bpf_get_current_pid_tgid();
pidbyreq.update(&req, &pid);
if (bpf_get_current_comm(&val.name, sizeof(val.name)) == 0) { if (bpf_get_current_comm(&val.name, sizeof(val.name)) == 0) {
commbyreq.update(&req, &val); val.pid = bpf_get_current_pid_tgid();
infobyreq.update(&req, &val);
} }
return 0; return 0;
...@@ -74,12 +72,11 @@ int trace_req_completion(struct pt_regs *ctx, struct request *req) ...@@ -74,12 +72,11 @@ int trace_req_completion(struct pt_regs *ctx, struct request *req)
// As bpf_trace_prink() is limited to a maximum of 1 string and 2 // As bpf_trace_prink() is limited to a maximum of 1 string and 2
// integers, we'll use more than one to output the data. // integers, we'll use more than one to output the data.
// //
valp = commbyreq.lookup(&req); valp = infobyreq.lookup(&req);
pidp = pidbyreq.lookup(&req); if (valp == 0) {
if (pidp == 0 || valp == 0) {
bpf_trace_printk("0 0 ? %d\\n", req->__data_len); bpf_trace_printk("0 0 ? %d\\n", req->__data_len);
} else { } else {
bpf_trace_printk("0 %d %s %d\\n", *pidp, valp->name, bpf_trace_printk("0 %d %s %d\\n", valp->pid, valp->name,
req->__data_len); req->__data_len);
} }
...@@ -93,8 +90,7 @@ int trace_req_completion(struct pt_regs *ctx, struct request *req) ...@@ -93,8 +90,7 @@ int trace_req_completion(struct pt_regs *ctx, struct request *req)
} }
start.delete(&req); start.delete(&req);
pidbyreq.delete(&req); infobyreq.delete(&req);
commbyreq.delete(&req);
return 0; return 0;
} }
......
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
# For Linux, uses BCC, eBPF. See .c file. # For Linux, uses BCC, eBPF. See .c file.
# #
# USAGE: bitesize # USAGE: bitesize
# Ctrl-C will print the partially gathered histogram then exit.
# #
# Ctrl-C will print the partially gathered histogram then exit.
# #
# Copyright (c) 2016 Allan McAleavy # Copyright (c) 2016 Allan McAleavy
# Licensed under the Apache License, Version 2.0 (the "License") # Licensed under the Apache License, Version 2.0 (the "License")
...@@ -19,7 +19,7 @@ bpf_text = """ ...@@ -19,7 +19,7 @@ bpf_text = """
#include <uapi/linux/ptrace.h> #include <uapi/linux/ptrace.h>
#include <linux/blkdev.h> #include <linux/blkdev.h>
struct proc_key_t { struct proc_key_t {
char name[TASK_COMM_LEN]; char name[TASK_COMM_LEN];
u64 slot; u64 slot;
}; };
...@@ -41,12 +41,12 @@ int trace_pid_start(struct pt_regs *ctx, struct request *req) ...@@ -41,12 +41,12 @@ int trace_pid_start(struct pt_regs *ctx, struct request *req)
return 0; return 0;
} }
int do_count (struct pt_regs *ctx, struct request *req) int do_count(struct pt_regs *ctx, struct request *req)
{ {
struct val_t *valp; struct val_t *valp;
valp = commbyreq.lookup(&req); valp = commbyreq.lookup(&req);
if ( valp == 0) { if (valp == 0) {
return 0; return 0;
} }
...@@ -55,7 +55,7 @@ int do_count (struct pt_regs *ctx, struct request *req) ...@@ -55,7 +55,7 @@ int do_count (struct pt_regs *ctx, struct request *req)
bpf_probe_read(&key.name, sizeof(key.name),valp->name); bpf_probe_read(&key.name, sizeof(key.name),valp->name);
dist.increment(key); dist.increment(key);
} }
return 0; return 0;
} }
""" """
...@@ -72,4 +72,4 @@ dist = b.get_table("dist") ...@@ -72,4 +72,4 @@ dist = b.get_table("dist")
try: try:
sleep(99999999) sleep(99999999)
except KeyboardInterrupt: except KeyboardInterrupt:
dist.print_log2_hist("Kbytes", "Process Name:") dist.print_log2_hist("Kbytes", "Process Name")
Example of BCC tool bitesize.py Examples of bitesize.py, the Linux bcc/eBPF version.
The aim of this tool is to show I/O distribution for requested block sizes, by process name. The aim of this tool is to show I/O distribution for requested block sizes, by process name.
...@@ -6,13 +7,13 @@ The aim of this tool is to show I/O distribution for requested block sizes, by p ...@@ -6,13 +7,13 @@ The aim of this tool is to show I/O distribution for requested block sizes, by p
Tracing... Hit Ctrl-C to end. Tracing... Hit Ctrl-C to end.
^C ^C
Process Name: = 'kworker/u128:1' Process Name = 'kworker/u128:1'
Kbytes : count distribution Kbytes : count distribution
0 -> 1 : 1 |******************** | 0 -> 1 : 1 |******************** |
2 -> 3 : 0 | | 2 -> 3 : 0 | |
4 -> 7 : 2 |****************************************| 4 -> 7 : 2 |****************************************|
Process Name: = 'bitesize.py' Process Name = 'bitesize.py'
Kbytes : count distribution Kbytes : count distribution
0 -> 1 : 0 | | 0 -> 1 : 0 | |
2 -> 3 : 0 | | 2 -> 3 : 0 | |
...@@ -23,7 +24,7 @@ Process Name: = 'bitesize.py' ...@@ -23,7 +24,7 @@ Process Name: = 'bitesize.py'
64 -> 127 : 0 | | 64 -> 127 : 0 | |
128 -> 255 : 1 |****************************************| 128 -> 255 : 1 |****************************************|
Process Name: = 'dd' Process Name = 'dd'
Kbytes : count distribution Kbytes : count distribution
0 -> 1 : 3 | | 0 -> 1 : 3 | |
2 -> 3 : 0 | | 2 -> 3 : 0 | |
...@@ -37,13 +38,13 @@ Process Name: = 'dd' ...@@ -37,13 +38,13 @@ Process Name: = 'dd'
512 -> 1023 : 0 | | 512 -> 1023 : 0 | |
1024 -> 2047 : 488 |****************************************| 1024 -> 2047 : 488 |****************************************|
Process Name: = 'jbd2/dm-1-8' Process Name = 'jbd2/dm-1-8'
Kbytes : count distribution Kbytes : count distribution
0 -> 1 : 0 | | 0 -> 1 : 0 | |
2 -> 3 : 0 | | 2 -> 3 : 0 | |
4 -> 7 : 1 |****************************************| 4 -> 7 : 1 |****************************************|
Process Name: = 'cat' Process Name = 'cat'
Kbytes : count distribution Kbytes : count distribution
0 -> 1 : 1 | | 0 -> 1 : 1 | |
2 -> 3 : 0 | | 2 -> 3 : 0 | |
...@@ -55,19 +56,19 @@ Process Name: = 'cat' ...@@ -55,19 +56,19 @@ Process Name: = 'cat'
128 -> 255 : 0 | | 128 -> 255 : 0 | |
256 -> 511 : 1924 |****************************************| 256 -> 511 : 1924 |****************************************|
Process Name: = 'ntpd' Process Name = 'ntpd'
Kbytes : count distribution Kbytes : count distribution
0 -> 1 : 0 | | 0 -> 1 : 0 | |
2 -> 3 : 0 | | 2 -> 3 : 0 | |
4 -> 7 : 104 |****************************************| 4 -> 7 : 104 |****************************************|
Process Name: = 'vmtoolsd' Process Name = 'vmtoolsd'
Kbytes : count distribution Kbytes : count distribution
0 -> 1 : 0 | | 0 -> 1 : 0 | |
2 -> 3 : 0 | | 2 -> 3 : 0 | |
4 -> 7 : 1 |****************************************| 4 -> 7 : 1 |****************************************|
Process Name: = 'bash' Process Name = 'bash'
Kbytes : count distribution Kbytes : count distribution
0 -> 1 : 0 | | 0 -> 1 : 0 | |
2 -> 3 : 0 | | 2 -> 3 : 0 | |
...@@ -75,7 +76,7 @@ Process Name: = 'bash' ...@@ -75,7 +76,7 @@ Process Name: = 'bash'
8 -> 15 : 0 | | 8 -> 15 : 0 | |
16 -> 31 : 2 |****************************************| 16 -> 31 : 2 |****************************************|
Process Name: = 'jbd2/sdb-8' Process Name = 'jbd2/sdb-8'
Kbytes : count distribution Kbytes : count distribution
0 -> 1 : 0 | | 0 -> 1 : 0 | |
2 -> 3 : 0 | | 2 -> 3 : 0 | |
...@@ -86,7 +87,3 @@ Process Name: = 'jbd2/sdb-8' ...@@ -86,7 +87,3 @@ Process Name: = 'jbd2/sdb-8'
We can see from above that there was a dd command being run which generated 488 IOPS between 1MB and 2MB, we can also see the We can see from above that there was a dd command being run which generated 488 IOPS between 1MB and 2MB, we can also see the
cat command generating 1924 IOPS between 256Kb and 512Kb. cat command generating 1924 IOPS between 256Kb and 512Kb.
See also systemtap version:
https://github.com/brendangregg/systemtap-lwtools/blob/master/disk/bitesize-nd.stp
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment