summaryrefslogtreecommitdiff
path: root/base/Tracing.h
blob: 93557d06e465d8529d433b7b806fe0967b1d3d53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright (C) 2019 The Android Open Source Project
// Copyright (C) 2019 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once

#include <inttypes.h>

// Library to perform tracing. Talks to platform-specific
// tracing libraries.
namespace android {
namespace base {

// New tracing API that talks to an underlying tracing library, possibly perfetto.
//
// Sets up global state useful for tracing.
void initializeTracing();

// Enable/disable tracing
void enableTracing();
void disableTracing();

// Set the time of traces on the host to be at this guest time.
// Not needed if we assume timestamps can be transferrable (e.g.,
// when RDTSC with raw passthrough is used)
void setGuestTime(uint64_t guestTime);

// Record a counter of some kind.
void traceCounter(const char* tag, int64_t value);

void beginTrace(const char* name);
void endTrace();

class ScopedTrace {
public:
    ScopedTrace(const char* name);
    ~ScopedTrace();
};

class ScopedTraceDerived : public ScopedTrace {
public:
    void* member = nullptr;
};

void setGuestTime(uint64_t t);

void enableTracing();
void disableTracing();

bool shouldEnableTracing();

void traceCounter(const char* name, int64_t value);

} // namespace base
} // namespace android

#define __AEMU_GENSYM2(x,y) x##y
#define __AEMU_GENSYM1(x,y) __AEMU_GENSYM2(x,y)
#define AEMU_GENSYM(x) __AEMU_GENSYM1(x,__COUNTER__)

#define AEMU_SCOPED_TRACE(tag) __attribute__ ((unused)) android::base::ScopedTrace AEMU_GENSYM(aemuScopedTrace_)(tag)
#define AEMU_SCOPED_TRACE_CALL() AEMU_SCOPED_TRACE(__func__)
#define AEMU_SCOPED_THRESHOLD_TRACE_CALL()
#define AEMU_SCOPED_THRESHOLD_TRACE(...)