• 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 #pragma once
16 
17 #include <inttypes.h>
18 
19 // Library to perform tracing. Talks to platform-specific
20 // tracing libraries.
21 namespace android {
22 namespace base {
23 
24 // New tracing API that talks to an underlying tracing library, possibly perfetto.
25 //
26 // Sets up global state useful for tracing.
27 void initializeTracing();
28 
29 // Enable/disable tracing
30 void enableTracing();
31 void disableTracing();
32 
33 // Set the time of traces on the host to be at this guest time.
34 // Not needed if we assume timestamps can be transferrable (e.g.,
35 // when RDTSC with raw passthrough is used)
36 void setGuestTime(uint64_t guestTime);
37 
38 // Record a counter of some kind.
39 void traceCounter(const char* tag, int64_t value);
40 
41 void beginTrace(const char* name);
42 void endTrace();
43 
44 class ScopedTrace {
45 public:
46     ScopedTrace(const char* name);
47     ~ScopedTrace();
48 };
49 
50 class ScopedTraceDerived : public ScopedTrace {
51 public:
52     void* member = nullptr;
53 };
54 
55 void setGuestTime(uint64_t t);
56 
57 void enableTracing();
58 void disableTracing();
59 
60 bool shouldEnableTracing();
61 
62 void traceCounter(const char* name, int64_t value);
63 
64 } // namespace base
65 } // namespace android
66 
67 #define __AEMU_GENSYM2(x,y) x##y
68 #define __AEMU_GENSYM1(x,y) __AEMU_GENSYM2(x,y)
69 #define AEMU_GENSYM(x) __AEMU_GENSYM1(x,__COUNTER__)
70 
71 #define AEMU_SCOPED_TRACE(tag) __attribute__ ((unused)) android::base::ScopedTrace AEMU_GENSYM(aemuScopedTrace_)(tag)
72 #define AEMU_SCOPED_TRACE_CALL() AEMU_SCOPED_TRACE(__func__)
73 #define AEMU_SCOPED_THRESHOLD_TRACE_CALL()
74 #define AEMU_SCOPED_THRESHOLD_TRACE(...)
75