diff options
author | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2020-03-08 12:21:08 +0100 |
---|---|---|
committer | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2020-03-08 12:36:39 +0100 |
commit | 3b47eb51e4025fae6dd63eb405dee54c49281a5f (patch) | |
tree | 41800eaf051ae2bed5cb58c29cd3b01443081d16 /editor | |
parent | b8ddaf9c33107e01928e04ed462aa08d4017247b (diff) |
Update editor debugger to new remote debugger.
Shared RemoteDebuggerPeer code between client and server.
Move editor profilers inside editor/debugger folder.
Diffstat (limited to 'editor')
-rw-r--r-- | editor/debugger/editor_debugger_inspector.cpp | 4 | ||||
-rw-r--r-- | editor/debugger/editor_debugger_node.cpp | 1 | ||||
-rw-r--r-- | editor/debugger/editor_debugger_server.cpp | 138 | ||||
-rw-r--r-- | editor/debugger/editor_debugger_server.h | 16 | ||||
-rw-r--r-- | editor/debugger/editor_network_profiler.cpp (renamed from editor/editor_network_profiler.cpp) | 8 | ||||
-rw-r--r-- | editor/debugger/editor_network_profiler.h (renamed from editor/editor_network_profiler.h) | 5 | ||||
-rw-r--r-- | editor/debugger/editor_profiler.cpp (renamed from editor/editor_profiler.cpp) | 4 | ||||
-rw-r--r-- | editor/debugger/editor_profiler.h (renamed from editor/editor_profiler.h) | 0 | ||||
-rw-r--r-- | editor/debugger/editor_visual_profiler.cpp (renamed from editor/editor_visual_profiler.cpp) | 4 | ||||
-rw-r--r-- | editor/debugger/editor_visual_profiler.h (renamed from editor/editor_visual_profiler.h) | 0 | ||||
-rw-r--r-- | editor/debugger/script_editor_debugger.cpp | 248 | ||||
-rw-r--r-- | editor/debugger/script_editor_debugger.h | 15 |
12 files changed, 142 insertions, 301 deletions
diff --git a/editor/debugger/editor_debugger_inspector.cpp b/editor/debugger/editor_debugger_inspector.cpp index 1506d64b63..9587daf93e 100644 --- a/editor/debugger/editor_debugger_inspector.cpp +++ b/editor/debugger/editor_debugger_inspector.cpp @@ -30,8 +30,8 @@ #include "editor_debugger_inspector.h" +#include "core/debugger/debugger_marshalls.h" #include "core/io/marshalls.h" -#include "core/script_debugger_remote.h" #include "editor/editor_node.h" #include "scene/debugger/scene_debugger.h" @@ -226,7 +226,7 @@ Object *EditorDebuggerInspector::get_object(ObjectID p_id) { void EditorDebuggerInspector::add_stack_variable(const Array &p_array) { - ScriptDebuggerRemote::ScriptStackVariable var; + DebuggerMarshalls::ScriptStackVariable var; var.deserialize(p_array); String n = var.name; Variant v = var.value; diff --git a/editor/debugger/editor_debugger_node.cpp b/editor/debugger/editor_debugger_node.cpp index 825883cffe..f4a8102b79 100644 --- a/editor/debugger/editor_debugger_node.cpp +++ b/editor/debugger/editor_debugger_node.cpp @@ -240,6 +240,7 @@ void EditorDebuggerNode::_notification(int p_what) { stop(); return; } + server->poll(); // Errors and warnings int error_count = 0; diff --git a/editor/debugger/editor_debugger_server.cpp b/editor/debugger/editor_debugger_server.cpp index bde0921ced..c80988a662 100644 --- a/editor/debugger/editor_debugger_server.cpp +++ b/editor/debugger/editor_debugger_server.cpp @@ -30,7 +30,7 @@ #include "editor_debugger_server.h" -#include "core/io/packet_peer.h" +#include "core/io/marshalls.h" #include "core/io/tcp_server.h" #include "core/os/mutex.h" #include "core/os/thread.h" @@ -38,114 +38,18 @@ #include "editor/editor_node.h" #include "editor/editor_settings.h" -class EditorDebuggerPeerTCP : public EditorDebuggerPeer { - -private: - enum { - QUEUE_MAX = 2048, - POLL_USEC_MAX = 100, - }; - Ref<StreamPeerTCP> tcp; - Ref<PacketPeerStream> packet_peer; - List<Array> out_queue; - List<Array> in_queue; - Mutex mutex; - bool connected = false; - -public: - Error poll() { - MutexLock lock(mutex); - connected = tcp->get_status() == StreamPeerTCP::STATUS_CONNECTED; - Error err = OK; - uint64_t ticks = OS::get_singleton()->get_ticks_usec(); - while (connected && packet_peer->get_available_packet_count() > 0 && in_queue.size() < QUEUE_MAX && OS::get_singleton()->get_ticks_usec() - ticks < POLL_USEC_MAX) { - Variant var; - err = packet_peer->get_var(var); - connected = tcp->get_status() == StreamPeerTCP::STATUS_CONNECTED; - if (err != OK) { - ERR_PRINT("Error reading variant from peer"); - break; - } - ERR_CONTINUE_MSG(var.get_type() != Variant::ARRAY, "Malformed packet received, not an Array."); - in_queue.push_back(var); - } - ticks = OS::get_singleton()->get_ticks_usec(); - while (connected && out_queue.size() > 0 && OS::get_singleton()->get_ticks_usec() - ticks < POLL_USEC_MAX) { - Array arr = out_queue[0]; - out_queue.pop_front(); - packet_peer->put_var(arr); - connected = tcp->get_status() == StreamPeerTCP::STATUS_CONNECTED; - } - return err; - } - - bool has_message() { - return in_queue.size() > 0; - } - - Array get_message() { - MutexLock lock(mutex); - ERR_FAIL_COND_V(!has_message(), Array()); - Array out = in_queue[0]; - in_queue.pop_front(); - return out; - } - - Error put_message(const Array p_arr) { - MutexLock lock(mutex); - if (out_queue.size() > QUEUE_MAX) { - return ERR_OUT_OF_MEMORY; - } - out_queue.push_back(p_arr); - return OK; - } - - int get_max_message_size() const { - return 8 << 20; // 8 MiB - } - - bool is_peer_connected() { - return connected; - } - - void close() { - MutexLock lock(mutex); - connected = false; - tcp->disconnect_from_host(); - } - - EditorDebuggerPeerTCP(Ref<StreamPeerTCP> p_stream) { - packet_peer.instance(); - tcp = p_stream; - if (tcp.is_null()) { - tcp.instance(); // Bug? - } - packet_peer->set_stream_peer(tcp); - } - - ~EditorDebuggerPeerTCP() { - close(); - packet_peer->set_stream_peer(Ref<StreamPeer>()); - } -}; - class EditorDebuggerServerTCP : public EditorDebuggerServer { private: Ref<TCP_Server> server; - List<Ref<EditorDebuggerPeer> > peers; - Thread *thread = NULL; - Mutex mutex; - bool running = false; - - static void _poll_func(void *p_ud); public: + virtual void poll() {} virtual Error start(); virtual void stop(); virtual bool is_active() const; virtual bool is_connection_available() const; - virtual Ref<EditorDebuggerPeer> take_connection(); + virtual Ref<RemoteDebuggerPeer> take_connection(); EditorDebuggerServerTCP(); }; @@ -161,19 +65,11 @@ Error EditorDebuggerServerTCP::start() { EditorNode::get_log()->add_message(String("Error listening on port ") + itos(remote_port), EditorLog::MSG_TYPE_ERROR); return err; } - running = true; - thread = Thread::create(_poll_func, this); return err; } void EditorDebuggerServerTCP::stop() { server->stop(); - if (thread != NULL) { - running = false; - Thread::wait_to_finish(thread); - memdelete(thread); - thread = NULL; - } } bool EditorDebuggerServerTCP::is_active() const { @@ -184,31 +80,9 @@ bool EditorDebuggerServerTCP::is_connection_available() const { return server->is_listening() && server->is_connection_available(); } -Ref<EditorDebuggerPeer> EditorDebuggerServerTCP::take_connection() { - ERR_FAIL_COND_V(!is_connection_available(), Ref<EditorDebuggerPeer>()); - MutexLock lock(mutex); - Ref<EditorDebuggerPeerTCP> peer = memnew(EditorDebuggerPeerTCP(server->take_connection())); - peers.push_back(peer); - return peer; -} - -void EditorDebuggerServerTCP::_poll_func(void *p_ud) { - EditorDebuggerServerTCP *me = (EditorDebuggerServerTCP *)p_ud; - while (me->running) { - me->mutex.lock(); - List<Ref<EditorDebuggerPeer> > remove; - for (int i = 0; i < me->peers.size(); i++) { - Ref<EditorDebuggerPeer> peer = me->peers[i]; - Error err = ((EditorDebuggerPeerTCP *)peer.ptr())->poll(); - if (err != OK || !peer->is_peer_connected()) - remove.push_back(peer); - } - for (List<Ref<EditorDebuggerPeer> >::Element *E = remove.front(); E; E = E->next()) { - me->peers.erase(E->get()); - } - me->mutex.unlock(); - OS::get_singleton()->delay_usec(50); - } +Ref<RemoteDebuggerPeer> EditorDebuggerServerTCP::take_connection() { + ERR_FAIL_COND_V(!is_connection_available(), Ref<RemoteDebuggerPeer>()); + return memnew(RemoteDebuggerPeerTCP(server->take_connection())); } EditorDebuggerServer *EditorDebuggerServer::create_default() { diff --git a/editor/debugger/editor_debugger_server.h b/editor/debugger/editor_debugger_server.h index 4594a8decf..e9798c90b3 100644 --- a/editor/debugger/editor_debugger_server.h +++ b/editor/debugger/editor_debugger_server.h @@ -31,29 +31,19 @@ #ifndef EDITOR_DEBUGGER_CONNECTION_H #define EDITOR_DEBUGGER_CONNECTION_H +#include "core/debugger/remote_debugger_peer.h" #include "core/reference.h" -class EditorDebuggerPeer : public Reference { - -public: - virtual bool has_message() = 0; - virtual Array get_message() = 0; - virtual Error put_message(const Array p_arr) = 0; - - virtual int get_max_message_size() const = 0; - virtual bool is_peer_connected() = 0; - virtual void close() = 0; -}; - class EditorDebuggerServer : public Reference { public: static EditorDebuggerServer *create_default(); + virtual void poll() = 0; virtual Error start() = 0; virtual void stop() = 0; virtual bool is_active() const = 0; virtual bool is_connection_available() const = 0; - virtual Ref<EditorDebuggerPeer> take_connection() = 0; + virtual Ref<RemoteDebuggerPeer> take_connection() = 0; }; #endif // EDITOR_DEBUGGER_CONNECTION_H diff --git a/editor/editor_network_profiler.cpp b/editor/debugger/editor_network_profiler.cpp index a9ef21bb87..21ef66d1aa 100644 --- a/editor/editor_network_profiler.cpp +++ b/editor/debugger/editor_network_profiler.cpp @@ -31,8 +31,8 @@ #include "editor_network_profiler.h" #include "core/os/os.h" -#include "editor_scale.h" -#include "editor_settings.h" +#include "editor/editor_scale.h" +#include "editor/editor_settings.h" void EditorNetworkProfiler::_bind_methods() { ADD_SIGNAL(MethodInfo("enable_profiling", PropertyInfo(Variant::BOOL, "enable"))); @@ -58,7 +58,7 @@ void EditorNetworkProfiler::_update_frame() { TreeItem *root = counters_display->create_item(); - for (Map<ObjectID, MultiplayerAPI::ProfilingInfo>::Element *E = nodes_data.front(); E; E = E->next()) { + for (Map<ObjectID, DebuggerMarshalls::MultiplayerNodeInfo>::Element *E = nodes_data.front(); E; E = E->next()) { TreeItem *node = counters_display->create_item(root); @@ -95,7 +95,7 @@ void EditorNetworkProfiler::_clear_pressed() { } } -void EditorNetworkProfiler::add_node_frame_data(const MultiplayerAPI::ProfilingInfo p_frame) { +void EditorNetworkProfiler::add_node_frame_data(const DebuggerMarshalls::MultiplayerNodeInfo p_frame) { if (!nodes_data.has(p_frame.node)) { nodes_data.insert(p_frame.node, p_frame); diff --git a/editor/editor_network_profiler.h b/editor/debugger/editor_network_profiler.h index 680131c288..f532dc5dd0 100644 --- a/editor/editor_network_profiler.h +++ b/editor/debugger/editor_network_profiler.h @@ -31,6 +31,7 @@ #ifndef EDITORNETWORKPROFILER_H #define EDITORNETWORKPROFILER_H +#include "core/debugger/debugger_marshalls.h" #include "scene/gui/box_container.h" #include "scene/gui/button.h" #include "scene/gui/label.h" @@ -50,7 +51,7 @@ private: Timer *frame_delay; - Map<ObjectID, MultiplayerAPI::ProfilingInfo> nodes_data; + Map<ObjectID, DebuggerMarshalls::MultiplayerNodeInfo> nodes_data; void _update_frame(); @@ -62,7 +63,7 @@ protected: static void _bind_methods(); public: - void add_node_frame_data(const MultiplayerAPI::ProfilingInfo p_frame); + void add_node_frame_data(const DebuggerMarshalls::MultiplayerNodeInfo p_frame); void set_bandwidth(int p_incoming, int p_outgoing); bool is_profiling(); diff --git a/editor/editor_profiler.cpp b/editor/debugger/editor_profiler.cpp index 64b633e656..2f3ad210b2 100644 --- a/editor/editor_profiler.cpp +++ b/editor/debugger/editor_profiler.cpp @@ -31,8 +31,8 @@ #include "editor_profiler.h" #include "core/os/os.h" -#include "editor_scale.h" -#include "editor_settings.h" +#include "editor/editor_scale.h" +#include "editor/editor_settings.h" void EditorProfiler::_make_metric_ptrs(Metric &m) { diff --git a/editor/editor_profiler.h b/editor/debugger/editor_profiler.h index 0a442ddd5c..0a442ddd5c 100644 --- a/editor/editor_profiler.h +++ b/editor/debugger/editor_profiler.h diff --git a/editor/editor_visual_profiler.cpp b/editor/debugger/editor_visual_profiler.cpp index e9638148e2..52aa418922 100644 --- a/editor/editor_visual_profiler.cpp +++ b/editor/debugger/editor_visual_profiler.cpp @@ -31,8 +31,8 @@ #include "editor_visual_profiler.h" #include "core/os/os.h" -#include "editor_scale.h" -#include "editor_settings.h" +#include "editor/editor_scale.h" +#include "editor/editor_settings.h" void EditorVisualProfiler::add_frame_metric(const Metric &p_metric) { diff --git a/editor/editor_visual_profiler.h b/editor/debugger/editor_visual_profiler.h index 5194c08b96..5194c08b96 100644 --- a/editor/editor_visual_profiler.h +++ b/editor/debugger/editor_visual_profiler.h diff --git a/editor/debugger/script_editor_debugger.cpp b/editor/debugger/script_editor_debugger.cpp index 299f504f1e..920f4d858a 100644 --- a/editor/debugger/script_editor_debugger.cpp +++ b/editor/debugger/script_editor_debugger.cpp @@ -30,17 +30,17 @@ #include "script_editor_debugger.h" +#include "core/debugger/debugger_marshalls.h" #include "core/io/marshalls.h" #include "core/project_settings.h" -#include "core/script_debugger_remote.h" #include "core/ustring.h" +#include "editor/debugger/editor_network_profiler.h" +#include "editor/debugger/editor_profiler.h" +#include "editor/debugger/editor_visual_profiler.h" #include "editor/editor_log.h" -#include "editor/editor_network_profiler.h" #include "editor/editor_node.h" -#include "editor/editor_profiler.h" #include "editor/editor_scale.h" #include "editor/editor_settings.h" -#include "editor/editor_visual_profiler.h" #include "editor/plugins/canvas_item_editor_plugin.h" #include "editor/plugins/spatial_editor_plugin.h" #include "editor/property_editor.h" @@ -144,7 +144,7 @@ void ScriptEditorDebugger::save_node(ObjectID p_id, const String &p_file) { Array msg; msg.push_back(p_id); msg.push_back(p_file); - _put_msg("save_node", msg); + _put_msg("scene:save_node", msg); } void ScriptEditorDebugger::_file_selected(const String &p_file) { @@ -186,7 +186,7 @@ void ScriptEditorDebugger::_file_selected(const String &p_file) { void ScriptEditorDebugger::request_remote_tree() { - _put_msg("request_scene_tree", Array()); + _put_msg("scene:request_scene_tree", Array()); } const SceneDebuggerTree *ScriptEditorDebugger::get_remote_tree() { @@ -199,7 +199,7 @@ void ScriptEditorDebugger::update_remote_object(ObjectID p_obj_id, const String msg.push_back(p_obj_id); msg.push_back(p_prop); msg.push_back(p_value); - _put_msg("set_object_property", msg); + _put_msg("scene:set_object_property", msg); } void ScriptEditorDebugger::request_remote_object(ObjectID p_obj_id) { @@ -207,7 +207,7 @@ void ScriptEditorDebugger::request_remote_object(ObjectID p_obj_id) { ERR_FAIL_COND(p_obj_id.is_null()); Array msg; msg.push_back(p_obj_id); - _put_msg("inspect_object", msg); + _put_msg("scene:inspect_object", msg); } Object *ScriptEditorDebugger::get_remote_object(ObjectID p_id) { @@ -229,7 +229,7 @@ void ScriptEditorDebugger::_remote_object_property_updated(ObjectID p_id, const void ScriptEditorDebugger::_video_mem_request() { - _put_msg("request_video_mem", Array()); + _put_msg("core:memory", Array()); } Size2 ScriptEditorDebugger::get_minimum_size() const { @@ -270,36 +270,36 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da emit_signal("breaked", false, false); profiler->set_enabled(true); profiler->disable_seeking(); - } else if (p_msg == "message:set_pid") { + } else if (p_msg == "set_pid") { ERR_FAIL_COND(p_data.size() < 1); remote_pid = p_data[0]; - } else if (p_msg == "message:click_ctrl") { + } else if (p_msg == "scene:click_ctrl") { ERR_FAIL_COND(p_data.size() < 2); clicked_ctrl->set_text(p_data[0]); clicked_ctrl_type->set_text(p_data[1]); - } else if (p_msg == "message:scene_tree") { + } else if (p_msg == "scene:scene_tree") { scene_tree->nodes.clear(); scene_tree->deserialize(p_data); emit_signal("remote_tree_updated"); _update_buttons_state(); - } else if (p_msg == "message:inspect_object") { + } else if (p_msg == "scene:inspect_object") { ObjectID id = inspector->add_object(p_data); if (id.is_valid()) emit_signal("remote_object_updated", id); - } else if (p_msg == "message:video_mem") { + } else if (p_msg == "memory:usage") { vmem_tree->clear(); TreeItem *root = vmem_tree->create_item(); - ScriptDebuggerRemote::ResourceUsage usage; + DebuggerMarshalls::ResourceUsage usage; usage.deserialize(p_data); int total = 0; - for (List<ScriptDebuggerRemote::ResourceInfo>::Element *E = usage.infos.front(); E; E = E->next()) { + for (List<DebuggerMarshalls::ResourceInfo>::Element *E = usage.infos.front(); E; E = E->next()) { TreeItem *it = vmem_tree->create_item(root); String type = E->get().type; @@ -319,7 +319,7 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da } else if (p_msg == "stack_dump") { - ScriptDebuggerRemote::ScriptStackDump stack; + DebuggerMarshalls::ScriptStackDump stack; stack.deserialize(p_data); stack_dump->clear(); @@ -352,10 +352,10 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da } else if (p_msg == "output") { ERR_FAIL_COND(p_data.size() < 1); - String t = p_data[0]; - EditorNode::get_log()->add_message(t); - - } else if (p_msg == "performance") { + ERR_FAIL_COND(p_data[0].get_type() != Variant::PACKED_STRING_ARRAY); + Vector<String> strings = p_data[0]; + EditorNode::get_log()->add_message(String("\n").join(strings)); + } else if (p_msg == "performance:profile_frame") { Vector<float> p; p.resize(p_data.size()); for (int i = 0; i < p_data.size(); i++) { @@ -388,36 +388,28 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da perf_history.push_front(p); perf_draw->update(); - } else if (p_msg == "visual_profile") { - // TODO check me. - uint64_t frame = p_data[0]; - Vector<String> names = p_data[1]; - Vector<real_t> values = p_data[2]; + } else if (p_msg == "visual:profile_frame") { + DebuggerMarshalls::VisualProfilerFrame frame; + frame.deserialize(p_data); EditorVisualProfiler::Metric metric; - metric.areas.resize(names.size()); - metric.frame_number = frame; + metric.areas.resize(frame.areas.size()); + metric.frame_number = frame.frame_number; metric.valid = true; { EditorVisualProfiler::Metric::Area *areas_ptr = metric.areas.ptrw(); - int metric_count = names.size(); - - const String *rs = names.ptr(); - const real_t *rr = values.ptr(); - - for (int i = 0; i < metric_count; i++) { - - areas_ptr[i].name = rs[i]; - areas_ptr[i].cpu_time = rr[i * 2 + 0]; - areas_ptr[i].gpu_time = rr[i * 2 + 1]; + for (int i = 0; i < frame.areas.size(); i++) { + areas_ptr[i].name = frame.areas[i].name; + areas_ptr[i].cpu_time = frame.areas[i].cpu_msec; + areas_ptr[i].gpu_time = frame.areas[i].gpu_msec; } } visual_profiler->add_frame_metric(metric); } else if (p_msg == "error") { - ScriptDebuggerRemote::OutputError oe; + DebuggerMarshalls::OutputError oe; ERR_FAIL_COND_MSG(oe.deserialize(p_data) == false, "Failed to deserialize error message"); // Format time. @@ -523,15 +515,15 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da else error_count++; - } else if (p_msg == "profile_sig") { + } else if (p_msg == "servers:function_signature") { // Cache a profiler signature. - ScriptDebuggerRemote::ProfilerSignature sig; + DebuggerMarshalls::ScriptFunctionSignature sig; sig.deserialize(p_data); profiler_signature[sig.id] = sig.name; - } else if (p_msg == "profile_frame" || p_msg == "profile_total") { + } else if (p_msg == "servers:profile_frame" || p_msg == "servers:profile_total") { EditorProfiler::Metric metric; - ScriptDebuggerRemote::ProfilerFrame frame; + DebuggerMarshalls::ServersProfilerFrame frame; frame.deserialize(p_data); metric.valid = true; metric.frame_number = frame.frame_number; @@ -539,10 +531,8 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da metric.idle_time = frame.idle_time; metric.physics_time = frame.physics_time; metric.physics_frame_time = frame.physics_frame_time; - int frame_data_amount = frame.frames_data.size(); - int frame_function_amount = frame.frame_functions.size(); - if (frame_data_amount) { + if (frame.servers.size()) { EditorProfiler::Metric::Category frame_time; frame_time.signature = "category_frame_time"; frame_time.name = "Frame Time"; @@ -576,42 +566,42 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da metric.categories.push_back(frame_time); } - for (int i = 0; i < frame_data_amount; i++) { + for (int i = 0; i < frame.servers.size(); i++) { + const DebuggerMarshalls::ServerInfo &srv = frame.servers[i]; EditorProfiler::Metric::Category c; - String name = frame.frames_data[i].name; - Array values = frame.frames_data[i].data; + const String name = srv.name; c.name = name.capitalize(); - c.items.resize(values.size() / 2); + c.items.resize(srv.functions.size()); c.total_time = 0; c.signature = "categ::" + name; - for (int j = 0; j < values.size(); j += 2) { + for (int j = 0; j < srv.functions.size(); j++) { EditorProfiler::Metric::Category::Item item; item.calls = 1; item.line = 0; - item.name = values[j]; - item.self = values[j + 1]; + item.name = srv.functions[j].name; + item.self = srv.functions[j].time; item.total = item.self; item.signature = "categ::" + name + "::" + item.name; item.name = item.name.capitalize(); c.total_time += item.total; - c.items.write[j / 2] = item; + c.items.write[j] = item; } metric.categories.push_back(c); } EditorProfiler::Metric::Category funcs; funcs.total_time = frame.script_time; - funcs.items.resize(frame_function_amount); + funcs.items.resize(frame.script_functions.size()); funcs.name = "Script Functions"; funcs.signature = "script_functions"; - for (int i = 0; i < frame_function_amount; i++) { + for (int i = 0; i < frame.script_functions.size(); i++) { - int signature = frame.frame_functions[i].sig_id; - int calls = frame.frame_functions[i].call_count; - float total = frame.frame_functions[i].total_time; - float self = frame.frame_functions[i].self_time; + int signature = frame.script_functions[i].sig_id; + int calls = frame.script_functions[i].call_count; + float total = frame.script_functions[i].total_time; + float self = frame.script_functions[i].self_time; EditorProfiler::Metric::Category::Item item; if (profiler_signature.has(signature)) { @@ -642,24 +632,28 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da metric.categories.push_back(funcs); - if (p_msg == "profile_frame") + if (p_msg == "servers:profile_frame") profiler->add_frame_metric(metric, false); else profiler->add_frame_metric(metric, true); - } else if (p_msg == "network_profile") { - ScriptDebuggerRemote::NetworkProfilerFrame frame; + } else if (p_msg == "network:profile_frame") { + DebuggerMarshalls::NetworkProfilerFrame frame; frame.deserialize(p_data); for (int i = 0; i < frame.infos.size(); i++) { network_profiler->add_node_frame_data(frame.infos[i]); } - } else if (p_msg == "network_bandwidth") { + + } else if (p_msg == "network:bandwidth") { ERR_FAIL_COND(p_data.size() < 2); network_profiler->set_bandwidth(p_data[0], p_data[1]); - } else if (p_msg == "kill_me") { + } else if (p_msg == "request_quit") { emit_signal("stop_requested"); _stop_and_notify(); + + } else { + WARN_PRINT("unknown message " + p_msg); } } @@ -792,7 +786,7 @@ void ScriptEditorDebugger::_notification(int p_what) { Array msg; msg.push_back(transform); - _put_msg("override_camera_2D:transform", msg); + _put_msg("scene:override_camera_2D:transform", msg); } else if (camera_override >= CameraOverride::OVERRIDE_3D_1) { int viewport_idx = camera_override - CameraOverride::OVERRIDE_3D_1; @@ -810,7 +804,7 @@ void ScriptEditorDebugger::_notification(int p_what) { } msg.push_back(cam->get_znear()); msg.push_back(cam->get_zfar()); - _put_msg("override_camera_3D:transform", msg); + _put_msg("scene:override_camera_3D:transform", msg); } } @@ -863,13 +857,14 @@ void ScriptEditorDebugger::_clear_execution() { inspector->clear_stack_variables(); } -void ScriptEditorDebugger::start(Ref<EditorDebuggerPeer> p_peer) { +void ScriptEditorDebugger::start(Ref<RemoteDebuggerPeer> p_peer) { error_count = 0; warning_count = 0; stop(); peer = p_peer; + ERR_FAIL_COND(p_peer.is_null()); perf_history.clear(); for (int i = 0; i < Performance::MONITOR_MAX; i++) { @@ -885,14 +880,6 @@ void ScriptEditorDebugger::start(Ref<EditorDebuggerPeer> p_peer) { tabs->set_current_tab(0); _set_reason_text(TTR("Debug session started."), MESSAGE_SUCCESS); _update_buttons_state(); - - if (profiler->is_profiling()) { - _profiler_activate(true); - } - - if (network_profiler->is_profiling()) { - _network_profiler_activate(true); - } } void ScriptEditorDebugger::_update_buttons_state() { @@ -939,46 +926,31 @@ void ScriptEditorDebugger::stop() { _update_buttons_state(); } -void ScriptEditorDebugger::_profiler_activate(bool p_enable) { - - if (p_enable) { - profiler_signature.clear(); - Array msg; - int max_funcs = EditorSettings::get_singleton()->get("debugger/profiler_frame_max_functions"); - max_funcs = CLAMP(max_funcs, 16, 512); - msg.push_back(max_funcs); - _put_msg("start_profiling", msg); - print_verbose("Starting profiling."); - - } else { - _put_msg("stop_profiling", Array()); - print_verbose("Ending profiling."); - } -} - -void ScriptEditorDebugger::_visual_profiler_activate(bool p_enable) { - - if (p_enable) { - profiler_signature.clear(); - _put_msg("start_visual_profiling", Array()); - print_verbose("Starting visual profiling."); - - } else { - _put_msg("stop_visual_profiling", Array()); - print_verbose("Ending visual profiling."); - } -} - -void ScriptEditorDebugger::_network_profiler_activate(bool p_enable) { +void ScriptEditorDebugger::_profiler_activate(bool p_enable, int p_type) { - if (p_enable) { - profiler_signature.clear(); - _put_msg("start_network_profiling", Array()); - print_verbose("Starting network profiling."); - - } else { - _put_msg("stop_network_profiling", Array()); - print_verbose("Ending network profiling."); + Array data; + data.push_back(p_enable); + switch (p_type) { + case PROFILER_NETWORK: + _put_msg("profiler:network", data); + break; + case PROFILER_VISUAL: + _put_msg("profiler:visual", data); + break; + case PROFILER_SCRIPTS_SERVERS: + if (p_enable) { + // Clear old script signatures. (should we move all this into the profiler?) + profiler_signature.clear(); + // Add max funcs options to request. + Array opts; + int max_funcs = EditorSettings::get_singleton()->get("debugger/profiler_frame_max_functions"); + opts.push_back(CLAMP(max_funcs, 16, 512)); + data.push_back(opts); + } + _put_msg("profiler:servers", data); + break; + default: + ERR_FAIL_MSG("Invalid profiler type"); } } @@ -1029,7 +1001,7 @@ int ScriptEditorDebugger::_get_node_path_cache(const NodePath &p_path) { Array msg; msg.push_back(p_path); msg.push_back(last_path_id); - _put_msg("live_node_path", msg); + _put_msg("scene:live_node_path", msg); return last_path_id; } @@ -1047,7 +1019,7 @@ int ScriptEditorDebugger::_get_res_path_cache(const String &p_path) { Array msg; msg.push_back(p_path); msg.push_back(last_path_id); - _put_msg("live_res_path", msg); + _put_msg("scene:live_res_path", msg); return last_path_id; } @@ -1079,7 +1051,7 @@ void ScriptEditorDebugger::_method_changed(Object *p_base, const StringName &p_n //no pointers, sorry msg.push_back(*argptr[i]); } - _put_msg("live_node_call", msg); + _put_msg("scene:live_node_call", msg); return; } @@ -1098,7 +1070,7 @@ void ScriptEditorDebugger::_method_changed(Object *p_base, const StringName &p_n //no pointers, sorry msg.push_back(*argptr[i]); } - _put_msg("live_res_call", msg); + _put_msg("scene:live_res_call", msg); return; } @@ -1124,7 +1096,7 @@ void ScriptEditorDebugger::_property_changed(Object *p_base, const StringName &p msg.push_back(pathid); msg.push_back(p_property); msg.push_back(res->get_path()); - _put_msg("live_node_prop_res", msg); + _put_msg("scene:live_node_prop_res", msg); } } else { @@ -1132,7 +1104,7 @@ void ScriptEditorDebugger::_property_changed(Object *p_base, const StringName &p msg.push_back(pathid); msg.push_back(p_property); msg.push_back(p_value); - _put_msg("live_node_prop", msg); + _put_msg("scene:live_node_prop", msg); } return; @@ -1153,7 +1125,7 @@ void ScriptEditorDebugger::_property_changed(Object *p_base, const StringName &p msg.push_back(pathid); msg.push_back(p_property); msg.push_back(res2->get_path()); - _put_msg("live_res_prop_res", msg); + _put_msg("scene:live_res_prop_res", msg); } } else { @@ -1161,7 +1133,7 @@ void ScriptEditorDebugger::_property_changed(Object *p_base, const StringName &p msg.push_back(pathid); msg.push_back(p_property); msg.push_back(p_value); - _put_msg("live_res_prop", msg); + _put_msg("scene:live_res_prop", msg); } return; @@ -1239,7 +1211,7 @@ void ScriptEditorDebugger::update_live_edit_root() { msg.push_back(editor->get_edited_scene()->get_filename()); else msg.push_back(""); - _put_msg("live_set_root", msg); + _put_msg("scene:live_set_root", msg); live_edit_root->set_text(np); } @@ -1250,7 +1222,7 @@ void ScriptEditorDebugger::live_debug_create_node(const NodePath &p_parent, cons msg.push_back(p_parent); msg.push_back(p_type); msg.push_back(p_name); - _put_msg("live_create_node", msg); + _put_msg("scene:live_create_node", msg); } } @@ -1261,7 +1233,7 @@ void ScriptEditorDebugger::live_debug_instance_node(const NodePath &p_parent, co msg.push_back(p_parent); msg.push_back(p_path); msg.push_back(p_name); - _put_msg("live_instance_node", msg); + _put_msg("scene:live_instance_node", msg); } } void ScriptEditorDebugger::live_debug_remove_node(const NodePath &p_at) { @@ -1269,7 +1241,7 @@ void ScriptEditorDebugger::live_debug_remove_node(const NodePath &p_at) { if (live_debug) { Array msg; msg.push_back(p_at); - _put_msg("live_remove_node", msg); + _put_msg("scene:live_remove_node", msg); } } void ScriptEditorDebugger::live_debug_remove_and_keep_node(const NodePath &p_at, ObjectID p_keep_id) { @@ -1278,7 +1250,7 @@ void ScriptEditorDebugger::live_debug_remove_and_keep_node(const NodePath &p_at, Array msg; msg.push_back(p_at); msg.push_back(p_keep_id); - _put_msg("live_remove_and_keep_node", msg); + _put_msg("scene:live_remove_and_keep_node", msg); } } void ScriptEditorDebugger::live_debug_restore_node(ObjectID p_id, const NodePath &p_at, int p_at_pos) { @@ -1288,7 +1260,7 @@ void ScriptEditorDebugger::live_debug_restore_node(ObjectID p_id, const NodePath msg.push_back(p_id); msg.push_back(p_at); msg.push_back(p_at_pos); - _put_msg("live_restore_node", msg); + _put_msg("scene:live_restore_node", msg); } } void ScriptEditorDebugger::live_debug_duplicate_node(const NodePath &p_at, const String &p_new_name) { @@ -1297,7 +1269,7 @@ void ScriptEditorDebugger::live_debug_duplicate_node(const NodePath &p_at, const Array msg; msg.push_back(p_at); msg.push_back(p_new_name); - _put_msg("live_duplicate_node", msg); + _put_msg("scene:live_duplicate_node", msg); } } void ScriptEditorDebugger::live_debug_reparent_node(const NodePath &p_at, const NodePath &p_new_place, const String &p_new_name, int p_at_pos) { @@ -1308,7 +1280,7 @@ void ScriptEditorDebugger::live_debug_reparent_node(const NodePath &p_at, const msg.push_back(p_new_place); msg.push_back(p_new_name); msg.push_back(p_at_pos); - _put_msg("live_reparent_node", msg); + _put_msg("scene:live_reparent_node", msg); } } @@ -1321,19 +1293,19 @@ void ScriptEditorDebugger::set_camera_override(CameraOverride p_override) { if (p_override == CameraOverride::OVERRIDE_2D && camera_override != CameraOverride::OVERRIDE_2D) { Array msg; msg.push_back(true); - _put_msg("override_camera_2D:set", msg); + _put_msg("scene:override_camera_2D:set", msg); } else if (p_override != CameraOverride::OVERRIDE_2D && camera_override == CameraOverride::OVERRIDE_2D) { Array msg; msg.push_back(false); - _put_msg("override_camera_2D:set", msg); + _put_msg("scene:override_camera_2D:set", msg); } else if (p_override >= CameraOverride::OVERRIDE_3D_1 && camera_override < CameraOverride::OVERRIDE_3D_1) { Array msg; msg.push_back(true); - _put_msg("override_camera_3D:set", msg); + _put_msg("scene:override_camera_3D:set", msg); } else if (p_override < CameraOverride::OVERRIDE_3D_1 && camera_override >= CameraOverride::OVERRIDE_3D_1) { Array msg; msg.push_back(false); - _put_msg("override_camera_3D:set", msg); + _put_msg("scene:override_camera_3D:set", msg); } camera_override = p_override; @@ -1636,7 +1608,7 @@ ScriptEditorDebugger::ScriptEditorDebugger(EditorNode *p_editor) { profiler = memnew(EditorProfiler); profiler->set_name(TTR("Profiler")); tabs->add_child(profiler); - profiler->connect("enable_profiling", callable_mp(this, &ScriptEditorDebugger::_profiler_activate)); + profiler->connect("enable_profiling", callable_mp(this, &ScriptEditorDebugger::_profiler_activate), varray(PROFILER_SCRIPTS_SERVERS)); profiler->connect("break_request", callable_mp(this, &ScriptEditorDebugger::_profiler_seeked)); } @@ -1644,14 +1616,14 @@ ScriptEditorDebugger::ScriptEditorDebugger(EditorNode *p_editor) { visual_profiler = memnew(EditorVisualProfiler); visual_profiler->set_name(TTR("Visual Profiler")); tabs->add_child(visual_profiler); - visual_profiler->connect("enable_profiling", callable_mp(this, &ScriptEditorDebugger::_visual_profiler_activate)); + visual_profiler->connect("enable_profiling", callable_mp(this, &ScriptEditorDebugger::_profiler_activate), varray(PROFILER_VISUAL)); } { //network profiler network_profiler = memnew(EditorNetworkProfiler); network_profiler->set_name(TTR("Network Profiler")); tabs->add_child(network_profiler); - network_profiler->connect("enable_profiling", callable_mp(this, &ScriptEditorDebugger::_network_profiler_activate)); + network_profiler->connect("enable_profiling", callable_mp(this, &ScriptEditorDebugger::_profiler_activate), varray(PROFILER_NETWORK)); } { //monitors diff --git a/editor/debugger/script_editor_debugger.h b/editor/debugger/script_editor_debugger.h index 1fd0713fe5..e7ce917543 100644 --- a/editor/debugger/script_editor_debugger.h +++ b/editor/debugger/script_editor_debugger.h @@ -67,6 +67,12 @@ private: MESSAGE_SUCCESS, }; + enum ProfilerType { + PROFILER_NETWORK, + PROFILER_VISUAL, + PROFILER_SCRIPTS_SERVERS + }; + AcceptDialog *msgdialog; LineEdit *clicked_ctrl; @@ -121,7 +127,7 @@ private: EditorDebuggerInspector *inspector; SceneDebuggerTree *scene_tree; - Ref<EditorDebuggerPeer> peer; + Ref<RemoteDebuggerPeer> peer; HashMap<NodePath, int> node_path_cache; int last_path_id; @@ -171,12 +177,9 @@ private: void _expand_errors_list(); void _collapse_errors_list(); - void _visual_profiler_activate(bool p_enable); - void _profiler_activate(bool p_enable); + void _profiler_activate(bool p_enable, int p_profiler); void _profiler_seeked(); - void _network_profiler_activate(bool p_enable); - void _clear_errors_list(); void _error_tree_item_rmb_selected(const Vector2 &p_pos); @@ -204,7 +207,7 @@ public: void request_remote_tree(); const SceneDebuggerTree *get_remote_tree(); - void start(Ref<EditorDebuggerPeer> p_peer); + void start(Ref<RemoteDebuggerPeer> p_peer); void stop(); void debug_skip_breakpoints(); |