aboutsummaryrefslogtreecommitdiff
path: root/thirdparty/trace/lane_trace.h
blob: 170526eb2cfa0ba727c29e686a6612d29e19bd73 (plain) (blame)
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// Copyright Epic Games, Inc. All Rights Reserved.

#pragma once

#if __has_include(<Containers/StringView.h>)
#	include <Trace/Trace.h>
#	include <Containers/StringView.h>
#	include <ProfilingDebugging/CpuProfilerTrace.h>
#	include <Templates/UnrealTemplate.h>
#else
#	define UE_LANETRACE_ENABLED		2
#	define IOSTOREHTTPCLIENT_API
#endif

////////////////////////////////////////////////////////////////////////////////
#if !defined(UE_LANETRACE_ENABLED)
#	define UE_LANETRACE_ENABLED CPUPROFILERTRACE_ENABLED && !UE_BUILD_SHIPPING
#endif

#if UE_LANETRACE_ENABLED
#	define LANETRACE_OFF_IMPL(...)
#	define UE_API					IOSTOREHTTPCLIENT_API
#else
#	define LANETRACE_OFF_IMPL(...)	{ return __VA_ARGS__ ; }
#	define UE_API					inline
#endif


////////////////////////////////////////////////////////////////////////////////
#if UE_LANETRACE_ENABLED == 2
namespace trace {
#endif

////////////////////////////////////////////////////////////////////////////////
struct FLaneTraceSpec
{
	FAnsiStringView	Name;
	FAnsiStringView	Group = "Lanes";
	const void*		Channel;
	int32			Weight = 100;
};

class				FLaneTrace;
UE_API FLaneTrace*	LaneTrace_New(const FLaneTraceSpec& Spec)			LANETRACE_OFF_IMPL(nullptr);
UE_API void			LaneTrace_Delete(FLaneTrace* Lane)					LANETRACE_OFF_IMPL();
UE_API uint32		LaneTrace_NewScope(const FAnsiStringView& Name)		LANETRACE_OFF_IMPL(1);
UE_API void			LaneTrace_Enter(FLaneTrace* Lane, uint32 ScopeId)	LANETRACE_OFF_IMPL();
UE_API void			LaneTrace_Change(FLaneTrace* Lane, uint32 ScopeId)	LANETRACE_OFF_IMPL();
UE_API void			LaneTrace_Leave(FLaneTrace* Lane)					LANETRACE_OFF_IMPL();
UE_API void			LaneTrace_LeaveAll(FLaneTrace* Lane)				LANETRACE_OFF_IMPL();



////////////////////////////////////////////////////////////////////////////////
struct FLanePostcode
{
			FLanePostcode(const void* In)	: Value(UPTRINT(In)) {}
			FLanePostcode(UPTRINT In)		: Value(In) {}
	UPTRINT Value;
};

class				FLaneEstate;
UE_API FLaneEstate*	LaneEstate_New(const FLaneTraceSpec& Spec)						LANETRACE_OFF_IMPL(nullptr);
UE_API void			LaneEstate_Delete(FLaneEstate* Estate)							LANETRACE_OFF_IMPL();
UE_API FLaneTrace*	LaneEstate_Build(FLaneEstate* Estate, FLanePostcode Postcode)	LANETRACE_OFF_IMPL(nullptr);
UE_API FLaneTrace*	LaneEstate_Lookup(FLaneEstate* Estate, FLanePostcode Postcode)	LANETRACE_OFF_IMPL(nullptr);
UE_API void			LaneEstate_Demolish(FLaneEstate* Estate, FLanePostcode Postcode)LANETRACE_OFF_IMPL();

#undef LANETRACE_OFF_IMPL
#undef UE_API



#if UE_LANETRACE_ENABLED

////////////////////////////////////////////////////////////////////////////////
class FLaneTraceScope
{
public:
						FLaneTraceScope(FLaneTrace* InLane, uint32 Scope);
						FLaneTraceScope() = default;
						~FLaneTraceScope();
						FLaneTraceScope(FLaneTraceScope&& Rhs);
	FLaneTraceScope&	operator = (FLaneTraceScope&& Rhs);
	void				Change(uint32 Scope) const;

private:
						FLaneTraceScope(const FLaneTraceScope&) = delete;
	FLaneTraceScope&	operator = (const FLaneTraceScope&) = delete;
	FLaneTrace*			Lane = nullptr;
};

////////////////////////////////////////////////////////////////////////////////
inline FLaneTraceScope::FLaneTraceScope(FLaneTrace* InLane, uint32 Scope)
: Lane(InLane)
{
	LaneTrace_Enter(Lane, Scope);
}

////////////////////////////////////////////////////////////////////////////////
inline FLaneTraceScope::~FLaneTraceScope()
{
	if (Lane)
	{
		LaneTrace_Leave(Lane);
	}
}

////////////////////////////////////////////////////////////////////////////////
inline FLaneTraceScope::FLaneTraceScope(FLaneTraceScope&& Rhs)
{
	Swap(Rhs.Lane, Lane);
}

////////////////////////////////////////////////////////////////////////////////
inline FLaneTraceScope& FLaneTraceScope::operator = (FLaneTraceScope&& Rhs)
{
	Swap(Rhs.Lane, Lane);
	return *this;
}

////////////////////////////////////////////////////////////////////////////////
inline void FLaneTraceScope::Change(uint32 Scope) const
{
	LaneTrace_Change(Lane, Scope);
}

#else // UE_LANETRACE_ENABLED

class FLaneTraceScope
{
public:
			FLaneTraceScope(...)	{}
	void	Change(uint32) const	{}
};

#endif // UE_LANETRACE_ENABLED

////////////////////////////////////////////////////////////////////////////////
#if UE_LANETRACE_ENABLED == 2
} // namespace trace
#endif

#if defined(TRACE_IMPLEMENT) && TRACE_IMPLEMENT
#	include "lane_trace.inl"
#endif