xref: /aosp_15_r20/external/libchrome/base/test/perf_test_suite.cc (revision 635a864187cb8b6c713ff48b7e790a6b21769273)
1*635a8641SAndroid Build Coastguard Worker // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2*635a8641SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
3*635a8641SAndroid Build Coastguard Worker // found in the LICENSE file.
4*635a8641SAndroid Build Coastguard Worker 
5*635a8641SAndroid Build Coastguard Worker #include "base/test/perf_test_suite.h"
6*635a8641SAndroid Build Coastguard Worker 
7*635a8641SAndroid Build Coastguard Worker #include "base/command_line.h"
8*635a8641SAndroid Build Coastguard Worker #include "base/debug/debugger.h"
9*635a8641SAndroid Build Coastguard Worker #include "base/files/file_path.h"
10*635a8641SAndroid Build Coastguard Worker #include "base/path_service.h"
11*635a8641SAndroid Build Coastguard Worker #include "base/process/launch.h"
12*635a8641SAndroid Build Coastguard Worker #include "base/strings/string_util.h"
13*635a8641SAndroid Build Coastguard Worker #include "base/test/perf_log.h"
14*635a8641SAndroid Build Coastguard Worker #include "build/build_config.h"
15*635a8641SAndroid Build Coastguard Worker #include "testing/gtest/include/gtest/gtest.h"
16*635a8641SAndroid Build Coastguard Worker 
17*635a8641SAndroid Build Coastguard Worker namespace base {
18*635a8641SAndroid Build Coastguard Worker 
PerfTestSuite(int argc,char ** argv)19*635a8641SAndroid Build Coastguard Worker PerfTestSuite::PerfTestSuite(int argc, char** argv) : TestSuite(argc, argv) {}
20*635a8641SAndroid Build Coastguard Worker 
Initialize()21*635a8641SAndroid Build Coastguard Worker void PerfTestSuite::Initialize() {
22*635a8641SAndroid Build Coastguard Worker   TestSuite::Initialize();
23*635a8641SAndroid Build Coastguard Worker 
24*635a8641SAndroid Build Coastguard Worker   // Initialize the perf timer log
25*635a8641SAndroid Build Coastguard Worker   FilePath log_path =
26*635a8641SAndroid Build Coastguard Worker       CommandLine::ForCurrentProcess()->GetSwitchValuePath("log-file");
27*635a8641SAndroid Build Coastguard Worker   if (log_path.empty()) {
28*635a8641SAndroid Build Coastguard Worker     PathService::Get(FILE_EXE, &log_path);
29*635a8641SAndroid Build Coastguard Worker #if defined(OS_ANDROID) || defined(OS_FUCHSIA)
30*635a8641SAndroid Build Coastguard Worker     base::FilePath tmp_dir;
31*635a8641SAndroid Build Coastguard Worker     PathService::Get(base::DIR_CACHE, &tmp_dir);
32*635a8641SAndroid Build Coastguard Worker     log_path = tmp_dir.Append(log_path.BaseName());
33*635a8641SAndroid Build Coastguard Worker #endif
34*635a8641SAndroid Build Coastguard Worker     log_path = log_path.ReplaceExtension(FILE_PATH_LITERAL("log"));
35*635a8641SAndroid Build Coastguard Worker     log_path = log_path.InsertBeforeExtension(FILE_PATH_LITERAL("_perf"));
36*635a8641SAndroid Build Coastguard Worker   }
37*635a8641SAndroid Build Coastguard Worker   ASSERT_TRUE(InitPerfLog(log_path));
38*635a8641SAndroid Build Coastguard Worker 
39*635a8641SAndroid Build Coastguard Worker   // Raise to high priority to have more precise measurements. Since we don't
40*635a8641SAndroid Build Coastguard Worker   // aim at 1% precision, it is not necessary to run at realtime level.
41*635a8641SAndroid Build Coastguard Worker   if (!debug::BeingDebugged())
42*635a8641SAndroid Build Coastguard Worker     RaiseProcessToHighPriority();
43*635a8641SAndroid Build Coastguard Worker }
44*635a8641SAndroid Build Coastguard Worker 
Shutdown()45*635a8641SAndroid Build Coastguard Worker void PerfTestSuite::Shutdown() {
46*635a8641SAndroid Build Coastguard Worker   TestSuite::Shutdown();
47*635a8641SAndroid Build Coastguard Worker   FinalizePerfLog();
48*635a8641SAndroid Build Coastguard Worker }
49*635a8641SAndroid Build Coastguard Worker 
50*635a8641SAndroid Build Coastguard Worker }  // namespace base
51