Skip to content

Commit

Permalink
libbpf-tools: update filelife for libbpf 1.0
Browse files Browse the repository at this point in the history
Switch to libbpf 1.0 mode and adapt libbpf API usage accordingly.

Signed-off-by: Andrii Nakryiko <[email protected]>
  • Loading branch information
anakryiko committed Dec 20, 2021
1 parent 0a035be commit 4ca8dd9
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions libbpf-tools/filelife.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ int main(int argc, char **argv)
.parser = parse_arg,
.doc = argp_program_doc,
};
struct perf_buffer_opts pb_opts;
struct perf_buffer *pb = NULL;
struct filelife_bpf *obj;
int err;
Expand All @@ -120,14 +119,9 @@ int main(int argc, char **argv)
if (err)
return err;

libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
libbpf_set_print(libbpf_print_fn);

err = bump_memlock_rlimit();
if (err) {
fprintf(stderr, "failed to increase rlimit: %d\n", err);
return 1;
}

obj = filelife_bpf__open();
if (!obj) {
fprintf(stderr, "failed to open BPF object\n");
Expand All @@ -152,13 +146,10 @@ int main(int argc, char **argv)
printf("Tracing the lifespan of short-lived files ... Hit Ctrl-C to end.\n");
printf("%-8s %-6s %-16s %-7s %s\n", "TIME", "PID", "COMM", "AGE(s)", "FILE");

pb_opts.sample_cb = handle_event;
pb_opts.lost_cb = handle_lost_events;
pb = perf_buffer__new(bpf_map__fd(obj->maps.events), PERF_BUFFER_PAGES,
&pb_opts);
err = libbpf_get_error(pb);
if (err) {
pb = NULL;
handle_event, handle_lost_events, NULL, NULL);
if (!pb) {
err = -errno;
fprintf(stderr, "failed to open perf buffer: %d\n", err);
goto cleanup;
}
Expand All @@ -171,8 +162,8 @@ int main(int argc, char **argv)

while (!exiting) {
err = perf_buffer__poll(pb, PERF_POLL_TIMEOUT_MS);
if (err < 0 && errno != EINTR) {
fprintf(stderr, "error polling perf buffer: %s\n", strerror(errno));
if (err < 0 && err != -EINTR) {
fprintf(stderr, "error polling perf buffer: %s\n", strerror(-err));
goto cleanup;
}
/* reset err to return 0 if exiting */
Expand Down

0 comments on commit 4ca8dd9

Please sign in to comment.