Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/main/performance.h
9898 views
1
/**************************************************************************/
2
/* performance.h */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#pragma once
32
33
#include "core/object/class_db.h"
34
#include "core/templates/hash_map.h"
35
36
#define PERF_WARN_OFFLINE_FUNCTION
37
#define PERF_WARN_PROCESS_SYNC
38
39
template <typename T>
40
class TypedArray;
41
42
class Performance : public Object {
43
GDCLASS(Performance, Object);
44
45
static Performance *singleton;
46
static void _bind_methods();
47
48
int _get_node_count() const;
49
50
double _process_time;
51
double _physics_process_time;
52
double _navigation_process_time;
53
54
class MonitorCall {
55
Callable _callable;
56
Vector<Variant> _arguments;
57
58
public:
59
MonitorCall(Callable p_callable, Vector<Variant> p_arguments);
60
MonitorCall();
61
Variant call(bool &r_error, String &r_error_message);
62
};
63
64
HashMap<StringName, MonitorCall> _monitor_map;
65
uint64_t _monitor_modification_time;
66
67
public:
68
enum Monitor {
69
TIME_FPS,
70
TIME_PROCESS,
71
TIME_PHYSICS_PROCESS,
72
TIME_NAVIGATION_PROCESS,
73
MEMORY_STATIC,
74
MEMORY_STATIC_MAX,
75
MEMORY_MESSAGE_BUFFER_MAX,
76
OBJECT_COUNT,
77
OBJECT_RESOURCE_COUNT,
78
OBJECT_NODE_COUNT,
79
OBJECT_ORPHAN_NODE_COUNT,
80
RENDER_TOTAL_OBJECTS_IN_FRAME,
81
RENDER_TOTAL_PRIMITIVES_IN_FRAME,
82
RENDER_TOTAL_DRAW_CALLS_IN_FRAME,
83
RENDER_VIDEO_MEM_USED,
84
RENDER_TEXTURE_MEM_USED,
85
RENDER_BUFFER_MEM_USED,
86
PHYSICS_2D_ACTIVE_OBJECTS,
87
PHYSICS_2D_COLLISION_PAIRS,
88
PHYSICS_2D_ISLAND_COUNT,
89
PHYSICS_3D_ACTIVE_OBJECTS,
90
PHYSICS_3D_COLLISION_PAIRS,
91
PHYSICS_3D_ISLAND_COUNT,
92
AUDIO_OUTPUT_LATENCY,
93
NAVIGATION_ACTIVE_MAPS,
94
NAVIGATION_REGION_COUNT,
95
NAVIGATION_AGENT_COUNT,
96
NAVIGATION_LINK_COUNT,
97
NAVIGATION_POLYGON_COUNT,
98
NAVIGATION_EDGE_COUNT,
99
NAVIGATION_EDGE_MERGE_COUNT,
100
NAVIGATION_EDGE_CONNECTION_COUNT,
101
NAVIGATION_EDGE_FREE_COUNT,
102
NAVIGATION_OBSTACLE_COUNT,
103
PIPELINE_COMPILATIONS_CANVAS,
104
PIPELINE_COMPILATIONS_MESH,
105
PIPELINE_COMPILATIONS_SURFACE,
106
PIPELINE_COMPILATIONS_DRAW,
107
PIPELINE_COMPILATIONS_SPECIALIZATION,
108
NAVIGATION_2D_ACTIVE_MAPS,
109
NAVIGATION_2D_REGION_COUNT,
110
NAVIGATION_2D_AGENT_COUNT,
111
NAVIGATION_2D_LINK_COUNT,
112
NAVIGATION_2D_POLYGON_COUNT,
113
NAVIGATION_2D_EDGE_COUNT,
114
NAVIGATION_2D_EDGE_MERGE_COUNT,
115
NAVIGATION_2D_EDGE_CONNECTION_COUNT,
116
NAVIGATION_2D_EDGE_FREE_COUNT,
117
NAVIGATION_2D_OBSTACLE_COUNT,
118
NAVIGATION_3D_ACTIVE_MAPS,
119
NAVIGATION_3D_REGION_COUNT,
120
NAVIGATION_3D_AGENT_COUNT,
121
NAVIGATION_3D_LINK_COUNT,
122
NAVIGATION_3D_POLYGON_COUNT,
123
NAVIGATION_3D_EDGE_COUNT,
124
NAVIGATION_3D_EDGE_MERGE_COUNT,
125
NAVIGATION_3D_EDGE_CONNECTION_COUNT,
126
NAVIGATION_3D_EDGE_FREE_COUNT,
127
NAVIGATION_3D_OBSTACLE_COUNT,
128
MONITOR_MAX
129
};
130
131
enum MonitorType {
132
MONITOR_TYPE_QUANTITY,
133
MONITOR_TYPE_MEMORY,
134
MONITOR_TYPE_TIME
135
};
136
137
double get_monitor(Monitor p_monitor) const;
138
String get_monitor_name(Monitor p_monitor) const;
139
140
MonitorType get_monitor_type(Monitor p_monitor) const;
141
142
void set_process_time(double p_pt);
143
void set_physics_process_time(double p_pt);
144
void set_navigation_process_time(double p_pt);
145
146
void add_custom_monitor(const StringName &p_id, const Callable &p_callable, const Vector<Variant> &p_args);
147
void remove_custom_monitor(const StringName &p_id);
148
bool has_custom_monitor(const StringName &p_id);
149
Variant get_custom_monitor(const StringName &p_id);
150
TypedArray<StringName> get_custom_monitor_names();
151
152
uint64_t get_monitor_modification_time();
153
154
static Performance *get_singleton() { return singleton; }
155
156
Performance();
157
};
158
159
VARIANT_ENUM_CAST(Performance::Monitor);
160
161