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

Detect if profiling is enabled in the first place #28

Open
daxpedda opened this issue Dec 19, 2024 · 1 comment
Open

Detect if profiling is enabled in the first place #28

daxpedda opened this issue Dec 19, 2024 · 1 comment

Comments

@daxpedda
Copy link

daxpedda commented Dec 19, 2024

I noticed that when using capture_coverage() and profiling is not enabled (via -Cinstrument-coverage), the result isn't empty. Is there a way to detect if the binary was instrumented in the first place?

My use case is moving minicov from a cfg to a crate feature in wasm-bindgen-test. But preferably enabling the crate feature, shouldn't cause a bunch of files being written when running the tests when not intending to measure test coverage.

Users would usually enable the cfg in RUSTFLAGS explicitly, but the crate feature is intended to get it closer to regular Rust targets, not requiring any additional flags (apart from -Zno-profiler-runtime) and maybe enabling it by default in the future. But if detection can't happen during runtime, it would still require --feature wasm-bindgen-test/minicov to get it enabled, which defeats the purpose.

@daxpedda
Copy link
Author

Apparently __llvm_profile_get_num_counters() does the trick. Presumably a bunch of other functions could fulfill the same purpose, e.g. __llvm_profile_get_counters_size() or __llvm_profile_get_num_bitmap_bytes().

There are a bunch of ways we could expose this:

  • Check in capture_coverage() beforehand and return an appropriate error.
  • Expose a function called is_enabled().
  • Expose directly, e.g. counters().

I think returning an error sounds like the most appropriate solution. Let me know if this in scope!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant