1 // Copyright (C) 2019 The Android Open Source Project 2 // Copyright (C) 2019 Google Inc. 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 #pragma once 16 17 // Library to perform tracing. Talks to platform-specific 18 // tracing libraries. 19 namespace android { 20 namespace base { 21 22 class ScopedTrace { 23 public: ScopedTrace(const char * name)24 ScopedTrace(const char* name) : name_(name) { 25 beginTraceImpl(name_); 26 } 27 ~ScopedTrace()28 ~ScopedTrace() { 29 endTraceImpl(name_); 30 } 31 private: 32 void beginTraceImpl(const char* name); 33 void endTraceImpl(const char* name); 34 35 const char* const name_; 36 }; 37 38 } // namespace base 39 } // namespace android 40 41 #define __AEMU_GENSYM2(x,y) x##y 42 #define __AEMU_GENSYM1(x,y) __AEMU_GENSYM2(x,y) 43 #define AEMU_GENSYM(x) __AEMU_GENSYM1(x,__COUNTER__) 44 45 #define AEMU_SCOPED_TRACE(tag) __attribute__ ((unused)) android::base::ScopedTrace AEMU_GENSYM(aemuScopedTrace_)(tag) 46