Pushed latest libmedia-service for tizen beta
[framework/multimedia/libmedia-service.git] / src / common / media-info-debug.c
1 /*
2  * libmedia-service
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Hyunjun Ko <zzoon.ko@samsung.com>, Haejeong Kim <backto.kim@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 #include <unistd.h>
23 #include <asm/unistd.h>
24 #include <time.h>
25 #include <sys/time.h>
26 #include "media-info-debug.h"
27
28 #ifdef _PERFORMANCE_CHECK_
29 static long g_time_usec = 0L;
30 #endif
31
32 #ifdef _USE_LOG_FILE_
33 static FILE *g_log_fp = NULL;
34 static char _g_file_path[1024] = "\0";
35
36 FILE *get_fp()
37 {
38         return g_log_fp;
39 }
40
41 void mediainfo_init_file_debug()
42 {
43         if (g_log_fp == NULL) {
44                 snprintf(_g_file_path, sizeof(_g_file_path), "/tmp/%s",
45                          "media-info");
46                 if (access(_g_file_path, R_OK == 0)) {
47                         remove(_g_file_path);
48                 }
49
50                 g_log_fp = fopen(_g_file_path, "a");
51         }
52 }
53
54 void mediainfo_close_file_debug()
55 {
56         if (g_log_fp != NULL) {
57                 fclose(g_log_fp);
58                 g_log_fp = NULL;
59         }
60 }
61
62 #endif
63
64 long mediainfo_get_debug_time(void)
65 {
66 #ifdef _PERFORMANCE_CHECK_
67         struct timeval time;
68         gettimeofday(&time, NULL);
69         return time.tv_sec * 1000000 + time.tv_usec;
70 #else
71         return 0L;
72 #endif
73 }
74
75 void mediainfo_reset_debug_time(void)
76 {
77 #ifdef _PERFORMANCE_CHECK_
78         struct timeval time;
79         gettimeofday(&time, NULL);
80         g_time_usec = time.tv_sec * 1000000 + time.tv_usec;
81 #endif
82 }
83
84 void mediainfo_print_debug_time(char *time_string)
85 {
86 #ifdef _PERFORMANCE_CHECK_
87         struct timeval time;
88         double totaltime = 0.0;
89
90         gettimeofday(&time, NULL);
91         totaltime =
92             (double)(time.tv_sec * 1000000 + time.tv_usec -
93                      g_time_usec) / CLOCKS_PER_SEC;
94
95         mediainfo_dbg("time [%s] : %f \n", time_string, totaltime);
96 #endif
97 }
98
99 void
100 mediainfo_print_debug_time_ex(long start, long end, const char *func_name,
101                               char *time_string)
102 {
103 #ifdef _PERFORMANCE_CHECK_
104         double totaltime = 0.0;
105
106         totaltime = (double)(end - start) / CLOCKS_PER_SEC;
107
108         mediainfo_dbg("time [%s: %s] : %f \n", func_name, time_string,
109                       totaltime);
110 #endif
111 }