Complete struct field assignment

This commit is contained in:
Pragyansh Chaturvedi
2025-09-21 05:22:00 +05:30
parent 36c2c0b695
commit 0f9a4078ee
3 changed files with 72 additions and 11 deletions

View File

@ -9,7 +9,7 @@
struct data_t {
__u32 pid;
__u64 ts;
char comm[TASK_COMM_LEN];
// char comm[TASK_COMM_LEN];
};
// Define a perf event output map
@ -31,7 +31,7 @@ int hello(struct pt_regs *ctx)
data.ts = bpf_ktime_get_ns();
// Get current process name
bpf_get_current_comm(&data.comm, sizeof(data.comm));
// bpf_get_current_comm(&data.comm, sizeof(data.comm));
// Submit data to userspace via perf event
bpf_perf_event_output(ctx, &events, BPF_F_CURRENT_CPU,

View File

@ -11,17 +11,21 @@ class data_t:
pid: c_uint64
ts: c_uint64
@bpf
@map
def events() -> PerfEventArray:
return PerfEventArray(key_size=c_int32, value_size=c_int32)
@bpf
@section("tracepoint/syscalls/sys_enter_clone")
def hello(ctx: c_void_p) -> c_int32:
dataobj = data_t()
ts = ktime()
process_id = pid()
dataobj.pid = process_id
dataobj.ts = ts
print(f"clone called at {ts} by pid {process_id}")
return c_int32(0)