perf_test_suite.h revision 3345a6884c488ff3a535c2c9acdd33d74b37e311
1// Copyright (c) 2009 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef BASE_TEST_PERF_TEST_SUITE_H_ 6#define BASE_TEST_PERF_TEST_SUITE_H_ 7#pragma once 8 9#include "base/command_line.h" 10#include "base/debug_util.h" 11#include "base/file_path.h" 12#include "base/path_service.h" 13#include "base/perftimer.h" 14#include "base/process_util.h" 15#include "base/string_util.h" 16#include "base/test/test_suite.h" 17#include "testing/gtest/include/gtest/gtest.h" 18 19class PerfTestSuite : public TestSuite { 20 public: 21 PerfTestSuite(int argc, char** argv) : TestSuite(argc, argv) { 22 } 23 24 virtual void Initialize() { 25 TestSuite::Initialize(); 26 27 // Initialize the perf timer log 28 FilePath log_path = 29 CommandLine::ForCurrentProcess()->GetSwitchValuePath("log-file"); 30 if (log_path.empty()) { 31 FilePath exe; 32 PathService::Get(base::FILE_EXE, &exe); 33 log_path = exe.ReplaceExtension(FILE_PATH_LITERAL("log")); 34 log_path = log_path.InsertBeforeExtension(FILE_PATH_LITERAL("_perf")); 35 } 36 ASSERT_TRUE(InitPerfLog(log_path)); 37 38 // Raise to high priority to have more precise measurements. Since we don't 39 // aim at 1% precision, it is not necessary to run at realtime level. 40 if (!DebugUtil::BeingDebugged()) 41 base::RaiseProcessToHighPriority(); 42 } 43 44 virtual void Shutdown() { 45 TestSuite::Shutdown(); 46 47 FinalizePerfLog(); 48 } 49}; 50 51#endif // BASE_TEST_PERF_TEST_SUITE_H_ 52