1 // SPDX-License-Identifier: GPL-2.0-only
2 /* Copyright (c) 2013-2015 PLUMgrid, http://plumgrid.com
3 * Copyright (c) 2015 BMW Car IT GmbH
13 #define MAX_ENTRIES 20
18 long data[MAX_ENTRIES];
22 static struct cpu_hist cpu_hist[MAX_CPU];
24 static void stars(char *str, long val, long max, int width)
28 for (i = 0; i < (width * val / max) - 1 && i < width - 1; i++)
35 static void print_hist(void)
37 char starstr[MAX_STARS];
38 struct cpu_hist *hist;
44 for (j = 0; j < MAX_CPU; j++) {
47 /* ignore CPUs without data (maybe offline?) */
51 printf("CPU %d\n", j);
52 printf(" latency : count distribution\n");
53 for (i = 1; i <= MAX_ENTRIES; i++) {
54 stars(starstr, hist->data[i - 1], hist->max, MAX_STARS);
55 printf("%8ld -> %-8ld : %-8ld |%-*s|\n",
56 (1l << i) >> 1, (1l << i) - 1,
57 hist->data[i - 1], MAX_STARS, starstr);
62 static void get_data(int fd)
67 for (i = 0; i < MAX_CPU; i++)
70 for (c = 0; c < MAX_CPU; c++) {
71 for (i = 0; i < MAX_ENTRIES; i++) {
72 key = c * MAX_ENTRIES + i;
73 bpf_map_lookup_elem(fd, &key, &value);
75 cpu_hist[c].data[i] = value;
76 if (value > cpu_hist[c].max)
77 cpu_hist[c].max = value;
82 int main(int argc, char **argv)
86 snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
88 if (load_bpf_file(filename)) {
89 printf("%s", bpf_log_buf);