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 #pragma once 18 19 #include <stdint.h> 20 21 #if __has_include(<cutils/trace.h>) 22 #include <cutils/trace.h> 23 #endif 24 25 #include <binder/Common.h> 26 27 #ifdef ATRACE_TAG_AIDL 28 #if ATRACE_TAG_AIDL != (1 << 24) 29 #error "Mismatched ATRACE_TAG_AIDL definitions" 30 #endif 31 #else 32 #define ATRACE_TAG_AIDL (1 << 24) 33 #endif 34 35 namespace android { 36 namespace binder { 37 38 // Forward declarations from internal OS.h 39 namespace os { 40 // Trampoline functions allowing generated aidls to trace binder transactions without depending on 41 // libcutils/libutils 42 void trace_begin(uint64_t tag, const char* name); 43 void trace_end(uint64_t tag); 44 void trace_int(uint64_t tag, const char* name, int32_t value); 45 } // namespace os 46 47 class LIBBINDER_EXPORTED ScopedTrace { 48 public: ScopedTrace(uint64_t tag,const char * name)49 inline ScopedTrace(uint64_t tag, const char* name) : mTag(tag) { os::trace_begin(mTag, name); } 50 ~ScopedTrace()51 inline ~ScopedTrace() { os::trace_end(mTag); } 52 53 private: 54 uint64_t mTag; 55 }; 56 57 } // namespace binder 58 } // namespace android 59