Commit baebe807 authored by Brendan Gregg's avatar Brendan Gregg

use one map instead of two

parent aa1e6ca3
...@@ -21,12 +21,12 @@ b = BPF(text=""" ...@@ -21,12 +21,12 @@ 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)
...@@ -35,9 +35,9 @@ int trace_pid_start(struct pt_regs *ctx, struct request *req) ...@@ -35,9 +35,9 @@ int trace_pid_start(struct pt_regs *ctx, struct request *req)
struct val_t val = {}; struct val_t val = {};
pid = bpf_get_current_pid_tgid(); 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 = pid;
infobyreq.update(&req, &val);
} }
return 0; return 0;
...@@ -74,12 +74,11 @@ int trace_req_completion(struct pt_regs *ctx, struct request *req) ...@@ -74,12 +74,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 +92,7 @@ int trace_req_completion(struct pt_regs *ctx, struct request *req) ...@@ -93,8 +92,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;
} }
......
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