Skip to content

Exclude setup/teardown from the MemoryManager measurement window (#2149)#2257

Open
devtejasx wants to merge 3 commits into
google:mainfrom
devtejasx:fix-memory-manager-measurement-window
Open

Exclude setup/teardown from the MemoryManager measurement window (#2149)#2257
devtejasx wants to merge 3 commits into
google:mainfrom
devtejasx:fix-memory-manager-measurement-window

Conversation

@devtejasx

Copy link
Copy Markdown
Contributor

Fixes #2149.

Problem

When a MemoryManager is registered, RunMemoryManager called memory_manager->Start() before allocating the internal ThreadManager and running the user's Setup(), and called Stop() after Teardown() and the ThreadManager destruction. As a result the library's own bookkeeping allocation and any per-benchmark fixture / Setup() / Teardown() allocations were attributed to the benchmark's reported memory usage, inflating num_allocs etc. for allocations that are not part of the measured work.

Fix

Move memory_manager->Start() to just before RunInThread (after the ThreadManager is constructed and Setup() has run) and Stop() to just after RunInThread (before Teardown() and manager teardown), so the measurement window covers only the benchmark iterations — matching how the timed window already excludes setup/teardown.

Test

test/memory_manager_ordering_gtest.cc registers a MemoryManager and a benchmark whose Setup/Teardown allocate, and asserts that those allocations fall outside the measured window.

(This supersedes #2247, which I closed to convert its ad-hoc test into a gtest.)

…2149)

RunMemoryManager called memory_manager->Start() before allocating the
internal ThreadManager and running the benchmark's Setup(), and called
Stop() after resetting the ThreadManager and running Teardown(). As a
result the MemoryManager attributed the library's own bookkeeping
allocation and any per-benchmark fixture allocations to the benchmark,
so the reported allocation count could never be accurate.

Setup()/Teardown() already run outside the timed region; make memory
measurement consistent by bracketing only RunInThread with Start()/
Stop(), and move the ThreadManager creation and Setup()/Teardown()
outside that window.

Add memory_manager_ordering_test, which registers a MemoryManager and
asserts no Setup/Teardown occurs between Start() and Stop(). It fails
on the previous ordering and passes with this change.

Signed-off-by: devtejasx <tejasnagmote520@gmail.com>
Address review feedback on google#2247: replace the assert-based
memory_manager_ordering_test with a gtest that tracks the
Start/Stop measurement window and the fixture callbacks with
booleans and checks the invariant inside the callbacks, instead
of collecting a string log of lifecycle events.
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.

[BUG] Memory manager counts allocations not part of benchmark

1 participant