1 /*
2  * Copyright (c) 2015-2016, The Linux Foundation. All rights reserved.
3  * Not a Contribution.
4  *
5  * Copyright (C) 2012 The Android Open Source Project
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 
20 #ifndef __QCAMERATRACE_H__
21 #define __QCAMERATRACE_H__
22 
23 #include <utils/Trace.h>
24 
25 #ifdef QCAMERA_REDEFINE_LOG
26 #define CAM_MODULE CAM_HAL_MODULE
27 extern "C" {
28 #include "mm_camera_dbg.h"
29 }
30 #endif
31 
32 #undef ATRACE_CALL
33 #undef ATRACE_NAME
34 #undef ATRACE_BEGIN
35 #undef ATRACE_INT
36 #undef ATRACE_END
37 #undef ATRACE_BEGIN_SNPRINTF
38 #undef KPI_ATRACE_BEGIN
39 #undef KPI_ATRACE_END
40 #undef KPI_ATRACE_INT
41 #undef ATRACE_TAG
42 #undef ATRACE_BEGIN_DBG
43 #undef ATRACE_INT_DBG
44 #undef ATRACE_END_DBG
45 
46 #define KPI_ONLY 1
47 #define KPI_DBG 2
48 
49 #define CAMERA_TRACE_BUF 32
50 
51 #define ATRACE_TAG ATRACE_TAG_CAMERA
52 
53 //to enable only KPI logs
54 #define KPI_ATRACE_BEGIN(name) ({\
55 if (gKpiDebugLevel >= KPI_ONLY) { \
56      atrace_begin(ATRACE_TAG, name); \
57 }\
58 })
59 
60 #define KPI_ATRACE_END() ({\
61 if (gKpiDebugLevel >= KPI_ONLY) { \
62      atrace_end(ATRACE_TAG); \
63 }\
64 })
65 
66 #define KPI_ATRACE_ASYNC_BEGIN(name, cookie) ({\
67 if (gKpiDebugLevel >= KPI_ONLY) { \
68      ATRACE_ASYNC_BEGIN(name, cookie); \
69 }\
70 })
71 
72 #define KPI_ATRACE_ASYNC_END(name, cookie) ({\
73 if (gKpiDebugLevel >= KPI_ONLY) { \
74      ATRACE_ASYNC_END(name, cookie); \
75 }\
76 })
77 
78 #define KPI_ATRACE_INT(name,val) ({\
79 if (gKpiDebugLevel >= KPI_ONLY) { \
80      atrace_int(ATRACE_TAG, name, val); \
81 }\
82 })
83 
84 
85 #define ATRACE_BEGIN_SNPRINTF(fmt_str, ...) \
86  if (gKpiDebugLevel >= KPI_DBG) { \
87    char trace_tag[CAMERA_TRACE_BUF]; \
88    snprintf(trace_tag, CAMERA_TRACE_BUF, fmt_str, ##__VA_ARGS__); \
89    ATRACE_BEGIN(trace_tag); \
90 }
91 
92 #define ATRACE_BEGIN_DBG(name) ({\
93 if (gKpiDebugLevel >= KPI_DBG) { \
94      atrace_begin(ATRACE_TAG, name); \
95 }\
96 })
97 
98 #define ATRACE_END_DBG() ({\
99 if (gKpiDebugLevel >= KPI_DBG) { \
100      atrace_end(ATRACE_TAG); \
101 }\
102 })
103 
104 #define ATRACE_INT_DBG(name,val) ({\
105 if (gKpiDebugLevel >= KPI_DBG) { \
106      atrace_int(ATRACE_TAG, name, val); \
107 }\
108 })
109 
110 #define ATRACE_BEGIN ATRACE_BEGIN_DBG
111 #define ATRACE_INT ATRACE_INT_DBG
112 #define ATRACE_END ATRACE_END_DBG
113 
114 #define KPI_ATRACE_NAME(name) qcamera::ScopedTraceKpi ___tracer(ATRACE_TAG, name)
115 #define ATRACE_NAME(name) qcamera::ScopedTraceDbg ___tracer(ATRACE_TAG, name)
116 #define KPI_ATRACE_CALL() KPI_ATRACE_NAME(__FUNCTION__)
117 #define ATRACE_CALL() ATRACE_NAME(__FUNCTION__)
118 
119 namespace qcamera {
120 extern volatile uint32_t gKpiDebugLevel;
121 class ScopedTraceKpi {
122 public:
ScopedTraceKpi(uint64_t tag,const char * name)123     inline ScopedTraceKpi(uint64_t tag, const char *name)
124     : mTag(tag) {
125         if (gKpiDebugLevel >= KPI_ONLY) {
126             atrace_begin(mTag,name);
127         }
128     }
129 
~ScopedTraceKpi()130     inline ~ScopedTraceKpi() {
131         if (gKpiDebugLevel >= KPI_ONLY) {
132             atrace_end(mTag);
133         }
134     }
135 
136     private:
137         uint64_t mTag;
138 };
139 
140 class ScopedTraceDbg {
141 public:
ScopedTraceDbg(uint64_t tag,const char * name)142     inline ScopedTraceDbg(uint64_t tag, const char *name)
143     : mTag(tag) {
144         if (gKpiDebugLevel >= KPI_DBG) {
145             atrace_begin(mTag,name);
146         }
147     }
148 
~ScopedTraceDbg()149     inline ~ScopedTraceDbg() {
150         if (gKpiDebugLevel >= KPI_DBG) {
151             atrace_end(mTag);
152         }
153     }
154 
155     private:
156         uint64_t mTag;
157 };
158 };
159 
160 extern volatile uint32_t gKpiDebugLevel;
161 
162 #endif /* __QCAMREATRACE_H__ */
163