Framework: Telemetry retake
[csit.git] / resources / templates / telemetry / bpf_runtime.yaml
1 ---
2 logging:
3   version: 1
4   formatters:
5     console:
6       format: '%(asctime)s - %(name)s - %(message)s'
7     prom:
8       format: '%(message)s'
9   handlers:
10     console:
11       class: logging.StreamHandler
12       level: INFO
13       formatter: console
14       stream: ext://sys.stdout
15     prom:
16       class: logging.handlers.RotatingFileHandler
17       level: INFO
18       formatter: prom
19       filename: /tmp/metric.prom
20       mode: w
21   loggers:
22     prom:
23       handlers: [prom]
24       level: INFO
25       propagate: False
26   root:
27     level: INFO
28     handlers: [console]
29 scheduler:
30   duration: 1
31 programs:
32   - name: bundle_bpf
33     metrics:
34       counter:
35         - name: cpu_cycle
36           documentation: Cycles processed by CPUs
37           namespace: bpf
38           labelnames:
39             - name
40             - cpu
41             - pid
42         - name: cpu_instruction
43           documentation: Instructions retired by CPUs
44           namespace: bpf
45           labelnames:
46             - name
47             - cpu
48             - pid
49         - name: llc_reference
50           documentation: Last level cache operations by type
51           namespace: bpf
52           labelnames:
53             - name
54             - cpu
55             - pid
56         - name: llc_miss
57           documentation: Last level cache operations by type
58           namespace: bpf
59           labelnames:
60             - name
61             - cpu
62             - pid
63     events:
64       - type: 0x0 # HARDWARE
65         name: 0x0 # PERF_COUNT_HW_CPU_CYCLES
66         target: on_cpu_cycle
67         table: cpu_cycle
68       - type: 0x0 # HARDWARE
69         name: 0x1 # PERF_COUNT_HW_INSTRUCTIONS
70         target: on_cpu_instruction
71         table: cpu_instruction
72       - type: 0x0 # HARDWARE
73         name: 0x2 # PERF_COUNT_HW_CACHE_REFERENCES
74         target: on_cache_reference
75         table: llc_reference
76       - type: 0x0 # HARDWARE
77         name: 0x3 # PERF_COUNT_HW_CACHE_MISSES
78         target: on_cache_miss
79         table: llc_miss
80     code: |
81       #include <linux/ptrace.h>
82       #include <uapi/linux/bpf_perf_event.h>
83
84       const int max_cpus = 256;
85
86       struct key_t {
87           int cpu;
88           int pid;
89           char name[TASK_COMM_LEN];
90       };
91
92       BPF_HASH(llc_miss, struct key_t);
93       BPF_HASH(llc_reference, struct key_t);
94       BPF_HASH(cpu_instruction, struct key_t);
95       BPF_HASH(cpu_cycle, struct key_t);
96
97       static inline __attribute__((always_inline)) void get_key(struct key_t* key) {
98           key->cpu = bpf_get_smp_processor_id();
99           key->pid = bpf_get_current_pid_tgid();
100           bpf_get_current_comm(&(key->name), sizeof(key->name));
101       }
102
103       int on_cpu_cycle(struct bpf_perf_event_data *ctx) {
104           struct key_t key = {};
105           get_key(&key);
106
107           cpu_cycle.increment(key, ctx->sample_period);
108           return 0;
109       }
110       int on_cpu_instruction(struct bpf_perf_event_data *ctx) {
111           struct key_t key = {};
112           get_key(&key);
113
114           cpu_instruction.increment(key, ctx->sample_period);
115           return 0;
116       }
117       int on_cache_reference(struct bpf_perf_event_data *ctx) {
118           struct key_t key = {};
119           get_key(&key);
120
121           llc_reference.increment(key, ctx->sample_period);
122           return 0;
123       }
124       int on_cache_miss(struct bpf_perf_event_data *ctx) {
125           struct key_t key = {};
126           get_key(&key);
127
128           llc_miss.increment(key, ctx->sample_period);
129           return 0;
130       }