Skip to content

Commit 0b44421

Browse files
committed
change is_valid to memory_iterations
1 parent 05774b2 commit 0b44421

File tree

4 files changed

+7
-8
lines changed

4 files changed

+7
-8
lines changed

include/benchmark/benchmark.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,8 @@ namespace benchmark {
306306
class BenchmarkReporter;
307307
class State;
308308

309+
typedef int64_t IterationCount;
310+
309311
// Define alias of Setup/Teardown callback function type
310312
using callback_function = std::function<void(const benchmark::State&)>;
311313

@@ -395,7 +397,7 @@ class MemoryManager {
395397
max_bytes_used(0),
396398
total_allocated_bytes(TombstoneValue),
397399
net_heap_growth(TombstoneValue),
398-
is_valid(false) {}
400+
memory_iterations(0) {}
399401

400402
// The number of allocations made in total between Start and Stop.
401403
int64_t num_allocs;
@@ -412,7 +414,7 @@ class MemoryManager {
412414
// Init'ed to TombstoneValue if metric not available.
413415
int64_t net_heap_growth;
414416

415-
bool is_valid;
417+
IterationCount memory_iterations;
416418
};
417419

418420
virtual ~MemoryManager() {}
@@ -662,8 +664,6 @@ enum BigO { oNone, o1, oN, oNSquared, oNCubed, oLogN, oNLogN, oAuto, oLambda };
662664

663665
typedef int64_t ComplexityN;
664666

665-
typedef int64_t IterationCount;
666-
667667
enum StatisticUnit { kTime, kPercentage };
668668

669669
// BigOFunc is passed to a benchmark in order to specify the asymptotic

src/benchmark_runner.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ BenchmarkReporter::Run CreateRunReport(
114114
report.counters = results.counters;
115115

116116
if (memory_iterations > 0) {
117-
assert(memory_result.is_valid);
118117
report.memory_result = memory_result;
119118
report.allocs_per_iter =
120119
memory_iterations != 0
@@ -440,6 +439,7 @@ MemoryManager::Result BenchmarkRunner::RunMemoryManager(
440439
b.Teardown();
441440
MemoryManager::Result memory_result;
442441
memory_manager->Stop(memory_result);
442+
memory_result.memory_iterations = memory_iterations;
443443
return memory_result;
444444
}
445445

@@ -511,7 +511,6 @@ void BenchmarkRunner::DoOneRepetition() {
511511
// allocations in benchmarks that are not properly managed.
512512
memory_iterations = std::min<IterationCount>(16, iters);
513513
memory_result = RunMemoryManager(memory_iterations);
514-
memory_result.is_valid = true;
515514
}
516515

517516
if (profiler_manager != nullptr) {

src/json_reporter.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ void JSONReporter::PrintRunData(Run const& run) {
306306
out << ",\n" << indent << FormatKV(c.first, c.second);
307307
}
308308

309-
if (run.memory_result.is_valid) {
309+
if (run.memory_result.memory_iterations > 0) {
310310
const MemoryManager::Result& memory_result{run.memory_result};
311311
out << ",\n" << indent << FormatKV("allocs_per_iter", run.allocs_per_iter);
312312
out << ",\n"

test/memory_results_gtest.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class TestReporter : public ConsoleReporter {
5353
void PrintHeader(const Run&) override {}
5454
void PrintRunData(const Run& run) override {
5555
if (run.repetition_index == -1) return;
56-
if (!run.memory_result.is_valid) return;
56+
if (!run.memory_result.memory_iterations) return;
5757

5858
store.push_back(run.memory_result);
5959
}

0 commit comments

Comments
 (0)