2 * Copyright (c) 2012 - 2014 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.
25 /* Measure elapased time */
27 _SCL_DEBUG_ELAPSED_TIME(const char* str, struct timeval t0, struct timeval t1);
29 /* Measure elapased time */
30 float SCL_DEBUG_TIME(const char* fileStr, int line, const char* str)
33 static struct timeval t0 = {
36 static struct timeval t1;
37 char *pFileStr = const_cast<char*>(fileStr);
39 if (strlen(fileStr) > 20) {
40 pFileStr += (strlen(fileStr) - 20);
42 gettimeofday(&t1, NULL);
43 if (t0.tv_usec != 0) {
44 etime = ((t1.tv_sec * 1000000 + t1.tv_usec) - (t0.tv_sec * 1000000 + t0.tv_usec))/1000000.0;
46 if (strncmp(str, "get_", 4) == 0) {
47 //printf("[%-20.20s]%04d [T:%u][E:" mc_red "%f" mc_normal "]" mc_normal " %s" mc_normal "\n", pFileStr, line, (t1.tv_sec * 1000000 + t1.tv_usec), etime, str);
49 printf("[%-20.20s]%04d [T:%lu][E:" mc_red "%f" mc_normal "]" mc_blue " %s" mc_normal "\n", pFileStr, line, (t1.tv_sec * 1000000 + t1.tv_usec), etime, str);
56 /* Measure elapsed time */
57 static float _SCL_DEBUG_ELAPSED_TIME(const char* str, struct timeval t0, struct timeval t1)
60 etime = ((t1.tv_sec * 1000000 + t1.tv_usec) - (t0.tv_sec * 1000000 + t0.tv_usec))/1000000.0;
62 printf("[%s] elap-time = " mc_green "%f ms" mc_normal " (%lu~%lu) \n", str, etime*1000, (t0.tv_sec * 1000000 + t0.tv_usec), (t1.tv_sec * 1000000 + t1.tv_usec));
66 /* Measure elapsed time */
67 float SCL_DEBUG_ELAPSED_TIME(const char* fileStr, int line, const char* str, int type)
69 static struct timeval s_tv1;
70 static struct timeval s_tv2;
71 static int s_start_line = 0;
72 static int s_end_line = 0;
74 if (type == MEASURE_START) {
75 gettimeofday(&s_tv1, NULL);
77 printf("[%-20.20s]%04d [T:%lu]" mc_blue " %s" mc_normal "\n", fileStr, line, (s_tv1.tv_sec * 1000000 + s_tv1.tv_usec), str);
78 } else if (type == MEASURE_END) {
79 gettimeofday(&s_tv2, NULL);
82 snprintf(printStr, 100, "%s(Line:%d~%d)", str, s_start_line, s_end_line);
83 etime = _SCL_DEBUG_ELAPSED_TIME(printStr, s_tv1, s_tv2);