File: tracing.h

package info (click to toggle)
freespace2 24.2.0%2Brepack-1
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid
  • size: 43,716 kB
  • sloc: cpp: 595,001; ansic: 21,741; python: 1,174; sh: 457; makefile: 248; xml: 181
file content (162 lines) | stat: -rw-r--r-- 3,216 bytes parent folder | download | duplicates (2)
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#ifndef _TRACING_H
#define _TRACING_H
#pragma once

#include "globalincs/pstypes.h"
#include "tracing/categories.h"
#include "tracing/scopes.h"

/**
 * @defgroup tracing The Tracing API
 *
 * The tracing system provides functions for gathering tracing data of engine events.
 */

/** @file
 *  @ingroup tracing
 */

namespace tracing {

/**
 * @brief Process id used for GPU events
 */
const std::int64_t GPU_PID = std::numeric_limits<std::int64_t>::min();

/**
 * @brief Possible types of events
 */
enum class EventType {
	Invalid,

	Complete, Begin, End,

	AsyncBegin, AsyncStep, AsyncEnd,

	Counter
};

/**
 * @brief Data of a trace event
 */
struct trace_event {
	const Category* category = nullptr;
	const Scope* scope = nullptr;
	EventType type = EventType::Invalid;

	std::uint64_t timestamp = 0;
	std::uint64_t duration = 0;

	std::uint64_t event_id = 0;
	std::uint64_t end_event_id = 0;

	std::int64_t tid = -1;
	std::int64_t pid = -1;

	float value = -1.f;
};

/**
 * @brief Initializes the tracing subsystem
 */
void init();

/**
 * @brief Should be called regularly to process GPU events
 */
void process_events();

void frame_profile_process_frame();

/**
 * @brief Gets the output of the frame profiler.
 * @return The frame profiler output
 */
SCP_string get_frame_profile_output();

/**
 * @brief Deinitializes the tracing subsystem
 */
void shutdown();

namespace complete {
/**
 * @brief Starts a complete event
 * @param category The category this event belongs to
 * @param evt The event which hold the data
 */
void start(const Category& category, trace_event* evt);

/**
 * @brief Ends and submits a complete event
 *
 * @warning Must be called from the same thread as the start function
 *
 * @param evt The event to submit
 */
void end(trace_event* evt);

/**
 * @brief Class for tracing a scope with a complete event
 */
class ScopedCompleteEvent {
	trace_event _evt;

 public:
	explicit ScopedCompleteEvent(const Category& category) {
		start(category, &_evt);
	}
	~ScopedCompleteEvent() {
		end(&_evt);
	}
};
}

namespace async {
/**
 * @brief Begins an asynchronous event
 *
 * @note Events can be submitted from multiple threads
 *
 * @param category The category of the event
 * @param async_scope The scope of the event
 */
void begin(const Category& category, const Scope& async_scope);

/**
 * @brief Steps an asynchronous event
 *
 * @note Events can be submitted from multiple threads
 *
 * @param category The category of the event
 * @param async_scope The scope of the event
 */
void step(const Category& category, const Scope& async_scope);

/**
 * @brief Ends an asynchronous event
 *
 * @note Events can be submitted from multiple threads
 *
 * @param category The category of the event
 * @param async_scope The scope of the event
 */
void end(const Category& category, const Scope& async_scope);
}

namespace counter {

/**
 * @brief Records the new value of a counter event
 * @param category The event category
 * @param value The new value of the category
 */
void value(const Category& category, float value);

}

}

#define TRACE_SCOPE(category) ::tracing::complete::ScopedCompleteEvent SCP_TOKEN_CONCAT(complete_trace_scope, __LINE__)(category)

#endif //_TRACING_H