• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "android/base/Tracing.h"
16 
17 #if defined(__ANDROID__) || defined(HOST_BUILD)
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 android {
31 namespace base {
32 
isTracingEnabled()33 bool isTracingEnabled() {
34 #if defined(__ANDROID__) || defined(HOST_BUILD)
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)42 void ScopedTraceGuest::beginTraceImpl(const char* name) {
43 #if defined(__ANDROID__) || defined(HOST_BUILD)
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 #endif
50 }
51 
endTraceImpl(const char * name)52 void ScopedTraceGuest::endTraceImpl(const char* name) {
53 #if defined(__ANDROID__) || defined(HOST_BUILD)
54     atrace_end(TRACE_TAG);
55 #elif defined(__Fuchsia__) && !defined(FUCHSIA_NO_TRACE)
56     TRACE_DURATION_END(TRACE_TAG, name);
57 #else
58     // No-op
59 #endif
60 }
61 
62 } // namespace base
63 } // namespace android
64