1 /* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef CHRE_PLATFORM_TRACING_H_ 18 #define CHRE_PLATFORM_TRACING_H_ 19 20 #include <cstdint> 21 22 // Needs to be a number because it's used in STRINGIFY and as a number. 23 #define CHRE_TRACE_STR_BUFFER_SIZE 11 24 // Strings are placed into a buffer in the form: 25 // {<1-byte str len>, str chars...}. 26 // So the max string size is always one less than the total string buffer size. 27 #define CHRE_TRACE_MAX_STRING_SIZE CHRE_TRACE_STR_BUFFER_SIZE - 1 28 29 // TODO(b/301497381): See if netstruct lib would be more useful here 30 // Field values defined by python struct docs: 31 // https://docs.python.org/3/library/struct.html. 32 #define TRACE_BOOL "?" 33 #define TRACE_U8 "B" 34 #define TRACE_U16 "H" 35 #define TRACE_U32 "L" 36 #define TRACE_U64 "Q" 37 #define TRACE_I8 "b" 38 #define TRACE_I16 "h" 39 #define TRACE_I32 "l" 40 #define TRACE_I64 "q" 41 #define TRACE_C "c" 42 #define TRACE_S STRINGIFY(CHRE_TRACE_STR_BUFFER_SIZE) "p" 43 44 // Check to make sure pointer size macro is defined. 45 #ifndef __SIZEOF_POINTER__ 46 #error "__SIZEOF_POINTER__ macro not defined - unsupported toolchain being used" 47 #else 48 static_assert(sizeof(void *) == __SIZEOF_POINTER__, 49 "Size of pointer does not match __SIZEOF_POINTER__ macro"); 50 #endif 51 52 // Check the predefined pointer size to use the most accurate size 53 #if __SIZEOF_POINTER__ == 8 54 #define TRACE_PTR TRACE_U64 55 #elif __SIZEOF_POINTER__ == 4 56 #define TRACE_PTR TRACE_U32 57 #else 58 #error "Pointer size is of unsupported size" 59 #endif // __SIZEOF_POINTER__ == 8 || __SIZEOF_POINTER__ == 4 60 61 #ifdef CHRE_TRACING_ENABLED 62 63 #include "chre/target_platform/tracing.h" 64 65 /** 66 * All tracing macros to be used in CHRE 67 */ 68 #ifndef CHRE_TRACE_INSTANT 69 #error "CHRE_TRACE_INSTANT must be defined by chre/target_platform/tracing.h" 70 #endif 71 72 #ifndef CHRE_TRACE_START 73 #error "CHRE_TRACE_START must be defined by chre/target_platform/tracing.h" 74 #endif 75 76 #ifndef CHRE_TRACE_END 77 #error "CHRE_TRACE_END must be defined by chre/target_platform/tracing.h" 78 #endif 79 80 #ifndef CHRE_TRACE_INSTANT_DATA 81 #error \ 82 "CHRE_TRACE_INSTANT_DATA must be defined by chre/target_platform/tracing.h" 83 #endif 84 85 #ifndef CHRE_TRACE_START_DATA 86 #error "CHRE_TRACE_START_DATA must be defined by chre/target_platform/tracing.h" 87 #endif 88 89 #ifndef CHRE_TRACE_END_DATA 90 #error "CHRE_TRACE_END_DATA must be defined by chre/target_platform/tracing.h" 91 #endif 92 93 #else // CHRE_TRACING_ENABLED 94 95 #include "chre/util/macros.h" 96 chreTraceUnusedParams(...)97inline void chreTraceUnusedParams(...) {} 98 99 #define CHRE_TRACE_INSTANT(...) chreTraceUnusedParams(__VA_ARGS__) 100 #define CHRE_TRACE_START(...) chreTraceUnusedParams(__VA_ARGS__) 101 #define CHRE_TRACE_END(...) chreTraceUnusedParams(__VA_ARGS__) 102 #define CHRE_TRACE_INSTANT_DATA(...) chreTraceUnusedParams(__VA_ARGS__) 103 #define CHRE_TRACE_START_DATA(...) chreTraceUnusedParams(__VA_ARGS__) 104 #define CHRE_TRACE_END_DATA(...) chreTraceUnusedParams(__VA_ARGS__) 105 106 #endif // CHRE_TRACING_ENABLED 107 108 #endif // CHRE_PLATFORM_TRACING_H_ 109