Skip to content

Commit

Permalink
support output cpu
Browse files Browse the repository at this point in the history
Signed-off-by: Leon Huayra <hffilwlqm@gmail.com>
  • Loading branch information
Asphaltt authored and brb committed Dec 2, 2021
1 parent 35f8017 commit 015a734
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
2 changes: 2 additions & 0 deletions bpf/kprobe_pwru.c
Expand Up @@ -59,6 +59,7 @@ struct event_t {
u64 addr;
u64 skb_addr;
u64 ts;
u32 cpu;
typeof(print_skb_id) print_skb_id;
struct skb_meta meta;
struct tuple tuple;
Expand Down Expand Up @@ -383,6 +384,7 @@ handle_everything(struct sk_buff *skb, struct pt_regs *ctx) {
event.addr = PT_REGS_IP(ctx);
event.skb_addr = (u64) skb;
event.ts = bpf_ktime_get_ns();
event.cpu = bpf_get_smp_processor_id();
bpf_perf_event_output(ctx, &events, BPF_F_CURRENT_CPU, &event, sizeof(event));

return 0;
Expand Down
4 changes: 2 additions & 2 deletions internal/pwru/output.go
Expand Up @@ -33,7 +33,7 @@ func NewOutput(flags *Flags, printSkbMap *ebpf.Map, printStackMap *ebpf.Map, add
}

func (o *output) PrintHeader() {
fmt.Printf("%18s %16s %24s %16s\n", "SKB", "PROCESS", "FUNC", "TIMESTAMP")
fmt.Printf("%18s %16s %24s %8s %16s\n", "SKB", "PROCESS", "FUNC", "CPU", "TIMESTAMP")
}

func (o *output) Print(event *Event) {
Expand All @@ -50,7 +50,7 @@ func (o *output) Print(event *Event) {
ts = 0
}
}
fmt.Printf("%18s %16s %24s %16d", fmt.Sprintf("0x%x", event.SAddr), fmt.Sprintf("[%s]", execName), o.addr2name.Addr2NameMap[event.Addr-1].name, ts)
fmt.Printf("%18s %16s %24s %8d %16d", fmt.Sprintf("0x%x", event.SAddr), fmt.Sprintf("[%s]", execName), o.addr2name.Addr2NameMap[event.Addr-1].name, event.CPU, ts)
o.lastSeenSkb[event.SAddr] = event.Timestamp

if o.flags.OutputMeta {
Expand Down
1 change: 1 addition & 0 deletions internal/pwru/types.go
Expand Up @@ -77,6 +77,7 @@ type Event struct {
Addr uint64
SAddr uint64
Timestamp uint64
CPU uint32
PrintSkbId uint64
Meta Meta
Tuple Tuple
Expand Down

0 comments on commit 015a734

Please sign in to comment.