Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / animations / FUiAnim_Debug.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://floralicense.org/license/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file        FUiAnim_Debug.h
20  * @brief       Header file of _VeDebug class
21  *
22  * This file contains declarations _VeDebug class.
23  */
24
25 #ifndef _FUI_ANIM_INTERNAL_DEBUG_H_
26 #define _FUI_ANIM_INTERNAL_DEBUG_H_
27
28 #include <sys/time.h>
29 #include <Evas.h>
30
31 //#define VE_DEBUG // debug config
32 #define VE_DEBUG_MODULE
33
34 namespace Tizen { namespace Ui { namespace Animations
35 {
36
37 #ifdef VE_DEBUG_MODULE
38
39 #ifdef  _OSP_PERF_
40 class _ElapsedTime
41 {
42 public:
43         _ElapsedTime(const char* tag = null)
44         {
45                 struct timeval tv;
46
47                 tagName = tag;
48
49                 gettimeofday(&tv, null);
50                 start_time = (long long)tv.tv_sec * 1000000LL + (long long)tv.tv_usec / 1LL;
51
52                 depth++;
53                 maxdepth++;
54         }
55
56         ~_ElapsedTime(void)
57         {
58                 long long end_time;
59                 struct timeval tv;
60                 gettimeofday(&tv, null);
61                 end_time = (long long)tv.tv_sec * 1000000LL + (long long)tv.tv_usec / 1LL;
62
63                 depth--;
64                 if (count < 500)
65                         snprintf(logs[count++], 256, "%*s -->[%s]=%lld us\n", depth * 3, " ", tagName, end_time - start_time);
66
67                 if (depth == 0)
68                 {
69                         for (int i = 0; i < count; i++)
70                                 printf("%s", logs[i]);
71
72                         maxdepth = 0;
73                         count = 0;
74                 }
75         }
76
77
78 public:
79         static char logs[500][256];
80         static int depth;
81         static int count;
82         static int maxdepth;
83         long long start_time;
84         const char* tagName;
85 };              // _ElapsedTime
86 #endif
87
88 #define VeLog(UID, ...) \
89         SysLogInternal(UID, 0, 0, __VA_ARGS__);
90 #define VELOG(...) \
91         do \
92         { \
93                 if (_VeDebug::IsDebugEnabled()) \
94                 { \
95                         _VeDebug::DumpVisualElement(this, __func__, __LINE__, __VA_ARGS__); \
96                 } \
97         } while (0)
98
99 #define VELOGEX(_ELEMENT_, ...) \
100         do \
101         { \
102                 if (_VeDebug::IsDebugEnabled()) \
103                 { \
104                         _VeDebug::DumpVisualElement(_ELEMENT_, __func__, __LINE__, __VA_ARGS__); \
105                 } \
106         } while (0)
107
108 #define VELOGEX_NOFUNCTION(_ELEMENT_, ...) \
109         do \
110         { \
111                 if (_VeDebug::IsDebugEnabled()) \
112                 { \
113                         _VeDebug::DumpVisualElement(_ELEMENT_, null, 0, __VA_ARGS__); \
114                 } \
115         } while (0)
116
117 #define VEDUMPTREE(_ELEMENT_, _INDENT_) \
118         do \
119         { \
120                 if (_VeDebug::IsDebugEnabled()) \
121                 { \
122                         _VeDebug::DumpVeTree(_ELEMENT_, _INDENT_); \
123                 } \
124         } while (0)
125
126 #define VELOGRECTTAG    "[%.1f:%.1f ~ %.1f:%.1f]"
127 #define VELOGRECT(r)    (r).x, (r).y, (r).GetBottomRight().x, (r).GetBottomRight().y
128
129 class _VisualElementImpl;
130
131 class _VeDebug
132 {
133 public:
134         static void DumpVisualElement(_VisualElementImpl* pElement, const char* func, int line, const char* fmt, ...);
135         static void PrintVeTree(_VisualElementImpl* pElement = 0, int depth = 0, unsigned int remainedChild = 0);
136         static void DumpVeTree(_VisualElementImpl* pElement = 0, int indent = 0);
137         static void DumpVeImage(_VisualElementImpl* pElement = 0, const char* pathPrefix = 0);
138         static void DumpAllVeImages(_VisualElementImpl* pElement = 0, const char* pathPrefix = 0);
139         static void ReflushAll(_VisualElementImpl* pElement, int depth = 0);
140         static void SetDebugEnabled(bool enable);
141         static bool IsDebugEnabled(void);
142
143         static void DumpEvasTree(_VisualElementImpl* pElement, int indent);
144         static void DumpAllEvas(void);
145
146         static void DumpEvasObjectForGraphI(FILE* pFile, Evas_Object* pEvasObject, int depth, int pos);
147         static void DumpEvasTreeGraphI(FILE* pFile, Evas_Object* pObject, int depth, int pos);
148         static void DumpVeObjectForGraphI(FILE* pFile, _VisualElementImpl* pVisualElementImpl, int depth, int pos);
149         static void DumpVeTreeGraphI(FILE* pFile, _VisualElementImpl* pVisualElementImpl, int depth, int pos);
150
151         static void DumpEvasTreeGraph(const char* pFilePath, VisualElement* pVisualElement);
152
153
154 private:
155         _VeDebug(void);
156         _VeDebug(const _VeDebug& rhs);
157         ~_VeDebug(void);
158
159         _VeDebug& operator =(const _VeDebug& rhs);
160
161 private:
162         static void DumpEvasTreeI(Evas_Object* pParent, int indent);
163
164 private:
165         static bool __veDebugEnabled;
166 };              //_VeDebug
167
168 #else
169 #define VELOG(...)
170 #define VELOGEX(_Element_, ...)
171 #define VELOGEX_NOFUNCTION(_ELEMENT_, ...)
172 #define VEDUMPTREE(_ELEMENT_, _INDENT_)
173 #define VELOGRECTTAG
174 #define VELOGRECT(r)
175 #endif
176
177 }}}             // Tizen::Ui::Animations
178
179 #endif //_FUI_ANIM_INTERNAL_DEBUG_H_
180