2 * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include "appcore-internal.h"
23 static struct timeval tv_s; /* measure start */
25 static inline int __get_msec(struct timeval *s, struct timeval *e)
27 return (e->tv_sec - s->tv_sec) * 1000 +
28 (e->tv_usec - s->tv_usec + 500) / 1000;
31 static int __get_time(struct timeval *s)
35 _retv_if(s == NULL || (s->tv_sec == 0 && s->tv_usec == 0), 0);
37 gettimeofday(&t, NULL);
39 return __get_msec(s, &t);
42 static int __get_envtime(const char *name, struct timeval *t)
47 s = getenv(name ? : ENV_START);
48 /*_retvm_if(s == NULL, -1, "%s is not set", name);*/
49 _retv_if(s == NULL, -1);
51 r = sscanf(s, "%u/%u", (int *)&t->tv_sec, (int *)&t->tv_usec);
53 r = sscanf(s, "%u %u", (int *)&t->tv_sec, (int *)&t->tv_usec);
60 static int __get_time_from(const char *name)
66 gettimeofday(&t, NULL);
68 r = __get_envtime(name, &s);
71 return __get_msec(&s, &t);
74 EXPORT_API int appcore_measure_time_from(const char *envnm)
76 return __get_time_from(envnm);
79 EXPORT_API int appcore_measure_time(void)
81 return __get_time(&tv_s);
84 EXPORT_API void appcore_measure_start(void)
86 gettimeofday(&tv_s, NULL);