Fix directory hierarchy & cmake configuration files
[platform/core/appfw/launchpad.git] / src / lib / common / inc / perf.h
1 /*
2  * Copyright (c) 2015 - 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef __PERF_H__
18 #define __PERF_H__
19
20 #ifdef PERF_ACTIVATE
21
22 #include <time.h>
23
24 static struct timespec __g_base_time = {
25         .tv_sec = 0,
26         .tv_nsec = 0
27 };
28
29 #define INIT_PERF(kb) do {                                                     \
30         const char *tmp;                                                       \
31         struct timespec tv;                                                    \
32         tmp = bundle_get_val(kb, AUL_K_STARTTIME);                             \
33         if (tmp != NULL)                                                       \
34                 sscanf(tmp, "%ld/%ld", &tv.tv_sec, &tv.tv_nsec);               \
35         else                                                                   \
36                 clock_gettime(CLOCK_MONOTONIC, &tv);                           \
37         __g_base_time.tv_sec = tv.tv_sec;                                      \
38         __g_base_time.tv_nsec = tv.tv_nsec;                                    \
39 } while (0)
40
41 #define PERF(fmt, arg...) do {                                                 \
42         struct timespec cur;                                                   \
43         struct timespec res;                                                   \
44         clock_gettime(CLOCK_MONOTONIC, &cur);                                  \
45         if (__g_base_time.tv_sec != 0) {                                       \
46                 res->tv_sec = cur.tv_sec - __g_base_time.tv_sec;               \
47                 res->tv_nsec = cur.tv_nsec - __g_base_time.tv_nsec;            \
48                 printf("%c[1;31m[%s,%d] %ld sec %ld msec "fmt                  \
49                                 " %c[0m\n", 27, __func__,                      \
50                                 __LINE__, res.tv_sec,                          \
51                                 res.tv_nsec / 1e6, ##arg, 27);                 \
52         }                                                                      \
53 } while (0)
54
55 #else
56
57 #define INIT_PERF(kb)
58 #define PERF(fmt, arg...)
59
60 #endif
61
62 #endif /* __PERF_H__ */
63