1 /* Copyright (c) 2013-2015 PLUMgrid, http://plumgrid.com
2 * Copyright (c) 2015 BMW Car IT GmbH
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of version 2 of the GNU General Public
6 * License as published by the Free Software Foundation.
12 #include <linux/bpf.h>
16 #define MAX_ENTRIES 20
21 long data[MAX_ENTRIES];
25 static struct cpu_hist cpu_hist[MAX_CPU];
27 static void stars(char *str, long val, long max, int width)
31 for (i = 0; i < (width * val / max) - 1 && i < width - 1; i++)
38 static void print_hist(void)
40 char starstr[MAX_STARS];
41 struct cpu_hist *hist;
47 for (j = 0; j < MAX_CPU; j++) {
50 /* ignore CPUs without data (maybe offline?) */
54 printf("CPU %d\n", j);
55 printf(" latency : count distribution\n");
56 for (i = 1; i <= MAX_ENTRIES; i++) {
57 stars(starstr, hist->data[i - 1], hist->max, MAX_STARS);
58 printf("%8ld -> %-8ld : %-8ld |%-*s|\n",
59 (1l << i) >> 1, (1l << i) - 1,
60 hist->data[i - 1], MAX_STARS, starstr);
65 static void get_data(int fd)
70 for (i = 0; i < MAX_CPU; i++)
73 for (c = 0; c < MAX_CPU; c++) {
74 for (i = 0; i < MAX_ENTRIES; i++) {
75 key = c * MAX_ENTRIES + i;
76 bpf_lookup_elem(fd, &key, &value);
78 cpu_hist[c].data[i] = value;
79 if (value > cpu_hist[c].max)
80 cpu_hist[c].max = value;
85 int main(int argc, char **argv)
89 snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
91 if (load_bpf_file(filename)) {
92 printf("%s", bpf_log_buf);