6 format: '%(asctime)s - %(name)s - %(message)s'
11 class: logging.StreamHandler
14 stream: ext://sys.stdout
16 class: logging.handlers.RotatingFileHandler
19 filename: /tmp/metric.prom
36 documentation: Cycles processed by CPUs
42 - name: cpu_instruction
43 documentation: Instructions retired by CPUs
50 documentation: Last level cache operations by type
57 documentation: Last level cache operations by type
64 - type: 0x0 # HARDWARE
65 name: 0x0 # PERF_COUNT_HW_CPU_CYCLES
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
76 - type: 0x0 # HARDWARE
77 name: 0x3 # PERF_COUNT_HW_CACHE_MISSES
81 #include <linux/ptrace.h>
82 #include <uapi/linux/bpf_perf_event.h>
84 const int max_cpus = 256;
89 char name[TASK_COMM_LEN];
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);
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));
103 int on_cpu_cycle(struct bpf_perf_event_data *ctx) {
104 struct key_t key = {};
107 cpu_cycle.increment(key, ctx->sample_period);
110 int on_cpu_instruction(struct bpf_perf_event_data *ctx) {
111 struct key_t key = {};
114 cpu_instruction.increment(key, ctx->sample_period);
117 int on_cache_reference(struct bpf_perf_event_data *ctx) {
118 struct key_t key = {};
121 llc_reference.increment(key, ctx->sample_period);
124 int on_cache_miss(struct bpf_perf_event_data *ctx) {
125 struct key_t key = {};
128 llc_miss.increment(key, ctx->sample_period);