diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2022-02-09 21:57:32 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-09 21:57:32 +0100 |
commit | d22ac13bc2f29cb9e490f5a7838fcd52805682cf (patch) | |
tree | ce08c3682a09adf8cf4cdde689535cc3f7bf3778 /scene | |
parent | 2c28729122c71e025f9491b3d9905752341530fe (diff) | |
parent | 65837973051e2aea43019fb5c20ec4a1debf0bcb (diff) |
Merge pull request #57715 from Faless/debugger/4.x_core_includes_and_servers
[Debugger] Move most profilers to ServersDebugger, fix core includes.
Diffstat (limited to 'scene')
-rw-r--r-- | scene/debugger/scene_debugger.cpp | 103 | ||||
-rw-r--r-- | scene/debugger/scene_debugger.h | 28 | ||||
-rw-r--r-- | scene/multiplayer/scene_cache_interface.cpp | 8 | ||||
-rw-r--r-- | scene/multiplayer/scene_replication_interface.cpp | 5 | ||||
-rw-r--r-- | scene/multiplayer/scene_rpc_interface.cpp | 9 |
5 files changed, 142 insertions, 11 deletions
diff --git a/scene/debugger/scene_debugger.cpp b/scene/debugger/scene_debugger.cpp index 41340f281b..e5b81f9d8d 100644 --- a/scene/debugger/scene_debugger.cpp +++ b/scene/debugger/scene_debugger.cpp @@ -31,30 +31,121 @@ #include "scene_debugger.h" #include "core/debugger/engine_debugger.h" +#include "core/debugger/engine_profiler.h" #include "core/io/marshalls.h" #include "core/object/script_language.h" #include "scene/main/scene_tree.h" #include "scene/main/window.h" #include "scene/resources/packed_scene.h" -void SceneDebugger::initialize() { +Array SceneDebugger::RPCProfilerFrame::serialize() { + Array arr; + arr.push_back(infos.size() * 4); + for (int i = 0; i < infos.size(); ++i) { + arr.push_back(uint64_t(infos[i].node)); + arr.push_back(infos[i].node_path); + arr.push_back(infos[i].incoming_rpc); + arr.push_back(infos[i].outgoing_rpc); + } + return arr; +} + +bool SceneDebugger::RPCProfilerFrame::deserialize(const Array &p_arr) { + ERR_FAIL_COND_V(p_arr.size() < 1, false); + uint32_t size = p_arr[0]; + ERR_FAIL_COND_V(size % 4, false); + ERR_FAIL_COND_V((uint32_t)p_arr.size() != size + 1, false); + infos.resize(size / 4); + int idx = 1; + for (uint32_t i = 0; i < size / 4; ++i) { + infos.write[i].node = uint64_t(p_arr[idx]); + infos.write[i].node_path = p_arr[idx + 1]; + infos.write[i].incoming_rpc = p_arr[idx + 2]; + infos.write[i].outgoing_rpc = p_arr[idx + 3]; + } + return true; +} + +class SceneDebugger::RPCProfiler : public EngineProfiler { + Map<ObjectID, RPCNodeInfo> rpc_node_data; + uint64_t last_profile_time = 0; + + void init_node(const ObjectID p_node) { + if (rpc_node_data.has(p_node)) { + return; + } + rpc_node_data.insert(p_node, RPCNodeInfo()); + rpc_node_data[p_node].node = p_node; + rpc_node_data[p_node].node_path = Object::cast_to<Node>(ObjectDB::get_instance(p_node))->get_path(); + rpc_node_data[p_node].incoming_rpc = 0; + rpc_node_data[p_node].outgoing_rpc = 0; + } + +public: + void toggle(bool p_enable, const Array &p_opts) { + rpc_node_data.clear(); + } + + void add(const Array &p_data) { + ERR_FAIL_COND(p_data.size() < 2); + const ObjectID id = p_data[0]; + const String what = p_data[1]; + init_node(id); + RPCNodeInfo &info = rpc_node_data[id]; + if (what == "rpc_in") { + info.incoming_rpc++; + } else if (what == "rpc_out") { + info.outgoing_rpc++; + } + } + + void tick(double p_frame_time, double p_idle_time, double p_physics_time, double p_physics_frame_time) { + uint64_t pt = OS::get_singleton()->get_ticks_msec(); + if (pt - last_profile_time > 100) { + last_profile_time = pt; + RPCProfilerFrame frame; + for (const KeyValue<ObjectID, RPCNodeInfo> &E : rpc_node_data) { + frame.infos.push_back(E.value); + } + rpc_node_data.clear(); + EngineDebugger::get_singleton()->send_message("multiplayer:rpc", frame.serialize()); + } + } +}; + +SceneDebugger *SceneDebugger::singleton = nullptr; + +SceneDebugger::SceneDebugger() { + singleton = this; + rpc_profiler.instantiate(); + rpc_profiler->bind("rpc"); #ifdef DEBUG_ENABLED LiveEditor::singleton = memnew(LiveEditor); EngineDebugger::register_message_capture("scene", EngineDebugger::Capture(nullptr, SceneDebugger::parse_message)); #endif } -void SceneDebugger::deinitialize() { +SceneDebugger::~SceneDebugger() { #ifdef DEBUG_ENABLED if (LiveEditor::singleton) { - // Should be removed automatically when deiniting debugger, but just in case - if (EngineDebugger::has_capture("scene")) { - EngineDebugger::unregister_message_capture("scene"); - } + EngineDebugger::unregister_message_capture("scene"); memdelete(LiveEditor::singleton); LiveEditor::singleton = nullptr; } #endif + singleton = nullptr; +} + +void SceneDebugger::initialize() { + if (EngineDebugger::is_active()) { + memnew(SceneDebugger); + } +} + +void SceneDebugger::deinitialize() { + if (singleton) { + memdelete(singleton); + } } #ifdef DEBUG_ENABLED diff --git a/scene/debugger/scene_debugger.h b/scene/debugger/scene_debugger.h index c8298391bb..dd0a17c2dc 100644 --- a/scene/debugger/scene_debugger.h +++ b/scene/debugger/scene_debugger.h @@ -32,6 +32,7 @@ #define SCENE_DEBUGGER_H #include "core/object/class_db.h" +#include "core/object/ref_counted.h" #include "core/string/ustring.h" #include "core/templates/pair.h" #include "core/variant/array.h" @@ -41,9 +42,36 @@ class Node; class SceneDebugger { public: + // RPC profiler + struct RPCNodeInfo { + ObjectID node; + String node_path; + int incoming_rpc = 0; + int outgoing_rpc = 0; + }; + + struct RPCProfilerFrame { + Vector<RPCNodeInfo> infos; + + Array serialize(); + bool deserialize(const Array &p_arr); + }; + +private: + class RPCProfiler; + + static SceneDebugger *singleton; + + Ref<RPCProfiler> rpc_profiler; + + SceneDebugger(); + +public: static void initialize(); static void deinitialize(); + ~SceneDebugger(); + #ifdef DEBUG_ENABLED private: static void _save_node(ObjectID id, const String &p_path); diff --git a/scene/multiplayer/scene_cache_interface.cpp b/scene/multiplayer/scene_cache_interface.cpp index de4a94470a..2f278ed864 100644 --- a/scene/multiplayer/scene_cache_interface.cpp +++ b/scene/multiplayer/scene_cache_interface.cpp @@ -107,6 +107,10 @@ void SceneCacheInterface::process_simplify_path(int p_from, const uint8_t *p_pac Ref<MultiplayerPeer> multiplayer_peer = multiplayer->get_multiplayer_peer(); ERR_FAIL_COND(multiplayer_peer.is_null()); +#ifdef DEBUG_ENABLED + multiplayer->profile_bandwidth("out", packet.size()); +#endif + multiplayer_peer->set_transfer_channel(0); multiplayer_peer->set_transfer_mode(Multiplayer::TRANSFER_MODE_RELIABLE); multiplayer_peer->set_target_peer(p_from); @@ -188,6 +192,10 @@ bool SceneCacheInterface::_send_confirm_path(Node *p_node, NodePath p_path, Path Ref<MultiplayerPeer> multiplayer_peer = multiplayer->get_multiplayer_peer(); ERR_FAIL_COND_V(multiplayer_peer.is_null(), false); +#ifdef DEBUG_ENABLED + multiplayer->profile_bandwidth("out", packet.size() * peers_to_add.size()); +#endif + for (int &E : peers_to_add) { multiplayer_peer->set_target_peer(E); // To all of you. multiplayer_peer->set_transfer_channel(0); diff --git a/scene/multiplayer/scene_replication_interface.cpp b/scene/multiplayer/scene_replication_interface.cpp index 2088a43ba7..25a704b37e 100644 --- a/scene/multiplayer/scene_replication_interface.cpp +++ b/scene/multiplayer/scene_replication_interface.cpp @@ -147,6 +147,11 @@ Error SceneReplicationInterface::_send_raw(const uint8_t *p_buffer, int p_size, ERR_FAIL_COND_V(!p_buffer || p_size < 1, ERR_INVALID_PARAMETER); ERR_FAIL_COND_V(!multiplayer, ERR_UNCONFIGURED); ERR_FAIL_COND_V(!multiplayer->has_multiplayer_peer(), ERR_UNCONFIGURED); + +#ifdef DEBUG_ENABLED + multiplayer->profile_bandwidth("out", p_size); +#endif + Ref<MultiplayerPeer> peer = multiplayer->get_multiplayer_peer(); peer->set_target_peer(p_peer); peer->set_transfer_channel(0); diff --git a/scene/multiplayer/scene_rpc_interface.cpp b/scene/multiplayer/scene_rpc_interface.cpp index 7d7f57b9a1..0cb703227b 100644 --- a/scene/multiplayer/scene_rpc_interface.cpp +++ b/scene/multiplayer/scene_rpc_interface.cpp @@ -46,12 +46,11 @@ void SceneRPCInterface::make_default() { #ifdef DEBUG_ENABLED _FORCE_INLINE_ void SceneRPCInterface::_profile_node_data(const String &p_what, ObjectID p_id) { - if (EngineDebugger::is_profiling("multiplayer")) { + if (EngineDebugger::is_profiling("rpc")) { Array values; - values.push_back("node"); values.push_back(p_id); values.push_back(p_what); - EngineDebugger::profiler_add_frame_data("multiplayer", values); + EngineDebugger::profiler_add_frame_data("rpc", values); } } #else @@ -268,7 +267,7 @@ void SceneRPCInterface::_process_rpc(Node *p_node, const uint16_t p_rpc_method_i argp.resize(argc); #ifdef DEBUG_ENABLED - _profile_node_data("in_rpc", p_node->get_instance_id()); + _profile_node_data("rpc_in", p_node->get_instance_id()); #endif int out; @@ -471,7 +470,7 @@ void SceneRPCInterface::rpcp(Object *p_obj, int p_peer_id, const StringName &p_m if (p_peer_id != node_id) { #ifdef DEBUG_ENABLED - _profile_node_data("out_rpc", node->get_instance_id()); + _profile_node_data("rpc_out", node->get_instance_id()); #endif _send_rpc(node, p_peer_id, rpc_id, config, p_method, p_arg, p_argcount); |