Created
October 21, 2020 13:24
-
-
Save tqbf/b65d08d68f67d2fa976319f6512893a5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// /sys/fs/bpf/tc/globals/perf_map | |
// records traces from BPF, using the snapshot_* functions, read by userland tcpdump-style; | |
// note this is implicitly per-CPU (the "size" of the perf map is the max number of CPUs) | |
DECLARE_GLOBAL_MAP(perf_map, BPF_MAP_TYPE_PERF_EVENT_ARRAY, sizeof(int), sizeof(u_int32_t), 8); | |
kfn void | |
_snapshot(int type, void *ctx, u_char *sp, void *ep, u_int16_t len) { | |
u_int64_t flags = BPF_F_CURRENT_CPU; | |
struct perf_meta_packet meta = | |
{ | |
.magic = PP_MAGIC, | |
.type = type, | |
.flags = 0, | |
.len = (u_int16_t)((u_char *)ep - sp), | |
}; | |
if(len == 0) { | |
len = meta.len; | |
} | |
if(len > meta.len) { | |
len = meta.len; | |
} | |
flags |= (u_int64_t)len << 32; | |
perf_event_output(ctx, &perf_map, flags, &meta, sizeof(meta)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello. In the blog entry (on fly.io) that pointed me to this gist, you wrote:
Just curious if you still had something like that dockerfile handy, or could point me to something similar? I'm someone who did a fair amount of Linux networking work in the late 90s and early 2000s, and am now trying to catch up on what I missed, too.