Exclude setup/teardown from the MemoryManager measurement window (#2149)#2257
Open
devtejasx wants to merge 3 commits into
Open
Exclude setup/teardown from the MemoryManager measurement window (#2149)#2257devtejasx wants to merge 3 commits into
devtejasx wants to merge 3 commits into
Conversation
…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.
…measurement-window
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2149.
Problem
When a
MemoryManageris registered,RunMemoryManagercalledmemory_manager->Start()before allocating the internalThreadManagerand running the user'sSetup(), and calledStop()afterTeardown()and theThreadManagerdestruction. 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, inflatingnum_allocsetc. for allocations that are not part of the measured work.Fix
Move
memory_manager->Start()to just beforeRunInThread(after theThreadManageris constructed andSetup()has run) andStop()to just afterRunInThread(beforeTeardown()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.ccregisters aMemoryManagerand a benchmark whoseSetup/Teardownallocate, 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.)