| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stdio.h> | |
| 6 | |
| 7 #include "base/perftimer.h" | 5 #include "base/perftimer.h" |
| 8 | 6 |
| 7 #include <stdio.h> |
| 8 #include <string> |
| 9 |
| 9 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/file_util.h" |
| 10 #include "base/logging.h" | 12 #include "base/logging.h" |
| 11 | 13 |
| 12 static FILE* perf_log_file = NULL; | 14 static FILE* perf_log_file = NULL; |
| 13 | 15 |
| 14 bool InitPerfLog(const char* log_file) { | 16 bool InitPerfLog(const char* log_file) { |
| 15 if (perf_log_file) { | 17 if (perf_log_file) { |
| 16 // trying to initialize twice | 18 // trying to initialize twice |
| 17 NOTREACHED(); | 19 NOTREACHED(); |
| 18 return false; | 20 return false; |
| 19 } | 21 } |
| 20 | 22 |
| 21 #if defined(OS_WIN) | 23 perf_log_file = file_util::OpenFile(std::string(log_file), "w"); |
| 22 return fopen_s(&perf_log_file, log_file, "w") == 0; | |
| 23 #elif defined(OS_POSIX) | |
| 24 perf_log_file = fopen(log_file, "w"); | |
| 25 return perf_log_file != NULL; | 24 return perf_log_file != NULL; |
| 26 #endif | |
| 27 } | 25 } |
| 28 | 26 |
| 29 void FinalizePerfLog() { | 27 void FinalizePerfLog() { |
| 30 if (!perf_log_file) { | 28 if (!perf_log_file) { |
| 31 // trying to cleanup without initializing | 29 // trying to cleanup without initializing |
| 32 NOTREACHED(); | 30 NOTREACHED(); |
| 33 return; | 31 return; |
| 34 } | 32 } |
| 35 fclose(perf_log_file); | 33 file_util::CloseFile(perf_log_file); |
| 36 } | 34 } |
| 37 | 35 |
| 38 void LogPerfResult(const char* test_name, double value, const char* units) { | 36 void LogPerfResult(const char* test_name, double value, const char* units) { |
| 39 if (!perf_log_file) { | 37 if (!perf_log_file) { |
| 40 NOTREACHED(); | 38 NOTREACHED(); |
| 41 return; | 39 return; |
| 42 } | 40 } |
| 43 | 41 |
| 44 fprintf(perf_log_file, "%s\t%g\t%s\n", test_name, value, units); | 42 fprintf(perf_log_file, "%s\t%g\t%s\n", test_name, value, units); |
| 45 printf("%s\t%g\t%s\n", test_name, value, units); | 43 printf("%s\t%g\t%s\n", test_name, value, units); |
| 46 } | 44 } |
| OLD | NEW |