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 #define ATRACE_TAG ATRACE_TAG_WEBVIEW 34 35 #include <cutils/log.h> 36 #include <utils/Trace.h> 37 #include <wtf/CurrentTime.h> 38 39 #ifdef ANDROID_DOM_LOGGING 40 #include <stdio.h> 41 extern FILE* gDomTreeFile; 42 #define DOM_TREE_LOG_FILE "/sdcard/domTree.txt" 43 #define DUMP_DOM_LOGD(...) { if (gDomTreeFile) \ 44 fprintf(gDomTreeFile, __VA_ARGS__); else ALOGD(__VA_ARGS__); } 45 46 extern FILE* gRenderTreeFile; 47 #define RENDER_TREE_LOG_FILE "/sdcard/renderTree.txt" 48 #define DUMP_RENDER_LOGD(...) { if (gRenderTreeFile) \ 49 fprintf(gRenderTreeFile, __VA_ARGS__); else ALOGD(__VA_ARGS__); } 50 #else 51 #define DUMP_DOM_LOGD(...) ((void)0) 52 #define DUMP_RENDER_LOGD(...) ((void)0) 53 #endif /* ANDROID_DOM_LOGGING */ 54 55 #define DISPLAY_TREE_LOG_FILE "/sdcard/displayTree.txt" 56 #define LAYERS_TREE_LOG_FILE "/sdcard/layersTree.plist" 57 58 #define FLOAT_RECT_FORMAT "[x=%.2f,y=%.2f,w=%.2f,h=%.2f]" 59 #define FLOAT_RECT_ARGS(fr) fr.x(), fr.y(), fr.width(), fr.height() 60 #define INT_RECT_FORMAT "[x=%d,y=%d,w=%d,h=%d]" 61 #define INT_RECT_ARGS(ir) ir.x(), ir.y(), ir.width(), ir.height() 62 63 #define TRACE_METHOD() android::ScopedTrace __st(ATRACE_TAG, __func__); 64 65 #define TIME_METHOD() MethodTimer __method_timer(__func__) 66 class MethodTimer { 67 public: 68 MethodTimer(const char* name) 69 : m_methodName(name) 70 { 71 m_startTime = currentTimeMS(); 72 } 73 virtual ~MethodTimer() { 74 double duration = currentTimeMS() - m_startTime; 75 ALOGD("%s took %.2fms", m_methodName, duration); 76 } 77 private: 78 const char* m_methodName; 79 double m_startTime; 80 }; 81 82 #endif // AndroidLog_h 83