180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/* 380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Copyright 2012 Google Inc. 480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * 580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Use of this source code is governed by a BSD-style license that can be 680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * found in the LICENSE file. 780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#ifndef SkBenchLogger_DEFINED 1080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define SkBenchLogger_DEFINED 1180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkTypes.h" 1380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkString.h" 140a657bbc2c6fc9daf699942e023050536d5ec95fDerek Sollenberger#include <stdio.h> 1580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruclass SkFILEWStream; 1780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/** 1980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Class that allows logging to a file while simultaneously logging to stdout/stderr. 2080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 2180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruclass SkBenchLogger { 2280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querupublic: 2380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkBenchLogger(); 2480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 2580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** 2680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Not virtual, since this class is not intended to be subclassed. 2780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 2880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru ~SkBenchLogger(); 2980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 3080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** 3180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Specify a file to write progress logs to. Unless this is called with a valid file path, 3280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * SkBenchLogger will only write to stdout/stderr. 3380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 3480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru bool SetLogFile(const char file[]); 3580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 3680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** 3780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Log an error to stderr, taking a C style string as input. 3880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 3980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void logError(const char msg[]) { this->nativeLogError(msg); } 4080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 4180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** 4280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Log an error to stderr, taking an SkString as input. 4380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 4480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void logError(const SkString& str) { this->nativeLogError(str.c_str()); } 4580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 4680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** 4780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Log the progress of the bench tool to both stdout and the log file specified by SetLogFile, 4880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * if any, taking a C style string as input. 4980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 5080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void logProgress(const char msg[]) { 5180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru this->nativeLogProgress(msg); 5280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru this->fileWrite(msg, strlen(msg)); 5380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 5480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 5580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** 5680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Log the progress of the bench tool to both stdout and the log file specified by SetLogFile, 5780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * if any, taking an SkString as input. 5880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 5980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void logProgress(const SkString& str) { 6080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru this->nativeLogProgress(str.c_str()); 6180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru this->fileWrite(str.c_str(), str.size()); 6280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 6380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 6480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruprivate: 6580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#ifdef SK_BUILD_FOR_ANDROID 6680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void nativeLogError(const char msg[]) { SkDebugf("%s", msg); } 6780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#else 6880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void nativeLogError(const char msg[]) { fprintf(stderr, "%s", msg); } 6980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif 700a657bbc2c6fc9daf699942e023050536d5ec95fDerek Sollenberger void nativeLogProgress(const char msg[]) { SkDebugf("%s", msg); } 7180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 7280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void fileWrite(const char msg[], size_t size); 7380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 7480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkFILEWStream* fFileStream; 7580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}; 7680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 7780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif // SkBenchLogger_DEFINED 78