1 // Copyright 2013 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifdef UNSAFE_BUFFERS_BUILD
6 // TODO(crbug.com/40284755): Remove this and spanify to fix the errors.
7 #pragma allow_unsafe_buffers
8 #endif
9
10 #include "base/test/perf_log.h"
11
12 #include "base/check.h"
13 #include "base/files/file_util.h"
14 #include "base/notreached.h"
15
16 namespace base {
17
18 static FILE* perf_log_file = nullptr;
19
InitPerfLog(const FilePath & log_file)20 bool InitPerfLog(const FilePath& log_file) {
21 if (perf_log_file) {
22 // trying to initialize twice
23 NOTREACHED();
24 }
25
26 perf_log_file = OpenFile(log_file, "w");
27 return perf_log_file != nullptr;
28 }
29
FinalizePerfLog()30 void FinalizePerfLog() {
31 if (!perf_log_file) {
32 // trying to cleanup without initializing
33 NOTREACHED();
34 }
35 base::CloseFile(perf_log_file);
36 }
37
LogPerfResult(const char * test_name,double value,const char * units)38 void LogPerfResult(const char* test_name, double value, const char* units) {
39 CHECK(perf_log_file);
40
41 fprintf(perf_log_file, "%s\t%g\t%s\n", test_name, value, units);
42 printf("%s\t%g\t%s\n", test_name, value, units);
43 fflush(stdout);
44 }
45
46 } // namespace base
47