Home | History | Annotate | Download | only in util
      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_INT(name,val) ({\
     67 if (gKpiDebugLevel >= KPI_ONLY) { \
     68      atrace_int(ATRACE_TAG, name, val); \
     69 }\
     70 })
     71 
     72 
     73 #define ATRACE_BEGIN_SNPRINTF(fmt_str, ...) \
     74  if (gKpiDebugLevel >= KPI_DBG) { \
     75    char trace_tag[CAMERA_TRACE_BUF]; \
     76    snprintf(trace_tag, CAMERA_TRACE_BUF, fmt_str, ##__VA_ARGS__); \
     77    ATRACE_BEGIN(trace_tag); \
     78 }
     79 
     80 #define ATRACE_BEGIN_DBG(name) ({\
     81 if (gKpiDebugLevel >= KPI_DBG) { \
     82      atrace_begin(ATRACE_TAG, name); \
     83 }\
     84 })
     85 
     86 #define ATRACE_END_DBG() ({\
     87 if (gKpiDebugLevel >= KPI_DBG) { \
     88      atrace_end(ATRACE_TAG); \
     89 }\
     90 })
     91 
     92 #define ATRACE_INT_DBG(name,val) ({\
     93 if (gKpiDebugLevel >= KPI_DBG) { \
     94      atrace_int(ATRACE_TAG, name, val); \
     95 }\
     96 })
     97 
     98 #define ATRACE_BEGIN ATRACE_BEGIN_DBG
     99 #define ATRACE_INT ATRACE_INT_DBG
    100 #define ATRACE_END ATRACE_END_DBG
    101 
    102 #define KPI_ATRACE_NAME(name) qcamera::ScopedTraceKpi ___tracer(ATRACE_TAG, name)
    103 #define ATRACE_NAME(name) qcamera::ScopedTraceDbg ___tracer(ATRACE_TAG, name)
    104 #define KPI_ATRACE_CALL() KPI_ATRACE_NAME(__FUNCTION__)
    105 #define ATRACE_CALL() ATRACE_NAME(__FUNCTION__)
    106 
    107 namespace qcamera {
    108 extern volatile uint32_t gKpiDebugLevel;
    109 class ScopedTraceKpi {
    110 public:
    111     inline ScopedTraceKpi(uint64_t tag, const char *name)
    112     : mTag(tag) {
    113         if (gKpiDebugLevel >= KPI_ONLY) {
    114             atrace_begin(mTag,name);
    115         }
    116     }
    117 
    118     inline ~ScopedTraceKpi() {
    119         if (gKpiDebugLevel >= KPI_ONLY) {
    120             atrace_end(mTag);
    121         }
    122     }
    123 
    124     private:
    125         uint64_t mTag;
    126 };
    127 
    128 class ScopedTraceDbg {
    129 public:
    130     inline ScopedTraceDbg(uint64_t tag, const char *name)
    131     : mTag(tag) {
    132         if (gKpiDebugLevel >= KPI_DBG) {
    133             atrace_begin(mTag,name);
    134         }
    135     }
    136 
    137     inline ~ScopedTraceDbg() {
    138         if (gKpiDebugLevel >= KPI_DBG) {
    139             atrace_end(mTag);
    140         }
    141     }
    142 
    143     private:
    144         uint64_t mTag;
    145 };
    146 };
    147 
    148 extern volatile uint32_t gKpiDebugLevel;
    149 
    150 #endif /* __QCAMREATRACE_H__ */
    151