blob: 5963583ea48c03e14377557b17a148baadf446e4 [file] [log] [blame]
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_TRACING_TEST_PERF_TEST_HELPERS_H_
#define COMPONENTS_TRACING_TEST_PERF_TEST_HELPERS_H_
#include <stdint.h>
#include <vector>
#include "base/macros.h"
#include "base/time/time.h"
namespace tracing {
// Measure time spent in a scope.
// Must be used inside GTest case and result will be printed in perf_test format
// with value name passed to constructor.
class ScopedStopwatch {
public:
ScopedStopwatch(const std::string& name);
~ScopedStopwatch();
private:
base::TimeTicks begin_;
const std::string name_;
DISALLOW_COPY_AND_ASSIGN(ScopedStopwatch);
};
// Measure median time of loop iterations.
// Example:
// IterableStopwatch stopwatch("foo");
// for (int i = 0; i < 100; i++) {
// ...
// stopwatch.NextLap();
// }
// Must be used inside GTest case and result will be printed in perf_test format
// with value name passed to constructor.
class IterableStopwatch {
public:
IterableStopwatch(const std::string& name);
~IterableStopwatch();
void NextLap();
private:
base::TimeTicks begin_;
std::vector<int64_t> laps_;
const std::string name_;
DISALLOW_COPY_AND_ASSIGN(IterableStopwatch);
};
} // namespace tracing
#endif // COMPONENTS_TRACING_TEST_PERF_TEST_HELPERS_H_