blob: be479c4af9e2243224d271b01853b240074777e7 [file] [log] [blame]
Kaixu Xia5ed3ccb2015-08-12 09:37:53 +00001#include <linux/ptrace.h>
Kaixu Xia47efb302015-08-06 07:02:36 +00002#include <linux/version.h>
3#include <uapi/linux/bpf.h>
4#include "bpf_helpers.h"
5
6struct bpf_map_def SEC("maps") my_map = {
7 .type = BPF_MAP_TYPE_PERF_EVENT_ARRAY,
8 .key_size = sizeof(int),
9 .value_size = sizeof(u32),
10 .max_entries = 32,
11};
12
13SEC("kprobe/sys_write")
14int bpf_prog1(struct pt_regs *ctx)
15{
16 u64 count;
17 u32 key = bpf_get_smp_processor_id();
18 char fmt[] = "CPU-%d %llu\n";
19
20 count = bpf_perf_event_read(&my_map, key);
21 bpf_trace_printk(fmt, sizeof(fmt), key, count);
22
23 return 0;
24}
25
26char _license[] SEC("license") = "GPL";
27u32 _version SEC("version") = LINUX_VERSION_CODE;