Git init
[framework/appfw/aul-1.git] / include / perf.h
1 /*
2  *  aul
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22
23 #ifndef __PERF_H__
24 #define __PERF_H__
25
26 #ifdef PERF_ACTIVATE
27
28 #include <sys/time.h>
29 static struct timeval __g_base_time = {
30         .tv_sec = 0,
31         .tv_usec = 0
32 };
33
34 #define INIT_PERF(kb)\
35 do {\
36         const char *tmp;\
37         struct timeval tv;\
38         tmp = bundle_get_val(kb, AUL_K_STARTTIME);\
39         if (tmp != NULL)\
40                 sscanf(tmp, "%ld/%ld", &tv.tv_sec, &tv.tv_usec);\
41         else\
42                 gettimeofday(&tv, NULL);\
43         __g_base_time.tv_sec = tv.tv_sec;\
44         __g_base_time.tv_usec = tv.tv_usec;\
45 } while (0);
46
47 #define PERF(fmt, arg...)\
48 do {\
49         struct timeval cur;\
50         struct timeval res;\
51         gettimeofday(&cur, NULL);\
52         if (__g_base_time.tv_sec != 0) {\
53                 timersub(&cur, &__g_base_time, &res);\
54                 printf("%c[1;31m[%s,%d] %ld sec %ld msec "fmt" %c[0m\n",\
55                         27, __FUNCTION__, __LINE__, \
56                                 res.tv_sec, res.tv_usec/1000, ##arg, 27);\
57         } \
58 } while (0);
59
60 #else
61
62 #define INIT_PERF(kb)
63 #define PERF(fmt, arg...)
64
65 #endif
66
67 #endif
68