35b092640f92e00a0e450605dc27de8136651045
[platform/framework/web/wrt.git] / src / wrt-launchpad-daemon / include / perf.h
1 /*
2  * Copyright (c) 2011 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
18 #ifndef __PERF_H__
19 #define __PERF_H__
20
21 #ifdef PERF_ACTIVATE
22
23 #include <sys/time.h>
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         tmp = bundle_get_val(kb, AUL_K_STARTTIME);\
34         if (tmp != NULL)\
35                 sscanf(tmp, "%ld/%ld", &tv.tv_sec, &tv.tv_usec);\
36         else\
37                 gettimeofday(&tv, NULL);\
38         __g_base_time.tv_sec = tv.tv_sec;\
39         __g_base_time.tv_usec = tv.tv_usec;\
40 } while (0);
41
42 #define PERF(fmt, arg...)\
43 do {\
44         struct timeval cur;\
45         struct timeval res;\
46         gettimeofday(&cur, NULL);\
47         if (__g_base_time.tv_sec != 0) {\
48                 timersub(&cur, &__g_base_time, &res);\
49                 printf("%c[1;31m[%s,%d] %ld sec %ld msec "fmt" %c[0m\n",\
50                         27, __FUNCTION__, __LINE__, \
51                                 res.tv_sec, res.tv_usec/1000, ##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
63