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

perf_counters: Initialize once only when needed #1656

Merged
merged 3 commits into from
Aug 24, 2023

Conversation

jmr
Copy link
Member

@jmr jmr commented Aug 24, 2023

This works around some performance problems running Android under QEMU. Calling pfm_initialize was very slow, and was called during dynamic initialization (before main or when loaded as a shared library). This happened whenever benchmark was linked, even if no benchmarks were run.

Instead, call pfm_initialize at most once, and only when one of:

  1. PerfCounters::Initialize is called
  2. PerfCounters::Create is called with a non-empty counter list
  3. PerfCounters::IsCounterSupported is called

The return value of the first pfm_initialize() is saved and returned from all subsequent PerfCounters::Initialize calls.

This works around some performance problems running Android under QEMU.
Calling `pfm_initialize` was very slow, and was called during dynamic
initialization (before `main` or when loaded as a shared library).
This happened whenever benchmark was linked, even if no benchmarks
were run.

Instead, call `pfm_initialize` at most once, and only when one of:
1. `PerfCounters::Initialize` is called
2. `PerfCounters::Create` is called with a non-empty counter list
3. `PerfCounters::IsCounterSupported` is called

The return value of the first `pfm_initialize()` is saved and
returned from all subsequent `PerfCounters::Initialize` calls.
@jmr
Copy link
Member Author

jmr commented Aug 24, 2023

@mtrofin

src/perf_counters.cc Outdated Show resolved Hide resolved
@dmah42 dmah42 merged commit 9c65aeb into google:main Aug 24, 2023
53 of 60 checks passed
@dmah42
Copy link
Member

dmah42 commented Aug 24, 2023

thanks!

@jmr jmr deleted the perf-counter-init branch August 24, 2023 09:05
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

Successfully merging this pull request may close these issues.

2 participants