Framework: Telemetry retake
[csit.git] / resources / templates / telemetry / bpf_runtime.yaml
diff --git a/resources/templates/telemetry/bpf_runtime.yaml b/resources/templates/telemetry/bpf_runtime.yaml
new file mode 100644 (file)
index 0000000..88ad7eb
--- /dev/null
@@ -0,0 +1,130 @@
+---
+logging:
+  version: 1
+  formatters:
+    console:
+      format: '%(asctime)s - %(name)s - %(message)s'
+    prom:
+      format: '%(message)s'
+  handlers:
+    console:
+      class: logging.StreamHandler
+      level: INFO
+      formatter: console
+      stream: ext://sys.stdout
+    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]
+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;
+      }