Skip to content

Commit

Permalink
Fix tgid detection (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagoftsm authored Nov 15, 2023
1 parent b0be1dc commit ad1414e
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/cachestat.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ static __always_inline int netdata_common_page_cache_lru()
libnetdata_update_s64(&fill->misses, 1);
} else {
data.ct = bpf_ktime_get_ns();
data.tgid = tgid;
libnetdata_update_uid_gid(&data.uid, &data.gid);
bpf_get_current_comm(&data.name, TASK_COMM_LEN);

Expand Down Expand Up @@ -91,6 +92,7 @@ static __always_inline int netdata_common_page_accessed()
libnetdata_update_s64(&fill->total, 1);
} else {
data.ct = bpf_ktime_get_ns();
data.tgid = tgid;
libnetdata_update_uid_gid(&data.uid, &data.gid);
bpf_get_current_comm(&data.name, TASK_COMM_LEN);

Expand Down Expand Up @@ -118,6 +120,7 @@ static __always_inline int netdata_common_page_dirtied()
libnetdata_update_s64(&fill->misses, -1);
} else {
data.ct = bpf_ktime_get_ns();
data.tgid = tgid;
libnetdata_update_uid_gid(&data.uid, &data.gid);
bpf_get_current_comm(&data.name, TASK_COMM_LEN);

Expand Down Expand Up @@ -147,6 +150,7 @@ static __always_inline int netdata_common_buffer_dirty()
libnetdata_update_u64(&fill->dirty, 1);
} else {
data.ct = bpf_ktime_get_ns();
data.tgid = tgid;
libnetdata_update_uid_gid(&data.uid, &data.gid);
bpf_get_current_comm(&data.name, TASK_COMM_LEN);

Expand Down
2 changes: 2 additions & 0 deletions src/dc.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ static __always_inline int netdata_common_lookup_fast()
libnetdata_update_u64(&fill->references, 1);
} else {
data.references = 1;
data.tgid = tgid;
libnetdata_update_uid_gid(&data.uid, &data.gid);
bpf_get_current_comm(&data.name, TASK_COMM_LEN);
bpf_map_update_elem(&dcstat_pid, &key, &data, BPF_ANY);
Expand All @@ -90,6 +91,7 @@ static __always_inline int netdata_common_d_lookup(long ret)
libnetdata_update_u64(&fill->slow, 1);
} else {
data.slow = 1;
data.tgid = tgid;
libnetdata_update_uid_gid(&data.uid, &data.gid);
bpf_get_current_comm(&data.name, TASK_COMM_LEN);
bpf_map_update_elem(&dcstat_pid, &key, &data, BPF_ANY);
Expand Down
2 changes: 2 additions & 0 deletions src/fd.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ static __always_inline int netdata_apps_do_sys_openat2(long ret)
libnetdata_update_u32(&fill->open_err, 1) ;
} else {
data.ct = bpf_ktime_get_ns();
data.tgid = tgid;
libnetdata_update_uid_gid(&data.uid, &data.gid);
bpf_get_current_comm(&data.name, TASK_COMM_LEN);
data.open_call = 1;
Expand Down Expand Up @@ -111,6 +112,7 @@ static __always_inline int netdata_apps_close_fd(int ret)
libnetdata_update_u32(&fill->close_err, 1) ;
} else {
data.ct = bpf_ktime_get_ns();
data.tgid = tgid;
libnetdata_update_uid_gid(&data.uid, &data.gid);
bpf_get_current_comm(&data.name, TASK_COMM_LEN);
data.close_call = 1;
Expand Down
3 changes: 3 additions & 0 deletions src/process.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ static __always_inline int netdata_common_fork_clone(int ret)
}
} else {
netdata_fill_common_process_data(&data);
data.tgid = tgid;
if (ret < 0) {
data.task_err = 1;
}
Expand Down Expand Up @@ -164,6 +165,7 @@ int netdata_tracepoint_sched_process_exec(struct netdata_sched_process_exec *ptr
libnetdata_update_u32(&fill->create_process, 1) ;
} else {
netdata_fill_common_process_data(&data);
data.tgid = tgid;
data.create_process = 1;

bpf_map_update_elem(&tbl_pid_stats, &key, &data, BPF_ANY);
Expand Down Expand Up @@ -203,6 +205,7 @@ int netdata_tracepoint_sched_process_fork(struct netdata_sched_process_fork *ptr
libnetdata_update_u32(&fill->create_thread, 1);
} else {
netdata_fill_common_process_data(&data);
data.tgid = tgid;
data.create_process = 1;
if (thread)
data.create_thread = 1;
Expand Down
1 change: 1 addition & 0 deletions src/shm.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ static __always_inline int netdata_update_apps(__u32 idx)
netdata_update_stored_data(fill, idx);
} else {
data.ct = bpf_ktime_get_ns();
data.tgid = tgid;
libnetdata_update_uid_gid(&data.uid, &data.gid);
bpf_get_current_comm(&data.name, TASK_COMM_LEN);

Expand Down
2 changes: 2 additions & 0 deletions src/swap.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ static __always_inline int common_readpage()
libnetdata_update_u64(&fill->read, 1);
} else {
data.ct = bpf_ktime_get_ns();
data.tgid = tgid;
libnetdata_update_uid_gid(&data.uid, &data.gid);
bpf_get_current_comm(&data.name, TASK_COMM_LEN);
data.read = 1;
Expand Down Expand Up @@ -92,6 +93,7 @@ static __always_inline int common_writepage()
libnetdata_update_u64(&fill->write, 1);
} else {
data.ct = bpf_ktime_get_ns();
data.tgid = tgid;
libnetdata_update_uid_gid(&data.uid, &data.gid);
bpf_get_current_comm(&data.name, TASK_COMM_LEN);
data.write = 1;
Expand Down
8 changes: 8 additions & 0 deletions src/vfs.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ static __always_inline int netdata_common_vfs_write(__u64 tot, ssize_t ret)

} else {
netdata_fill_common_vfs_data(&data);
data.tgid = tgid;

if (ret < 0)
data.write_err = 1;
Expand Down Expand Up @@ -130,6 +131,7 @@ static __always_inline int netdata_common_vfs_writev(__u64 tot, ssize_t ret)
}
} else {
netdata_fill_common_vfs_data(&data);
data.tgid = tgid;

if (ret < 0) {
data.writev_err = 1;
Expand Down Expand Up @@ -171,6 +173,7 @@ static __always_inline int netdata_common_vfs_read(__u64 tot, ssize_t ret)
}
} else {
netdata_fill_common_vfs_data(&data);
data.tgid = tgid;

if (ret < 0) {
data.read_err = 1;
Expand Down Expand Up @@ -212,6 +215,7 @@ static __always_inline int netdata_common_vfs_readv(__u64 tot, ssize_t ret)
}
} else {
netdata_fill_common_vfs_data(&data);
data.tgid = tgid;

if (ret < 0) {
data.readv_err = 1;
Expand Down Expand Up @@ -250,6 +254,7 @@ static __always_inline int netdata_common_vfs_unlink(int ret)
}
} else {
netdata_fill_common_vfs_data(&data);
data.tgid = tgid;

if (ret < 0)
data.unlink_err = 1;
Expand Down Expand Up @@ -287,6 +292,7 @@ static __always_inline int netdata_common_vfs_fsync(int ret)
}
} else {
netdata_fill_common_vfs_data(&data);
data.tgid = tgid;

if (ret < 0) {
data.fsync_err = 1;
Expand Down Expand Up @@ -325,6 +331,7 @@ static __always_inline int netdata_common_vfs_open(int ret)
}
} else {
netdata_fill_common_vfs_data(&data);
data.tgid = tgid;

if (ret < 0) {
data.open_err = 1;
Expand Down Expand Up @@ -363,6 +370,7 @@ static __always_inline int netdata_common_vfs_create(int ret)
}
} else {
netdata_fill_common_vfs_data(&data);
data.tgid = tgid;

if (ret < 0) {
data.create_err = 1;
Expand Down

0 comments on commit ad1414e

Please sign in to comment.