aboutsummaryrefslogtreecommitdiffhomepage
path: root/bench/BenchLogger.h
diff options
context:
space:
mode:
authorGravatar tfarina <tfarina@chromium.org>2014-06-19 12:32:29 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-06-19 12:32:29 -0700
commitf168b86d7fafc5c20c87bebc6fd393cb17e120ca (patch)
tree9a1b1cff3725cc6cc030657fd83b5dca12137d86 /bench/BenchLogger.h
parent8e80d17d2b63fa84081236012f31bb10c58d344d (diff)
Remove Sk prefix from some bench classes.
This idea came while commenting on https://codereview.chromium.org/343583005/ Since SkBenchmark, SkBenchLogger and SkGMBench are not part of the Skia library, they should not have the Sk prefix. BUG=None TEST=make all R=mtklein@google.com Author: tfarina@chromium.org Review URL: https://codereview.chromium.org/347823004
Diffstat (limited to 'bench/BenchLogger.h')
-rw-r--r--bench/BenchLogger.h76
1 files changed, 76 insertions, 0 deletions
diff --git a/bench/BenchLogger.h b/bench/BenchLogger.h
new file mode 100644
index 0000000000..a7c283ad50
--- /dev/null
+++ b/bench/BenchLogger.h
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2012 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef BenchLogger_DEFINED
+#define BenchLogger_DEFINED
+
+#include <stdio.h>
+#include "SkString.h"
+#include "SkTypes.h"
+
+class SkFILEWStream;
+
+/**
+ * Class that allows logging to a file while simultaneously logging to stdout/stderr.
+ */
+class BenchLogger {
+public:
+ BenchLogger();
+
+ /**
+ * Not virtual, since this class is not intended to be subclassed.
+ */
+ ~BenchLogger();
+
+ /**
+ * Specify a file to write progress logs to. Unless this is called with a valid file path,
+ * BenchLogger will only write to stdout/stderr.
+ */
+ bool SetLogFile(const char file[]);
+
+ /**
+ * Log an error to stderr, taking a C style string as input.
+ */
+ void logError(const char msg[]) { this->nativeLogError(msg); }
+
+ /**
+ * Log an error to stderr, taking an SkString as input.
+ */
+ void logError(const SkString& str) { this->nativeLogError(str.c_str()); }
+
+ /**
+ * Log the progress of the bench tool to both stdout and the log file specified by SetLogFile,
+ * if any, taking a C style string as input.
+ */
+ void logProgress(const char msg[]) {
+ this->nativeLogProgress(msg);
+ this->fileWrite(msg, strlen(msg));
+ }
+
+ /**
+ * Log the progress of the bench tool to both stdout and the log file specified by SetLogFile,
+ * if any, taking an SkString as input.
+ */
+ void logProgress(const SkString& str) {
+ this->nativeLogProgress(str.c_str());
+ this->fileWrite(str.c_str(), str.size());
+ }
+
+private:
+#ifdef SK_BUILD_FOR_ANDROID
+ void nativeLogError(const char msg[]) { SkDebugf("%s", msg); }
+#else
+ void nativeLogError(const char msg[]) { fprintf(stderr, "%s", msg); }
+#endif
+ void nativeLogProgress(const char msg[]) { SkDebugf("%s", msg); }
+
+ void fileWrite(const char msg[], size_t size);
+
+ SkFILEWStream* fFileStream;
+};
+
+#endif // BenchLogger_DEFINED