/* fetch IPs and counts */
key = 0, i = 0; while (bpf_map_get_next_key(fd, &key, &next_key) == 0) {
bpf_map_lookup_elem(fd, &next_key, &value);
counts[i].ip = next_key;
counts[i++].count = value;
key = next_key;
}
max = i;
/* sort and print */
qsort(counts, max, sizeof(struct ipcount), count_cmp); for (i = 0; i < max; i++) { if (counts[i].ip > _text_addr) {
sym = ksym_search(counts[i].ip); if (!sym) {
printf("ksym not found. Is kallsyms loaded?\n"); continue;
}
/* initialize kernel symbol translation */ if (load_kallsyms()) {
fprintf(stderr, "ERROR: loading /proc/kallsyms\n"); return 2;
}
/* used to determine whether the address is kernel space */
_text_addr = ksym_get_addr("_text"); if (!_text_addr) {
fprintf(stderr, "ERROR: no '_text' in /proc/kallsyms\n"); return 3;
}
/* create perf FDs for each CPU */
nr_cpus = sysconf(_SC_NPROCESSORS_ONLN);
links = calloc(nr_cpus, sizeof(struct bpf_link *)); if (!links) {
fprintf(stderr, "ERROR: malloc of links\n"); goto cleanup;
}
/* do sampling */
printf("Sampling at %d Hertz for %d seconds. Ctrl-C also ends.\n",
freq, secs); if (sampling_start(freq, prog, links) != 0) goto cleanup;
sleep(secs);
error = 0;
cleanup:
sampling_end(links); /* output sample counts */ if (!error)
print_ip_map(map_fd);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.