-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix memory manager result bug #1941
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
05774b2
fix memory manager result bug
EfesX 0b44421
change is_valid to memory_iterations
EfesX ffca034
fix test
EfesX 91815d8
some fixes
EfesX fbf959d
fix test
EfesX 208509a
fix test
EfesX eaabe46
fix test
EfesX e1eaa52
fix msvc failure
EfesX d43e705
some fixes
EfesX 46bd46c
remove unnecessary include
EfesX 62d46c8
Merge branch 'main' into issue_1939
EfesX File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| #include <vector> | ||
|
|
||
LebedevRI marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #include "benchmark/benchmark.h" | ||
| #include "gtest/gtest.h" | ||
|
|
||
| namespace { | ||
|
|
||
| using benchmark::ClearRegisteredBenchmarks; | ||
| using benchmark::ConsoleReporter; | ||
| using benchmark::MemoryManager; | ||
| using benchmark::RegisterBenchmark; | ||
| using benchmark::RunSpecifiedBenchmarks; | ||
| using benchmark::State; | ||
| using benchmark::internal::Benchmark; | ||
|
|
||
| constexpr int N_REPETITIONS = 100; | ||
| constexpr int N_ITERATIONS = 1; | ||
|
|
||
| int num_allocs = 0; | ||
| int max_bytes_used = 0; | ||
| int total_allocated_bytes = 0; | ||
| int net_heap_growth = 0; | ||
|
|
||
| void reset() { | ||
| num_allocs = 0; | ||
| max_bytes_used = 0; | ||
| total_allocated_bytes = 0; | ||
| net_heap_growth = 0; | ||
| } | ||
| class TestMemoryManager : public MemoryManager { | ||
| void Start() override {} | ||
| void Stop(Result& result) override { | ||
| result.num_allocs = num_allocs; | ||
| result.net_heap_growth = net_heap_growth; | ||
| result.max_bytes_used = max_bytes_used; | ||
| result.total_allocated_bytes = total_allocated_bytes; | ||
|
|
||
| num_allocs += 1; | ||
| max_bytes_used += 2; | ||
| net_heap_growth += 4; | ||
| total_allocated_bytes += 10; | ||
| } | ||
| }; | ||
|
|
||
| class TestReporter : public ConsoleReporter { | ||
| public: | ||
| TestReporter() = default; | ||
| virtual ~TestReporter() = default; | ||
|
|
||
| bool ReportContext(const Context& /*unused*/) override { return true; } | ||
|
|
||
| void PrintHeader(const Run&) override {} | ||
| void PrintRunData(const Run& run) override { | ||
| if (run.repetition_index == -1) return; | ||
| if (!run.memory_result.memory_iterations) return; | ||
|
|
||
| store.push_back(run.memory_result); | ||
| } | ||
|
|
||
| std::vector<MemoryManager::Result> store; | ||
| }; | ||
|
|
||
| class MemoryResultsTest : public testing::Test { | ||
| public: | ||
| Benchmark* bm; | ||
| TestReporter reporter; | ||
|
|
||
| void SetUp() override { | ||
| bm = RegisterBenchmark("BM", [](State& st) { | ||
| for (auto _ : st) { | ||
| } | ||
| }); | ||
| bm->Repetitions(N_REPETITIONS); | ||
| bm->Iterations(N_ITERATIONS); | ||
| reset(); | ||
| } | ||
| void TearDown() override { ClearRegisteredBenchmarks(); } | ||
| }; | ||
|
|
||
| TEST_F(MemoryResultsTest, NoMMTest) { | ||
| RunSpecifiedBenchmarks(&reporter); | ||
| EXPECT_EQ(reporter.store.size(), 0); | ||
| } | ||
|
|
||
| TEST_F(MemoryResultsTest, ResultsTest) { | ||
| auto mm = std::make_unique<TestMemoryManager>(); | ||
| RegisterMemoryManager(mm.get()); | ||
|
|
||
| RunSpecifiedBenchmarks(&reporter); | ||
| EXPECT_EQ(reporter.store.size(), N_REPETITIONS); | ||
|
|
||
| for (size_t i = 0; i < reporter.store.size(); i++) { | ||
| EXPECT_EQ(reporter.store[i].num_allocs, static_cast<int64_t>(i)); | ||
| EXPECT_EQ(reporter.store[i].max_bytes_used, static_cast<int64_t>(i) * 2); | ||
| EXPECT_EQ(reporter.store[i].net_heap_growth, static_cast<int64_t>(i) * 4); | ||
| EXPECT_EQ(reporter.store[i].total_allocated_bytes, | ||
| static_cast<int64_t>(i) * 10); | ||
| } | ||
| } | ||
|
|
||
| } // namespace | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.