4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
27 #include "appcore-internal.h"
29 static struct timeval tv_s; /* measure start */
31 static inline int __get_msec(struct timeval *s, struct timeval *e)
33 return (e->tv_sec - s->tv_sec) * 1000 +
34 (e->tv_usec - s->tv_usec + 500) / 1000;
37 static int __get_time(struct timeval *s)
41 _retv_if(s == NULL || (s->tv_sec == 0 && s->tv_usec == 0), 0);
43 gettimeofday(&t, NULL);
45 return __get_msec(s, &t);
48 static int __get_envtime(const char *name, struct timeval *t)
53 s = getenv(name ? : ENV_START);
54 /*_retvm_if(s == NULL, -1, "%s is not set", name);*/
55 _retv_if(s == NULL, -1);
57 r = sscanf(s, "%u/%u", (int *)&t->tv_sec, (int *)&t->tv_usec);
59 r = sscanf(s, "%u %u", (int *)&t->tv_sec, (int *)&t->tv_usec);
66 static int __get_time_from(const char *name)
72 gettimeofday(&t, NULL);
74 r = __get_envtime(name, &s);
77 return __get_msec(&s, &t);
80 EXPORT_API int appcore_measure_time_from(const char *envnm)
82 return __get_time_from(envnm);
85 EXPORT_API int appcore_measure_time(void)
87 return __get_time(&tv_s);
90 EXPORT_API void appcore_measure_start(void)
92 gettimeofday(&tv_s, NULL);