golang, ebpf and functions duration

梦想的初衷 提交于 2019-12-06 11:54:26

This looks like it is caused by a mismatch of paddings between kernel and user sides. The data_t structure is actually padded at compile-time to be equivalent to the following:

struct data_t {
   u32 pid;
   char padding[4];
   char comm[TASK_COMM_LEN];
   u64 delta;    
};

If you explicitely add that same padding on the Go side, your problem will go away:

type amebaEvent struct {
    Pid uint32
    Pad [4]byte
    Comm [16]byte
    Delta uint64
}

Produces:

PID COMMAND DURATION    RAW
8258    a   1.000179625s    1000179625
8260    a   1.000158337s    1000158337

As you've mentioned in comments, another solution would be to pack the C structure to remove padding, with __attribute__((packed)).


It is closely related---although not identical---to this issue on bcc: https://github.com/iovisor/bcc/issues/2017.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!