You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-07 12:30:27 +00:00
Add network profiler
This commit is contained in:
@@ -764,6 +764,14 @@ void ScriptDebuggerRemote::_poll_events() {
|
||||
profiling = false;
|
||||
_send_profiling_data(false);
|
||||
print_line("PROFILING END!");
|
||||
} else if (command == "start_network_profiling") {
|
||||
|
||||
multiplayer->profiling_start();
|
||||
profiling_network = true;
|
||||
} else if (command == "stop_network_profiling") {
|
||||
|
||||
multiplayer->profiling_end();
|
||||
profiling_network = false;
|
||||
} else if (command == "reload_scripts") {
|
||||
reload_all_scripts = true;
|
||||
} else if (command == "breakpoint") {
|
||||
@@ -911,6 +919,18 @@ void ScriptDebuggerRemote::idle_poll() {
|
||||
}
|
||||
}
|
||||
|
||||
if (profiling_network) {
|
||||
uint64_t pt = OS::get_singleton()->get_ticks_msec();
|
||||
if (pt - last_net_bandwidth_time > 200) {
|
||||
last_net_bandwidth_time = pt;
|
||||
_send_network_bandwidth_usage();
|
||||
}
|
||||
if (pt - last_net_prof_time > 100) {
|
||||
last_net_prof_time = pt;
|
||||
_send_network_profiling_data();
|
||||
}
|
||||
}
|
||||
|
||||
if (reload_all_scripts) {
|
||||
|
||||
for (int i = 0; i < ScriptServer::get_language_count(); i++) {
|
||||
@@ -922,6 +942,35 @@ void ScriptDebuggerRemote::idle_poll() {
|
||||
_poll_events();
|
||||
}
|
||||
|
||||
void ScriptDebuggerRemote::_send_network_profiling_data() {
|
||||
ERR_FAIL_COND(multiplayer.is_null());
|
||||
|
||||
int n_nodes = multiplayer->get_profiling_frame(&network_profile_info.write[0]);
|
||||
|
||||
packet_peer_stream->put_var("network_profile");
|
||||
packet_peer_stream->put_var(n_nodes * 6);
|
||||
for (int i = 0; i < n_nodes; ++i) {
|
||||
packet_peer_stream->put_var(network_profile_info[i].node);
|
||||
packet_peer_stream->put_var(network_profile_info[i].node_path);
|
||||
packet_peer_stream->put_var(network_profile_info[i].incoming_rpc);
|
||||
packet_peer_stream->put_var(network_profile_info[i].incoming_rset);
|
||||
packet_peer_stream->put_var(network_profile_info[i].outgoing_rpc);
|
||||
packet_peer_stream->put_var(network_profile_info[i].outgoing_rset);
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptDebuggerRemote::_send_network_bandwidth_usage() {
|
||||
ERR_FAIL_COND(multiplayer.is_null());
|
||||
|
||||
int incoming_bandwidth = multiplayer->get_incoming_bandwidth_usage();
|
||||
int outgoing_bandwidth = multiplayer->get_outgoing_bandwidth_usage();
|
||||
|
||||
packet_peer_stream->put_var("network_bandwidth");
|
||||
packet_peer_stream->put_var(2);
|
||||
packet_peer_stream->put_var(incoming_bandwidth);
|
||||
packet_peer_stream->put_var(outgoing_bandwidth);
|
||||
}
|
||||
|
||||
void ScriptDebuggerRemote::send_message(const String &p_message, const Array &p_args) {
|
||||
|
||||
mutex->lock();
|
||||
@@ -1061,6 +1110,10 @@ void ScriptDebuggerRemote::set_live_edit_funcs(LiveEditFuncs *p_funcs) {
|
||||
live_edit_funcs = p_funcs;
|
||||
}
|
||||
|
||||
void ScriptDebuggerRemote::set_multiplayer(Ref<MultiplayerAPI> p_multiplayer) {
|
||||
multiplayer = p_multiplayer;
|
||||
}
|
||||
|
||||
bool ScriptDebuggerRemote::is_profiling() const {
|
||||
|
||||
return profiling;
|
||||
@@ -1106,12 +1159,15 @@ ScriptDebuggerRemote::ResourceUsageFunc ScriptDebuggerRemote::resource_usage_fun
|
||||
|
||||
ScriptDebuggerRemote::ScriptDebuggerRemote() :
|
||||
profiling(false),
|
||||
profiling_network(false),
|
||||
max_frame_functions(16),
|
||||
skip_profile_frame(false),
|
||||
reload_all_scripts(false),
|
||||
tcp_client(Ref<StreamPeerTCP>(memnew(StreamPeerTCP))),
|
||||
packet_peer_stream(Ref<PacketPeerStream>(memnew(PacketPeerStream))),
|
||||
last_perf_time(0),
|
||||
last_net_prof_time(0),
|
||||
last_net_bandwidth_time(0),
|
||||
performance(Engine::get_singleton()->get_singleton_object("Performance")),
|
||||
requested_quit(false),
|
||||
mutex(Mutex::create()),
|
||||
@@ -1143,6 +1199,7 @@ ScriptDebuggerRemote::ScriptDebuggerRemote() :
|
||||
add_error_handler(&eh);
|
||||
|
||||
profile_info.resize(GLOBAL_GET("debug/settings/profiler/max_functions"));
|
||||
network_profile_info.resize(GLOBAL_GET("debug/settings/profiler/max_functions"));
|
||||
profile_info_ptrs.resize(profile_info.size());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user