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