Apply tizen coding rule
[platform/core/multimedia/libmedia-service.git] / src / common / media-svc-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-svc-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", "media-info");
45                 if (access(_g_file_path, R_OK == 0)) {
46                         remove(_g_file_path);
47                 }
48
49                 g_log_fp = fopen(_g_file_path, "a");
50         }
51 }
52
53 void mediainfo_close_file_debug()
54 {
55         if (g_log_fp != NULL) {
56                 fclose(g_log_fp);
57                 g_log_fp = NULL;
58         }
59 }
60
61 #endif
62
63 long mediainfo_get_debug_time(void)
64 {
65 #ifdef _PERFORMANCE_CHECK_
66         struct timeval time;
67         gettimeofday(&time, NULL);
68         return time.tv_sec * 1000000 + time.tv_usec;
69 #else
70         return 0L;
71 #endif
72 }
73
74 void mediainfo_reset_debug_time(void)
75 {
76 #ifdef _PERFORMANCE_CHECK_
77         struct timeval time;
78         gettimeofday(&time, NULL);
79         g_time_usec = time.tv_sec * 1000000 + time.tv_usec;
80 #endif
81 }
82
83 void mediainfo_print_debug_time(char *time_string)
84 {
85 #ifdef _PERFORMANCE_CHECK_
86         struct timeval time;
87         double totaltime = 0.0;
88
89         gettimeofday(&time, NULL);
90         totaltime = (double)(time.tv_sec * 1000000 + time.tv_usec - g_time_usec) / CLOCKS_PER_SEC;
91
92         media_svc_debug("time [%s] : %f", time_string, totaltime);
93 #endif
94 }
95
96 void
97 mediainfo_print_debug_time_ex(long start, long end, const char *func_name, char *time_string)
98 {
99 #ifdef _PERFORMANCE_CHECK_
100         double totaltime = 0.0;
101
102         totaltime = (double)(end - start) / CLOCKS_PER_SEC;
103
104         media_svc_debug("time [%s: %s] : %f", func_name, time_string, totaltime);
105 #endif
106 }