2012-09-07 15:21:18 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
#ifndef BenchLogger_DEFINED
|
|
|
|
#define BenchLogger_DEFINED
|
2012-09-07 15:21:18 +00:00
|
|
|
|
2013-10-11 18:50:45 +00:00
|
|
|
#include <stdio.h>
|
2014-06-19 19:32:29 +00:00
|
|
|
#include "SkString.h"
|
|
|
|
#include "SkTypes.h"
|
2012-09-07 15:21:18 +00:00
|
|
|
|
|
|
|
class SkFILEWStream;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class that allows logging to a file while simultaneously logging to stdout/stderr.
|
|
|
|
*/
|
2014-06-19 19:32:29 +00:00
|
|
|
class BenchLogger {
|
2012-09-07 15:21:18 +00:00
|
|
|
public:
|
2014-06-19 19:32:29 +00:00
|
|
|
BenchLogger();
|
2012-09-07 15:21:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Not virtual, since this class is not intended to be subclassed.
|
|
|
|
*/
|
2014-06-19 19:32:29 +00:00
|
|
|
~BenchLogger();
|
2012-09-07 15:21:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Specify a file to write progress logs to. Unless this is called with a valid file path,
|
2014-06-19 19:32:29 +00:00
|
|
|
* BenchLogger will only write to stdout/stderr.
|
2012-09-07 15:21:18 +00:00
|
|
|
*/
|
|
|
|
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
|
2013-10-09 15:09:42 +00:00
|
|
|
void nativeLogProgress(const char msg[]) { SkDebugf("%s", msg); }
|
2012-09-07 15:21:18 +00:00
|
|
|
|
|
|
|
void fileWrite(const char msg[], size_t size);
|
|
|
|
|
|
|
|
SkFILEWStream* fFileStream;
|
|
|
|
};
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
#endif // BenchLogger_DEFINED
|