Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / effects / inc / FUiEffects_LoggingProfiler.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  * @file    FUiEffects_LoggingProfiler.h
19  * @brief               This is the header file for the profiling defines
20  */
21
22 #ifndef FUIEXTEFF3D_ELOGPROFILER_H_
23 #define FUIEXTEFF3D_ELOGPROFILER_H_
24
25 #ifdef USE_PROFILER
26
27 #include <FApp.h>
28
29 #ifdef __linux__
30 #include <time.h>
31 #ifndef CLOCK_MONOTONIC_RAW
32 #error Undefined CLOCK_MONOTONIC_RAW
33 #endif
34 #define HIRES_COUNTER_ID CLOCK_MONOTONIC_RAW
35 #else
36 #error Unknown platform
37 #endif
38
39 namespace Tizen { namespace Ui { namespace Effects { namespace _EffectsLogging
40 {
41 //instant measure
42 #define START_PROFILER(Name)\
43                 static timespec Name##_prof_t1, Name##_prof_t2;\
44                 static long Name##_prof_dt = 0;\
45                 clock_gettime(HIRES_COUNTER_ID, &Name##_prof_t1);
46
47 #define END_PROFILER(Name) \
48                 clock_gettime(HIRES_COUNTER_ID, &Name##_prof_t2); \
49                 Name##_prof_dt = (Name##_prof_t2.tv_sec  - Name##_prof_t1.tv_sec) * 1000000 + (Name##_prof_t2.tv_nsec - Name##_prof_t1.tv_nsec) / 1000; \
50                 SysLog(NID_UI_EFFECT, #Name" = %.3f ms", (float) Name##_prof_dt * 0.001f);
51
52 #define PROFILER_EXPR(expression, Name)         \
53                 START_PROFILER(Name)                    \
54                 expression                                              \
55                 END_PROFILER(Name)
56
57 #define PROFILER_EXPR0(expression, Name) expression
58
59 //average measure
60 #define START_PROFILER_AV(Name, N)      \
61                 static timespec Name##_prof_av_t1, Name##_prof_av_t2; \
62                 static long Name##_prof_av_tmin = 999999999, Name##_prof_av_tmax = -1;\
63                 static long Name##_prof_av_dt = 0;\
64                 static unsigned int Name##_prof_av_count = N, Name##_prof_av_N = N; \
65                 clock_gettime(HIRES_COUNTER_ID, &Name##_prof_av_t1);
66
67 #define END_PROFILER_AV(Name)   \
68                 if (Name##_prof_av_count > 0)                                   \
69                 {                                                                       \
70                         clock_gettime(HIRES_COUNTER_ID, &Name##_prof_av_t2);            \
71                         long dt = (Name##_prof_av_t2.tv_sec  - Name##_prof_av_t1.tv_sec) * 1000000 + (Name##_prof_av_t2.tv_nsec - Name##_prof_av_t1.tv_nsec) / 1000;\
72                         if(dt > Name##_prof_av_tmax) Name##_prof_av_tmax = dt; \
73                         if(dt < Name##_prof_av_tmin) Name##_prof_av_tmin = dt; \
74                         Name##_prof_av_dt += dt; \
75                         Name##_prof_av_count--;                                 \
76                 }                                                                       \
77                 else                                                            \
78                 {\
79                         SysLog(NID_UI_EFFECT, #Name" = %.3f ms (min = %.3f, max = %.3f)", float(Name##_prof_av_dt / Name##_prof_av_N) * 0.001f, (float) Name##_prof_av_tmin * 0.001f, (float) Name##_prof_av_tmax * 0.001f);\
80                         Name##_prof_av_count = Name##_prof_av_N;\
81                         Name##_prof_av_dt = 0; \
82                         Name##_prof_av_tmin = 999999999; \
83                         Name##_prof_av_tmax = -1;\
84                 }
85
86 #define PROFILER_EXPR_AV(expression, Name, N)   \
87                 START_PROFILER_AV(Name, N)                      \
88                 expression                                              \
89                 END_PROFILER_AV(Name)
90
91 #define PROFILER_EXPR_AV0(expression, Name, N) expression
92
93 //checkpoint entrance
94 #define PROFILER_CHECKPOINT(Name, N)    \
95                 static timespec Name##_prof_checkp_t1, Name##_prof_checkp_t2;\
96                 static long Name##_prof_checkp_tmin = 999999999, Name##_prof_checkp_tmax = -1;\
97                 static long Name##_prof_checkp_dt = 0;\
98                 static unsigned int Name##_prof_checkp_count = 0, Name##_prof_checkp_N = N;\
99                 \
100                 if (Name##_prof_checkp_count > 0)                                       \
101                 {                                                                       \
102                         clock_gettime(HIRES_COUNTER_ID, &Name##_prof_checkp_t2);                \
103                         long dt = (Name##_prof_checkp_t2.tv_sec  - Name##_prof_checkp_t1.tv_sec) * 1000000 + (Name##_prof_checkp_t2.tv_nsec - Name##_prof_checkp_t1.tv_nsec) / 1000; \
104                         clock_gettime(HIRES_COUNTER_ID, &Name##_prof_checkp_t1);                \
105                         if(dt > Name##_prof_checkp_tmax) Name##_prof_checkp_tmax = dt; \
106                         if(dt < Name##_prof_checkp_tmin) Name##_prof_checkp_tmin = dt; \
107                         Name##_prof_checkp_dt += dt;    \
108                         Name##_prof_checkp_count--;                                     \
109                 }                                                                       \
110                 else                                                            \
111                 {\
112                         clock_gettime(HIRES_COUNTER_ID, &Name##_prof_checkp_t1);                \
113                         SysLog(NID_UI_EFFECT, #Name" = %.3f ms (min = %.3f, max = %.3f)", float(Name##_prof_checkp_dt / Name##_prof_checkp_N) * 0.001f, (float) Name##_prof_checkp_tmin * 0.001f, (float) Name##_prof_checkp_tmax * 0.001f);\
114                         Name##_prof_checkp_count = Name##_prof_checkp_N;\
115                         Name##_prof_checkp_dt = 0;\
116                         Name##_prof_checkp_tmin = 999999999; \
117                         Name##_prof_checkp_tmax = -1;\
118                 }
119
120 } } } } // Tizen::Ui::Effects::_EffectsLogging
121 #else   //USE_PROFILER
122 #define START_PROFILER(Name)
123 #define END_PROFILER(Name)
124 #define PROFILER_EXPR(expression, Name) expression
125 #define PROFILER_EXPR0(expression, Name) expression
126
127 #define START_PROFILER_AV(Name, N)
128 #define END_PROFILER_AV(Name)
129 #define PROFILER_EXPR_AV(expression, Name, N) expression
130 #define PROFILER_EXPR_AV0(expression, Name, N) expression
131
132 #define PROFILER_CHECKPOINT(Name, N)
133 #endif  //USE_PROFILER
134
135 #endif // FUIEXTEFF3D_ELOGPROFILER_H_