google / benchmark

A microbenchmark support library
Apache License 2.0
8.61k stars 1.57k forks source link

perf_counters: Initialize once only when needed #1656

Closed jmr closed 10 months ago

jmr commented 10 months ago

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 commented 10 months ago

@mtrofin

dmah42 commented 10 months ago

thanks!