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 #include "aemu/base/Tracing.h" 16 17 #if defined(__ANDROID__) 18 19 #include <cutils/trace.h> 20 #define TRACE_TAG ATRACE_TAG_GRAPHICS 21 22 #elif defined(__Fuchsia__) && !defined(FUCHSIA_NO_TRACE) 23 24 #include <lib/trace/event.h> 25 #define TRACE_TAG "gfx" 26 27 #else 28 #endif 29 30 namespace gfxstream { 31 namespace guest { 32 isTracingEnabled()33bool isTracingEnabled() { 34 #if defined(__ANDROID__) 35 return atrace_is_tag_enabled(TRACE_TAG); 36 #else 37 // TODO: Fuchsia + Linux 38 return false; 39 #endif 40 } 41 beginTraceImpl(const char * name)42void ScopedTraceGuest::beginTraceImpl(const char* name) { 43 #if defined(__ANDROID__) 44 atrace_begin(TRACE_TAG, name); 45 #elif defined(__Fuchsia__) && !defined(FUCHSIA_NO_TRACE) 46 TRACE_DURATION_BEGIN(TRACE_TAG, name); 47 #else 48 // No-op 49 (void)name; 50 #endif 51 } 52 endTraceImpl(const char * name)53void ScopedTraceGuest::endTraceImpl(const char* name) { 54 #if defined(__ANDROID__) 55 (void)name; 56 atrace_end(TRACE_TAG); 57 #elif defined(__Fuchsia__) && !defined(FUCHSIA_NO_TRACE) 58 TRACE_DURATION_END(TRACE_TAG, name); 59 #else 60 // No-op 61 (void)name; 62 #endif 63 } 64 65 } // namespace base 66 } // namespace android 67