Skip to content

Commit

Permalink
tools: Use u32 as pid field type
Browse files Browse the repository at this point in the history
  • Loading branch information
xingfeng2510 authored and yonghong-song committed May 6, 2022
1 parent 2957738 commit 0064feb
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 34 deletions.
6 changes: 2 additions & 4 deletions tools/bashreadline.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#include <linux/sched.h>
struct str_t {
u64 pid;
u32 pid;
char str[80];
};
Expand All @@ -47,11 +47,9 @@
int printret(struct pt_regs *ctx) {
struct str_t data = {};
char comm[TASK_COMM_LEN] = {};
u32 pid;
if (!PT_REGS_RC(ctx))
return 0;
pid = bpf_get_current_pid_tgid() >> 32;
data.pid = pid;
data.pid = bpf_get_current_pid_tgid() >> 32;
bpf_probe_read_user(&data.str, sizeof(data.str), (void *)PT_REGS_RC(ctx));
bpf_get_current_comm(&comm, sizeof(comm));
Expand Down
12 changes: 7 additions & 5 deletions tools/btrfsslower.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@
// XXX: switch some to u32's when supported
u64 ts_us;
u64 type;
u64 size;
u32 size;
u64 offset;
u64 delta_us;
u64 pid;
u32 pid;
char task[TASK_COMM_LEN];
char file[DNAME_INLINE_LEN];
};
Expand Down Expand Up @@ -219,9 +219,11 @@
return 0;
// populate output struct
u32 size = PT_REGS_RC(ctx);
struct data_t data = {.type = type, .size = size, .delta_us = delta_us,
.pid = pid};
struct data_t data = {};
data.type = type;
data.size = PT_REGS_RC(ctx);
data.delta_us = delta_us;
data.pid = pid;
data.ts_us = ts / 1000;
data.offset = valp->offset;
bpf_get_current_comm(&data.task, sizeof(data.task));
Expand Down
2 changes: 1 addition & 1 deletion tools/dbslower.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
};
struct data_t {
u64 pid;
u32 pid;
u64 timestamp;
u64 duration;
char query[256];
Expand Down
12 changes: 7 additions & 5 deletions tools/ext4slower.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@
// XXX: switch some to u32's when supported
u64 ts_us;
u64 type;
u64 size;
u32 size;
u64 offset;
u64 delta_us;
u64 pid;
u32 pid;
char task[TASK_COMM_LEN];
char file[DNAME_INLINE_LEN];
};
Expand Down Expand Up @@ -212,9 +212,11 @@
return 0;
// populate output struct
u32 size = PT_REGS_RC(ctx);
struct data_t data = {.type = type, .size = size, .delta_us = delta_us,
.pid = pid};
struct data_t data = {};
data.type = type;
data.size = PT_REGS_RC(ctx);
data.delta_us = delta_us;
data.pid = pid;
data.ts_us = ts / 1000;
data.offset = valp->offset;
bpf_get_current_comm(&data.task, sizeof(data.task));
Expand Down
4 changes: 2 additions & 2 deletions tools/killsnoop.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@
#include <linux/sched.h>
struct val_t {
u64 pid;
u32 pid;
int sig;
int tpid;
char comm[TASK_COMM_LEN];
};
struct data_t {
u64 pid;
u32 pid;
int tpid;
int sig;
int ret;
Expand Down
5 changes: 2 additions & 3 deletions tools/mdflush.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <linux/bio.h>
struct data_t {
u64 pid;
u32 pid;
char comm[TASK_COMM_LEN];
char disk[DISK_NAME_LEN];
};
Expand All @@ -32,8 +32,7 @@
int kprobe__md_flush_request(struct pt_regs *ctx, void *mddev, struct bio *bio)
{
struct data_t data = {};
u32 pid = bpf_get_current_pid_tgid() >> 32;
data.pid = pid;
data.pid = bpf_get_current_pid_tgid() >> 32;
bpf_get_current_comm(&data.comm, sizeof(data.comm));
/*
* The following deals with kernel version changes (in mainline 4.14 and 5.12, although
Expand Down
2 changes: 1 addition & 1 deletion tools/mysqld_qslower.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def usage():
};
struct data_t {
u64 pid;
u32 pid;
u64 ts;
u64 delta;
char query[QUERY_MAX];
Expand Down
2 changes: 1 addition & 1 deletion tools/nfsslower.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
u64 size;
u64 offset;
u64 delta_us;
u64 pid;
u32 pid;
char task[TASK_COMM_LEN];
char file[DNAME_INLINE_LEN];
};
Expand Down
4 changes: 2 additions & 2 deletions tools/offcputime.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ def signal_ignore(signal, frame):
#define MAXBLOCK_US MAXBLOCK_US_VALUEULL
struct key_t {
u64 pid;
u64 tgid;
u32 pid;
u32 tgid;
int user_stack_id;
int kernel_stack_id;
char name[TASK_COMM_LEN];
Expand Down
4 changes: 2 additions & 2 deletions tools/runqlat.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@
#include <linux/init_task.h>
typedef struct pid_key {
u64 id; // work around
u32 id;
u64 slot;
} pid_key_t;
typedef struct pidns_key {
u64 id; // work around
u32 id;
u64 slot;
} pidns_key_t;
Expand Down
4 changes: 2 additions & 2 deletions tools/solisten.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@
// Common structure for UDP/TCP IPv4/IPv6
struct listen_evt_t {
u64 ts_us;
u64 pid;
u64 backlog;
u32 pid;
int backlog;
u64 netns;
u64 proto; // familiy << 16 | type
u64 lport; // use only 16 bits
Expand Down
2 changes: 1 addition & 1 deletion tools/xfsslower.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
u64 size;
u64 offset;
u64 delta_us;
u64 pid;
u32 pid;
char task[TASK_COMM_LEN];
char file[DNAME_INLINE_LEN];
};
Expand Down
12 changes: 7 additions & 5 deletions tools/zfsslower.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@
// XXX: switch some to u32's when supported
u64 ts_us;
u64 type;
u64 size;
u32 size;
u64 offset;
u64 delta_us;
u64 pid;
u32 pid;
char task[TASK_COMM_LEN];
char file[DNAME_INLINE_LEN];
};
Expand Down Expand Up @@ -182,9 +182,11 @@
return 0;
// populate output struct
u32 size = PT_REGS_RC(ctx);
struct data_t data = {.type = type, .size = size, .delta_us = delta_us,
.pid = pid};
struct data_t data = {};
data.type = type;
data.size = PT_REGS_RC(ctx);
data.delta_us = delta_us;
data.pid = pid;
data.ts_us = ts / 1000;
data.offset = valp->offset;
bpf_get_current_comm(&data.task, sizeof(data.task));
Expand Down

0 comments on commit 0064feb

Please sign in to comment.