skia2/bench/SkBenchLogger.h
bungeman@google.com fab44db294 Clean up SkTypes.h.
This change removes sk_stdint.h since it is only needed for vs2008 and earlier.
This change removes SK_MMAP_SUPPORT define since it is no longer used.
This change removes the stdio.h include from SkTypes.h since on many systems
this is a very large header, few Skia files actually use it, it is
available everywhere standard, and SkDebugf should be used instead.

After this change there is no need for external users to put Skia's
include/config into their own list of includes, saving the headache
of having two header files of the same name and sometimes getting the
wrong one depending on include order.

R=bsalomon@google.com, djsollen@google.com

Review URL: https://codereview.chromium.org/27044002

git-svn-id: http://skia.googlecode.com/svn/trunk@11738 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-10-11 18:50:45 +00:00

78 lines
2.0 KiB
C++

/*
* 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 SkBenchLogger_DEFINED
#define SkBenchLogger_DEFINED
#include "SkTypes.h"
#include "SkString.h"
#include <stdio.h>
class SkFILEWStream;
/**
* Class that allows logging to a file while simultaneously logging to stdout/stderr.
*/
class SkBenchLogger {
public:
SkBenchLogger();
/**
* Not virtual, since this class is not intended to be subclassed.
*/
~SkBenchLogger();
/**
* Specify a file to write progress logs to. Unless this is called with a valid file path,
* SkBenchLogger 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 // SkBenchLogger_DEFINED