Adjust coding rules
[platform/core/appfw/debug-launchpad.git] / include / 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 #include <sys/time.h>
22 #include <bundle_internal.h>
23
24 static struct timeval __g_base_time = {
25         .tv_sec = 0,
26         .tv_usec = 0
27 };
28
29 #define INIT_PERF(kb) \
30         do { \
31                 const char *tmp; \
32                 struct timeval tv; \
33                 int ret; \
34                 tmp = bundle_get_val(kb, AUL_K_STARTTIME); \
35                 if (tmp != NULL) { \
36                         ret = sscanf(tmp, "%ld/%ld", &tv.tv_sec, &tv.tv_usec); \
37                         if (ret != 2) \
38                                 printf("Failed to convert format\n"); \
39                 } else { \
40                         gettimeofday(&tv, NULL); \
41                 } \
42                 __g_base_time.tv_sec = tv.tv_sec; \
43                 __g_base_time.tv_usec = tv.tv_usec; \
44         } while (0)
45
46 #define PERF(fmt, arg...) \
47         do { \
48                 struct timeval cur; \
49                 struct timeval res; \
50                 gettimeofday(&cur, NULL); \
51                 if (__g_base_time.tv_sec != 0) { \
52                         timersub(&cur, &__g_base_time, &res); \
53                         printf("%c[1;31m[%s,%d] %ld sec %ld msec " \
54                                         fmt" %c[0m\n", \
55                                         27, __func__, __LINE__, \
56                                         res.tv_sec, res.tv_usec/1000, \
57                                         ##arg, 27); \
58                 } \
59         } while (0)
60 #else
61 #define INIT_PERF(kb)
62 #define PERF(fmt, arg...)
63 #endif
64
65 #endif /* __PERF_H__ */
66