perf_log.cc 1006 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright 2013 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. #include "base/test/perf_log.h"
  5. #include "base/files/file_util.h"
  6. #include "base/notreached.h"
  7. namespace base {
  8. static FILE* perf_log_file = nullptr;
  9. bool InitPerfLog(const FilePath& log_file) {
  10. if (perf_log_file) {
  11. // trying to initialize twice
  12. NOTREACHED();
  13. return false;
  14. }
  15. perf_log_file = OpenFile(log_file, "w");
  16. return perf_log_file != nullptr;
  17. }
  18. void FinalizePerfLog() {
  19. if (!perf_log_file) {
  20. // trying to cleanup without initializing
  21. NOTREACHED();
  22. return;
  23. }
  24. base::CloseFile(perf_log_file);
  25. }
  26. void LogPerfResult(const char* test_name, double value, const char* units) {
  27. if (!perf_log_file) {
  28. NOTREACHED();
  29. return;
  30. }
  31. fprintf(perf_log_file, "%s\t%g\t%s\n", test_name, value, units);
  32. printf("%s\t%g\t%s\n", test_name, value, units);
  33. fflush(stdout);
  34. }
  35. } // namespace base