1 /* 2 * Copyright 2008, The Android Open Source Project 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * * Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * * Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26 #ifndef AndroidLog_h 27 #define AndroidLog_h 28 29 #ifndef LOG_TAG 30 #define LOG_TAG __FILE__ 31 #endif 32 33 #include <cutils/log.h> 34 #include <utils/Trace.h> 35 #include <wtf/CurrentTime.h> 36 37 #ifdef ANDROID_DOM_LOGGING 38 #include <stdio.h> 39 extern FILE* gDomTreeFile; 40 #define DOM_TREE_LOG_FILE "/sdcard/domTree.txt" 41 #define DUMP_DOM_LOGD(...) { if (gDomTreeFile) \ 42 fprintf(gDomTreeFile, __VA_ARGS__); else ALOGD(__VA_ARGS__); } 43 44 extern FILE* gRenderTreeFile; 45 #define RENDER_TREE_LOG_FILE "/sdcard/renderTree.txt" 46 #define DUMP_RENDER_LOGD(...) { if (gRenderTreeFile) \ 47 fprintf(gRenderTreeFile, __VA_ARGS__); else ALOGD(__VA_ARGS__); } 48 #else 49 #define DUMP_DOM_LOGD(...) ((void)0) 50 #define DUMP_RENDER_LOGD(...) ((void)0) 51 #endif /* ANDROID_DOM_LOGGING */ 52 53 #define DISPLAY_TREE_LOG_FILE "/sdcard/displayTree.txt" 54 #define LAYERS_TREE_LOG_FILE "/sdcard/layersTree.plist" 55 56 #define FLOAT_RECT_FORMAT "[x=%.2f,y=%.2f,w=%.2f,h=%.2f]" 57 #define FLOAT_RECT_ARGS(fr) fr.x(), fr.y(), fr.width(), fr.height() 58 #define INT_RECT_FORMAT "[x=%d,y=%d,w=%d,h=%d]" 59 #define INT_RECT_ARGS(ir) ir.x(), ir.y(), ir.width(), ir.height() 60 61 #define TRACE_METHOD() android::ScopedTrace __st(ATRACE_TAG_WEBVIEW, __func__); 62 63 #define TIME_METHOD() MethodTimer __method_timer(__func__) 64 class MethodTimer { 65 public: MethodTimer(const char * name)66 MethodTimer(const char* name) 67 : m_methodName(name) 68 { 69 m_startTime = currentTimeMS(); 70 } ~MethodTimer()71 virtual ~MethodTimer() { 72 double duration = currentTimeMS() - m_startTime; 73 ALOGD("%s took %.2fms", m_methodName, duration); 74 } 75 private: 76 const char* m_methodName; 77 double m_startTime; 78 }; 79 80 #endif // AndroidLog_h 81