Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/servers/debugger/servers_debugger.h
10278 views
1
/**************************************************************************/
2
/* servers_debugger.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 "servers/rendering_server.h"
34
35
class ServersDebugger {
36
public:
37
// Memory usage
38
struct ResourceInfo {
39
String path;
40
String format;
41
String type;
42
RID id;
43
int vram = 0;
44
bool operator<(const ResourceInfo &p_img) const { return vram == p_img.vram ? id < p_img.id : vram > p_img.vram; }
45
};
46
47
struct ResourceUsage {
48
List<ResourceInfo> infos;
49
50
Array serialize();
51
bool deserialize(const Array &p_arr);
52
};
53
54
// Script Profiler
55
struct ScriptFunctionSignature {
56
StringName name;
57
int id = -1;
58
59
Array serialize();
60
bool deserialize(const Array &p_arr);
61
};
62
63
struct ScriptFunctionInfo {
64
StringName name;
65
int sig_id = -1;
66
int call_count = 0;
67
double self_time = 0;
68
double total_time = 0;
69
double internal_time = 0;
70
};
71
72
// Servers profiler
73
struct ServerFunctionInfo {
74
StringName name;
75
double time = 0;
76
};
77
78
struct ServerInfo {
79
StringName name;
80
List<ServerFunctionInfo> functions;
81
};
82
83
struct ServersProfilerFrame {
84
int frame_number = 0;
85
double frame_time = 0;
86
double process_time = 0;
87
double physics_time = 0;
88
double physics_frame_time = 0;
89
double script_time = 0;
90
List<ServerInfo> servers;
91
Vector<ScriptFunctionInfo> script_functions;
92
93
Array serialize();
94
bool deserialize(const Array &p_arr);
95
};
96
97
// Visual Profiler
98
struct VisualProfilerFrame {
99
uint64_t frame_number = 0;
100
Vector<RS::FrameProfileArea> areas;
101
102
Array serialize();
103
bool deserialize(const Array &p_arr);
104
};
105
106
private:
107
class ScriptsProfiler;
108
class ServersProfiler;
109
class VisualProfiler;
110
111
double last_draw_time = 0.0;
112
Ref<ServersProfiler> servers_profiler;
113
Ref<VisualProfiler> visual_profiler;
114
115
static ServersDebugger *singleton;
116
117
static Error _capture(void *p_user, const String &p_cmd, const Array &p_data, bool &r_captured);
118
119
void _send_resource_usage();
120
String _get_resource_type_from_path(const String &p_path);
121
122
ServersDebugger();
123
124
public:
125
static void initialize();
126
static void deinitialize();
127
128
~ServersDebugger();
129
};
130
131