1 /*
2 * Copyright (c) 2010, Texas Instruments Incorporated
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * * Neither the name of Texas Instruments Incorporated nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 /*
34 * @file timm_osal_trace.c
35 * This file contains methods that provides the functionality
36 * for logging errors/warings/information/etc.
37 *
38 * @path \
39 *
40 */
41 /* -------------------------------------------------------------------------- */
42 /* =========================================================================
43 *!
44 *! Revision History
45 *! ===================================
46 *!
47 * ========================================================================= */
48
49 /******************************************************************************
50 * Includes
51 ******************************************************************************/
52
53 /*#include "typedefs.h"*/
54 #include <stdarg.h>
55 #include <stdio.h>
56 #include <stdlib.h>
57 #include "timm_osal_trace.h"
58
59 #ifdef _Android
60 #define LOG_TAG "DOMX"
61 #include <utils/Log.h>
62 #include <cutils/properties.h>
63 #endif
64
65 /**
66 * The OSAL debug trace detail can be set at compile time by defining the flag
67 * TIMM_OSAL_DEBUG_TRACE_DETAIL=<Details>
68 * detail - 0 - no detail
69 * 1 - function name
70 * 2 - function name, line number
71 * Prefix is added to every debug trace message
72 */
73 #ifndef TIMM_OSAL_DEBUG_TRACE_DETAIL
74 #define TIMM_OSAL_DEBUG_TRACE_DETAIL 2
75 #endif
76
77 #define DEFAULT_TRACE_LEVEL TIMM_OSAL_TRACE_LEVEL_ERROR
78
79 static int trace_level = -1;
80
81 /* strip out leading ../ stuff that happens to __FILE__ for out-of-tree builds */
simplify_path(const char * file)82 static const char *simplify_path(const char *file)
83 {
84 while (file)
85 {
86 char c = file[0];
87 if ((c != '.') && (c != '/') && (c != '\\'))
88 break;
89 file++;
90 }
91 return file;
92 }
93
TIMM_OSAL_UpdateTraceLevel(void)94 void TIMM_OSAL_UpdateTraceLevel(void)
95 {
96 char *val = getenv("TIMM_OSAL_DEBUG_TRACE_LEVEL");
97
98 if (val)
99 {
100 trace_level = strtol(val, NULL, 0);
101 }
102 else
103 {
104 #ifdef _Android
105 char value[PROPERTY_VALUE_MAX];
106 int val;
107
108 property_get("debug.domx.trace_level", value, "0");
109 val = atoi(value);
110 if ( (!val) || (val < 0) )
111 {
112 trace_level = DEFAULT_TRACE_LEVEL;
113 }
114 else
115 trace_level = val;
116 #else
117 trace_level = DEFAULT_TRACE_LEVEL;
118 #endif
119 }
120 }
121
__TIMM_OSAL_TraceFunction(const __TIMM_OSAL_TRACE_LOCATION * loc,const char * fmt,...)122 void __TIMM_OSAL_TraceFunction(const __TIMM_OSAL_TRACE_LOCATION * loc,
123 const char *fmt, ...)
124 {
125 if (trace_level == -1)
126 {
127 char *val = getenv("TIMM_OSAL_DEBUG_TRACE_LEVEL");
128 trace_level =
129 val ? strtol(val, NULL, 0) : DEFAULT_TRACE_LEVEL;
130 }
131
132 if (trace_level >= loc->level)
133 {
134 va_list ap;
135
136 va_start(ap, fmt); /* make ap point to first arg after 'fmt' */
137
138 #ifdef _Android
139
140 #if 0 // Original for reference
141 #if ( TIMM_OSAL_DEBUG_TRACE_DETAIL > 1 )
142 ALOGD("%s:%d\t%s()\t", simplify_path(loc->file), loc->line,
143 loc->function);
144 #endif
145 #else // Prints function_name for ERROR, WARNING and ENTRY/EXIT
146 if ( (loc->level == TIMM_OSAL_TRACE_LEVEL_ERROR) || (loc->level == TIMM_OSAL_TRACE_LEVEL_WARNING) || (loc->level == TIMM_OSAL_TRACE_LEVEL_ENTERING) )
147 ALOGD("%s:%d\t%s()\t", simplify_path(loc->file), loc->line,
148 loc->function);
149 #endif
150
151 char string[1000];
152 vsprintf(string, fmt, ap);
153 ALOGD("%s",string);
154
155 #else
156
157 #if 0 // Original for reference
158 #if ( TIMM_OSAL_DEBUG_TRACE_DETAIL > 1 )
159 printf("%s:%d\t%s()\t", simplify_path(loc->file), loc->line,
160 loc->function);
161 #endif
162 #else // Prints function_name for ERROR, WARNING and ENTRY/EXIT
163 if ( (loc->level == 1) || (loc->level == 2) || (loc->level == 5) )
164 printf("%s:%d\t%s()\t", simplify_path(loc->file), loc->line,
165 loc->function);
166 #endif
167
168 vprintf(fmt, ap);
169
170 #endif
171
172 va_end(ap);
173 }
174 }
175