Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dlfilter filtering out trace errors #265

Merged
merged 2 commits into from
Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions core/env_vars.ml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ let debug = Option.is_some (Unix.getenv "MAGIC_TRACE_DEBUG")
features of magic-trace. *)
let experimental = Option.is_some (Unix.getenv "MAGIC_TRACE_EXPERIMENTAL")

(* magic-trace's dlfilter integration is busted right now, see #246. Also:

When tracing the kernel on certain systems, perf only has root access when
(* When tracing the kernel on certain systems, perf only has root access when
being run with a specific set of flags. Since this does not include
[--dlfilter], this environment variable allows the user to forcibly disable
filtering. *)
let no_dlfilter = Option.is_none (Unix.getenv "MAGIC_TRACE_ENABLE_DLFILTER")
let no_dlfilter = Option.is_some (Unix.getenv "MAGIC_TRACE_NO_DLFILTER")
8 changes: 6 additions & 2 deletions src/perf_dlfilter.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ int filter_event_early(void *data, const struct perf_dlfilter_sample *sample,
perf_dlfilter_fns.resolve_ip(ctx);
const struct perf_dlfilter_al *resolved_addr =
perf_dlfilter_fns.resolve_addr(ctx);
if (!resolved_ip || !resolved_ip->sym || !resolved_addr ||
!resolved_addr->sym ||

// Only filter out events we for sure don't want. It's better to be less aggressive than
// too aggressive, as being too aggressive will lead to broken traces, while being not
// aggressive enough just makes things slower.
if (resolved_ip && resolved_ip->sym && resolved_addr && resolved_addr->sym &&
strcmp(resolved_ip->sym, resolved_addr->sym) == 0) {
return 1;
}

return 0;
}