Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/debugger/editor_profiler.h
9903 views
1
/**************************************************************************/
2
/* editor_profiler.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 "scene/gui/box_container.h"
34
#include "scene/gui/button.h"
35
#include "scene/gui/check_button.h"
36
#include "scene/gui/label.h"
37
#include "scene/gui/option_button.h"
38
#include "scene/gui/spin_box.h"
39
#include "scene/gui/split_container.h"
40
#include "scene/gui/texture_rect.h"
41
#include "scene/gui/tree.h"
42
43
class ImageTexture;
44
45
class EditorProfiler : public VBoxContainer {
46
GDCLASS(EditorProfiler, VBoxContainer);
47
48
public:
49
struct Metric {
50
bool valid = false;
51
52
int frame_number = 0;
53
float frame_time = 0;
54
float process_time = 0;
55
float physics_time = 0;
56
float physics_frame_time = 0;
57
58
struct Category {
59
StringName signature;
60
String name;
61
float total_time = 0; //total for category
62
63
struct Item {
64
StringName signature;
65
String name;
66
String script;
67
int line = 0;
68
float self = 0;
69
float total = 0;
70
float internal = 0;
71
int calls = 0;
72
};
73
74
Vector<Item> items;
75
};
76
77
Vector<Category> categories;
78
79
HashMap<StringName, Category *> category_ptrs;
80
HashMap<StringName, Category::Item *> item_ptrs;
81
};
82
83
enum DisplayMode {
84
DISPLAY_FRAME_TIME,
85
DISPLAY_AVERAGE_TIME,
86
DISPLAY_FRAME_PERCENT,
87
DISPLAY_PHYSICS_FRAME_PERCENT,
88
};
89
90
enum DisplayTime {
91
DISPLAY_TOTAL_TIME,
92
DISPLAY_SELF_TIME,
93
};
94
95
private:
96
struct ThemeCache {
97
Color seek_line_color;
98
Color seek_line_hover_color;
99
} theme_cache;
100
101
Button *activate = nullptr;
102
Button *clear_button = nullptr;
103
TextureRect *graph = nullptr;
104
Ref<ImageTexture> graph_texture;
105
Vector<uint8_t> graph_image;
106
107
float graph_zoom = 0.0f;
108
float pan_accumulator = 0.0f;
109
int zoom_center = -1;
110
111
Tree *variables = nullptr;
112
HSplitContainer *h_split = nullptr;
113
114
HashSet<StringName> plot_sigs;
115
116
OptionButton *display_mode = nullptr;
117
OptionButton *display_time = nullptr;
118
119
CheckButton *display_internal_profiles = nullptr;
120
121
SpinBox *cursor_metric_edit = nullptr;
122
123
Vector<Metric> frame_metrics;
124
int total_metrics = 0;
125
int last_metric = -1;
126
127
int max_functions = 0;
128
129
bool updating_frame = false;
130
131
int hover_metric = -1;
132
133
float graph_height = 1.0f;
134
135
bool seeking = false;
136
137
Timer *frame_delay = nullptr;
138
Timer *plot_delay = nullptr;
139
140
void _update_button_text();
141
void _update_frame();
142
143
void _activate_pressed();
144
void _clear_pressed();
145
void _autostart_toggled(bool p_toggled_on);
146
147
void _internal_profiles_pressed();
148
149
String _get_time_as_text(const Metric &m, float p_time, int p_calls);
150
151
void _make_metric_ptrs(Metric &m);
152
void _item_edited();
153
154
void _update_plot();
155
156
void _graph_tex_mouse_exit();
157
158
void _graph_tex_draw();
159
void _graph_tex_input(const Ref<InputEvent> &p_ev);
160
161
Color _get_color_from_signature(const StringName &p_signature) const;
162
int _get_zoom_left_border() const;
163
164
void _cursor_metric_changed(double);
165
166
void _combo_changed(int);
167
168
Metric _get_frame_metric(int index);
169
170
protected:
171
void _notification(int p_what);
172
static void _bind_methods();
173
174
public:
175
void add_frame_metric(const Metric &p_metric, bool p_final = false);
176
void set_enabled(bool p_enable, bool p_clear = true);
177
void set_profiling(bool p_pressed);
178
bool is_profiling();
179
bool is_seeking() { return seeking; }
180
void disable_seeking();
181
182
void clear();
183
184
Vector<Vector<String>> get_data_as_csv() const;
185
186
EditorProfiler();
187
};
188
189