|
@@ -36,13 +36,19 @@
|
|
|
|
|
|
void EditorNetworkProfiler::_bind_methods() {
|
|
void EditorNetworkProfiler::_bind_methods() {
|
|
ADD_SIGNAL(MethodInfo("enable_profiling", PropertyInfo(Variant::BOOL, "enable")));
|
|
ADD_SIGNAL(MethodInfo("enable_profiling", PropertyInfo(Variant::BOOL, "enable")));
|
|
|
|
+ ADD_SIGNAL(MethodInfo("open_request", PropertyInfo(Variant::STRING, "path")));
|
|
}
|
|
}
|
|
|
|
|
|
void EditorNetworkProfiler::_notification(int p_what) {
|
|
void EditorNetworkProfiler::_notification(int p_what) {
|
|
switch (p_what) {
|
|
switch (p_what) {
|
|
case NOTIFICATION_ENTER_TREE:
|
|
case NOTIFICATION_ENTER_TREE:
|
|
case NOTIFICATION_THEME_CHANGED: {
|
|
case NOTIFICATION_THEME_CHANGED: {
|
|
- activate->set_icon(get_theme_icon(SNAME("Play"), SNAME("EditorIcons")));
|
|
|
|
|
|
+ node_icon = get_theme_icon(SNAME("Node"), SNAME("EditorIcons"));
|
|
|
|
+ if (activate->is_pressed()) {
|
|
|
|
+ activate->set_icon(get_theme_icon(SNAME("Stop"), SNAME("EditorIcons")));
|
|
|
|
+ } else {
|
|
|
|
+ activate->set_icon(get_theme_icon(SNAME("Play"), SNAME("EditorIcons")));
|
|
|
|
+ }
|
|
clear_button->set_icon(get_theme_icon(SNAME("Clear"), SNAME("EditorIcons")));
|
|
clear_button->set_icon(get_theme_icon(SNAME("Clear"), SNAME("EditorIcons")));
|
|
incoming_bandwidth_text->set_right_icon(get_theme_icon(SNAME("ArrowDown"), SNAME("EditorIcons")));
|
|
incoming_bandwidth_text->set_right_icon(get_theme_icon(SNAME("ArrowDown"), SNAME("EditorIcons")));
|
|
outgoing_bandwidth_text->set_right_icon(get_theme_icon(SNAME("ArrowUp"), SNAME("EditorIcons")));
|
|
outgoing_bandwidth_text->set_right_icon(get_theme_icon(SNAME("ArrowUp"), SNAME("EditorIcons")));
|
|
@@ -54,15 +60,25 @@ void EditorNetworkProfiler::_notification(int p_what) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-void EditorNetworkProfiler::_update_frame() {
|
|
|
|
|
|
+void EditorNetworkProfiler::_refresh() {
|
|
|
|
+ if (!dirty) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ dirty = false;
|
|
|
|
+ refresh_rpc_data();
|
|
|
|
+ refresh_replication_data();
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void EditorNetworkProfiler::refresh_rpc_data() {
|
|
counters_display->clear();
|
|
counters_display->clear();
|
|
|
|
|
|
TreeItem *root = counters_display->create_item();
|
|
TreeItem *root = counters_display->create_item();
|
|
|
|
+ int cols = counters_display->get_columns();
|
|
|
|
|
|
- for (const KeyValue<ObjectID, RPCNodeInfo> &E : nodes_data) {
|
|
|
|
|
|
+ for (const KeyValue<ObjectID, RPCNodeInfo> &E : rpc_data) {
|
|
TreeItem *node = counters_display->create_item(root);
|
|
TreeItem *node = counters_display->create_item(root);
|
|
|
|
|
|
- for (int j = 0; j < counters_display->get_columns(); ++j) {
|
|
|
|
|
|
+ for (int j = 0; j < cols; ++j) {
|
|
node->set_text_alignment(j, j > 0 ? HORIZONTAL_ALIGNMENT_RIGHT : HORIZONTAL_ALIGNMENT_LEFT);
|
|
node->set_text_alignment(j, j > 0 ? HORIZONTAL_ALIGNMENT_RIGHT : HORIZONTAL_ALIGNMENT_LEFT);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -72,11 +88,76 @@ void EditorNetworkProfiler::_update_frame() {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+void EditorNetworkProfiler::refresh_replication_data() {
|
|
|
|
+ replication_display->clear();
|
|
|
|
+
|
|
|
|
+ TreeItem *root = replication_display->create_item();
|
|
|
|
+
|
|
|
|
+ for (const KeyValue<ObjectID, SyncInfo> &E : sync_data) {
|
|
|
|
+ // Ensure the nodes have at least a temporary cache.
|
|
|
|
+ ObjectID ids[3] = { E.value.synchronizer, E.value.config, E.value.root_node };
|
|
|
|
+ for (uint32_t i = 0; i < 3; i++) {
|
|
|
|
+ const ObjectID &id = ids[i];
|
|
|
|
+ if (!node_data.has(id)) {
|
|
|
|
+ missing_node_data.insert(id);
|
|
|
|
+ node_data[id] = NodeInfo(id);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ TreeItem *node = replication_display->create_item(root);
|
|
|
|
+
|
|
|
|
+ const NodeInfo &root_info = node_data[E.value.root_node];
|
|
|
|
+ const NodeInfo &sync_info = node_data[E.value.synchronizer];
|
|
|
|
+ const NodeInfo &cfg_info = node_data[E.value.config];
|
|
|
|
+
|
|
|
|
+ node->set_text(0, root_info.path.get_file());
|
|
|
|
+ node->set_icon(0, has_theme_icon(root_info.type, SNAME("EditorIcons")) ? get_theme_icon(root_info.type, SNAME("EditorIcons")) : node_icon);
|
|
|
|
+ node->set_tooltip_text(0, root_info.path);
|
|
|
|
+
|
|
|
|
+ node->set_text(1, sync_info.path.get_file());
|
|
|
|
+ node->set_icon(1, get_theme_icon("MultiplayerSynchronizer", SNAME("EditorIcons")));
|
|
|
|
+ node->set_tooltip_text(1, sync_info.path);
|
|
|
|
+
|
|
|
|
+ int cfg_idx = cfg_info.path.find("::");
|
|
|
|
+ if (cfg_info.path.begins_with("res://") && ResourceLoader::exists(cfg_info.path) && cfg_idx > 0) {
|
|
|
|
+ String res_idstr = cfg_info.path.substr(cfg_idx + 2).replace("SceneReplicationConfig_", "");
|
|
|
|
+ String scene_path = cfg_info.path.substr(0, cfg_idx);
|
|
|
|
+ node->set_text(2, vformat("%s (%s)", res_idstr, scene_path.get_file()));
|
|
|
|
+ node->add_button(2, get_theme_icon(SNAME("InstanceOptions"), SNAME("EditorIcons")));
|
|
|
|
+ node->set_tooltip_text(2, cfg_info.path);
|
|
|
|
+ node->set_metadata(2, scene_path);
|
|
|
|
+ } else {
|
|
|
|
+ node->set_text(2, cfg_info.path);
|
|
|
|
+ node->set_metadata(2, "");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ node->set_text(3, vformat("%d - %d", E.value.incoming_syncs, E.value.outgoing_syncs));
|
|
|
|
+ node->set_text(4, vformat("%d - %d", E.value.incoming_size, E.value.outgoing_size));
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+Array EditorNetworkProfiler::pop_missing_node_data() {
|
|
|
|
+ Array out;
|
|
|
|
+ for (const ObjectID &id : missing_node_data) {
|
|
|
|
+ out.push_back(id);
|
|
|
|
+ }
|
|
|
|
+ missing_node_data.clear();
|
|
|
|
+ return out;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void EditorNetworkProfiler::add_node_data(const NodeInfo &p_info) {
|
|
|
|
+ ERR_FAIL_COND(!node_data.has(p_info.id));
|
|
|
|
+ node_data[p_info.id] = p_info;
|
|
|
|
+ dirty = true;
|
|
|
|
+}
|
|
|
|
+
|
|
void EditorNetworkProfiler::_activate_pressed() {
|
|
void EditorNetworkProfiler::_activate_pressed() {
|
|
if (activate->is_pressed()) {
|
|
if (activate->is_pressed()) {
|
|
|
|
+ refresh_timer->start();
|
|
activate->set_icon(get_theme_icon(SNAME("Stop"), SNAME("EditorIcons")));
|
|
activate->set_icon(get_theme_icon(SNAME("Stop"), SNAME("EditorIcons")));
|
|
activate->set_text(TTR("Stop"));
|
|
activate->set_text(TTR("Stop"));
|
|
} else {
|
|
} else {
|
|
|
|
+ refresh_timer->stop();
|
|
activate->set_icon(get_theme_icon(SNAME("Play"), SNAME("EditorIcons")));
|
|
activate->set_icon(get_theme_icon(SNAME("Play"), SNAME("EditorIcons")));
|
|
activate->set_text(TTR("Start"));
|
|
activate->set_text(TTR("Start"));
|
|
}
|
|
}
|
|
@@ -84,31 +165,55 @@ void EditorNetworkProfiler::_activate_pressed() {
|
|
}
|
|
}
|
|
|
|
|
|
void EditorNetworkProfiler::_clear_pressed() {
|
|
void EditorNetworkProfiler::_clear_pressed() {
|
|
- nodes_data.clear();
|
|
|
|
|
|
+ rpc_data.clear();
|
|
|
|
+ sync_data.clear();
|
|
|
|
+ node_data.clear();
|
|
|
|
+ missing_node_data.clear();
|
|
set_bandwidth(0, 0);
|
|
set_bandwidth(0, 0);
|
|
- if (frame_delay->is_stopped()) {
|
|
|
|
- frame_delay->set_wait_time(0.1);
|
|
|
|
- frame_delay->start();
|
|
|
|
|
|
+ refresh_rpc_data();
|
|
|
|
+ refresh_replication_data();
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void EditorNetworkProfiler::_replication_button_clicked(TreeItem *p_item, int p_column, int p_idx, MouseButton p_button) {
|
|
|
|
+ if (!p_item) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ String meta = p_item->get_metadata(p_column);
|
|
|
|
+ if (meta.size() && ResourceLoader::exists(meta)) {
|
|
|
|
+ emit_signal("open_request", meta);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-void EditorNetworkProfiler::add_node_frame_data(const RPCNodeInfo p_frame) {
|
|
|
|
- if (!nodes_data.has(p_frame.node)) {
|
|
|
|
- nodes_data.insert(p_frame.node, p_frame);
|
|
|
|
|
|
+void EditorNetworkProfiler::add_rpc_frame_data(const RPCNodeInfo &p_frame) {
|
|
|
|
+ dirty = true;
|
|
|
|
+ if (!rpc_data.has(p_frame.node)) {
|
|
|
|
+ rpc_data.insert(p_frame.node, p_frame);
|
|
} else {
|
|
} else {
|
|
- nodes_data[p_frame.node].incoming_rpc += p_frame.incoming_rpc;
|
|
|
|
- nodes_data[p_frame.node].outgoing_rpc += p_frame.outgoing_rpc;
|
|
|
|
|
|
+ rpc_data[p_frame.node].incoming_rpc += p_frame.incoming_rpc;
|
|
|
|
+ rpc_data[p_frame.node].outgoing_rpc += p_frame.outgoing_rpc;
|
|
}
|
|
}
|
|
if (p_frame.incoming_rpc) {
|
|
if (p_frame.incoming_rpc) {
|
|
- nodes_data[p_frame.node].incoming_size = p_frame.incoming_size / p_frame.incoming_rpc;
|
|
|
|
|
|
+ rpc_data[p_frame.node].incoming_size = p_frame.incoming_size / p_frame.incoming_rpc;
|
|
}
|
|
}
|
|
if (p_frame.outgoing_rpc) {
|
|
if (p_frame.outgoing_rpc) {
|
|
- nodes_data[p_frame.node].outgoing_size = p_frame.outgoing_size / p_frame.outgoing_rpc;
|
|
|
|
|
|
+ rpc_data[p_frame.node].outgoing_size = p_frame.outgoing_size / p_frame.outgoing_rpc;
|
|
}
|
|
}
|
|
|
|
+}
|
|
|
|
|
|
- if (frame_delay->is_stopped()) {
|
|
|
|
- frame_delay->set_wait_time(0.1);
|
|
|
|
- frame_delay->start();
|
|
|
|
|
|
+void EditorNetworkProfiler::add_sync_frame_data(const SyncInfo &p_frame) {
|
|
|
|
+ dirty = true;
|
|
|
|
+ if (!sync_data.has(p_frame.synchronizer)) {
|
|
|
|
+ sync_data[p_frame.synchronizer] = p_frame;
|
|
|
|
+ } else {
|
|
|
|
+ sync_data[p_frame.synchronizer].incoming_syncs += p_frame.incoming_syncs;
|
|
|
|
+ sync_data[p_frame.synchronizer].outgoing_syncs += p_frame.outgoing_syncs;
|
|
|
|
+ }
|
|
|
|
+ SyncInfo &info = sync_data[p_frame.synchronizer];
|
|
|
|
+ if (info.incoming_syncs) {
|
|
|
|
+ info.incoming_size = p_frame.incoming_size / p_frame.incoming_syncs;
|
|
|
|
+ }
|
|
|
|
+ if (info.outgoing_syncs) {
|
|
|
|
+ info.outgoing_size = p_frame.outgoing_size / p_frame.outgoing_syncs;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -174,9 +279,17 @@ EditorNetworkProfiler::EditorNetworkProfiler() {
|
|
// Set initial texts in the incoming/outgoing bandwidth labels
|
|
// Set initial texts in the incoming/outgoing bandwidth labels
|
|
set_bandwidth(0, 0);
|
|
set_bandwidth(0, 0);
|
|
|
|
|
|
|
|
+ HSplitContainer *sc = memnew(HSplitContainer);
|
|
|
|
+ add_child(sc);
|
|
|
|
+ sc->set_v_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
+ sc->set_h_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
+ sc->set_split_offset(100 * EDSCALE);
|
|
|
|
+
|
|
|
|
+ // RPC
|
|
counters_display = memnew(Tree);
|
|
counters_display = memnew(Tree);
|
|
- counters_display->set_custom_minimum_size(Size2(300, 0) * EDSCALE);
|
|
|
|
|
|
+ counters_display->set_custom_minimum_size(Size2(320, 0) * EDSCALE);
|
|
counters_display->set_v_size_flags(SIZE_EXPAND_FILL);
|
|
counters_display->set_v_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
+ counters_display->set_h_size_flags(SIZE_EXPAND_FILL);
|
|
counters_display->set_hide_folding(true);
|
|
counters_display->set_hide_folding(true);
|
|
counters_display->set_hide_root(true);
|
|
counters_display->set_hide_root(true);
|
|
counters_display->set_columns(3);
|
|
counters_display->set_columns(3);
|
|
@@ -193,11 +306,42 @@ EditorNetworkProfiler::EditorNetworkProfiler() {
|
|
counters_display->set_column_expand(2, false);
|
|
counters_display->set_column_expand(2, false);
|
|
counters_display->set_column_clip_content(2, true);
|
|
counters_display->set_column_clip_content(2, true);
|
|
counters_display->set_column_custom_minimum_width(2, 120 * EDSCALE);
|
|
counters_display->set_column_custom_minimum_width(2, 120 * EDSCALE);
|
|
- add_child(counters_display);
|
|
|
|
|
|
+ sc->add_child(counters_display);
|
|
|
|
+
|
|
|
|
+ // Replication
|
|
|
|
+ replication_display = memnew(Tree);
|
|
|
|
+ replication_display->set_custom_minimum_size(Size2(320, 0) * EDSCALE);
|
|
|
|
+ replication_display->set_v_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
+ replication_display->set_h_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
+ replication_display->set_hide_folding(true);
|
|
|
|
+ replication_display->set_hide_root(true);
|
|
|
|
+ replication_display->set_columns(5);
|
|
|
|
+ replication_display->set_column_titles_visible(true);
|
|
|
|
+ replication_display->set_column_title(0, TTR("Root"));
|
|
|
|
+ replication_display->set_column_expand(0, true);
|
|
|
|
+ replication_display->set_column_clip_content(0, true);
|
|
|
|
+ replication_display->set_column_custom_minimum_width(0, 80 * EDSCALE);
|
|
|
|
+ replication_display->set_column_title(1, TTR("Synchronizer"));
|
|
|
|
+ replication_display->set_column_expand(1, true);
|
|
|
|
+ replication_display->set_column_clip_content(1, true);
|
|
|
|
+ replication_display->set_column_custom_minimum_width(1, 80 * EDSCALE);
|
|
|
|
+ replication_display->set_column_title(2, TTR("Config"));
|
|
|
|
+ replication_display->set_column_expand(2, true);
|
|
|
|
+ replication_display->set_column_clip_content(2, true);
|
|
|
|
+ replication_display->set_column_custom_minimum_width(2, 80 * EDSCALE);
|
|
|
|
+ replication_display->set_column_title(3, TTR("Count"));
|
|
|
|
+ replication_display->set_column_expand(3, false);
|
|
|
|
+ replication_display->set_column_clip_content(3, true);
|
|
|
|
+ replication_display->set_column_custom_minimum_width(3, 80 * EDSCALE);
|
|
|
|
+ replication_display->set_column_title(4, TTR("Size"));
|
|
|
|
+ replication_display->set_column_expand(4, false);
|
|
|
|
+ replication_display->set_column_clip_content(4, true);
|
|
|
|
+ replication_display->set_column_custom_minimum_width(4, 80 * EDSCALE);
|
|
|
|
+ replication_display->connect("button_clicked", callable_mp(this, &EditorNetworkProfiler::_replication_button_clicked));
|
|
|
|
+ sc->add_child(replication_display);
|
|
|
|
|
|
- frame_delay = memnew(Timer);
|
|
|
|
- frame_delay->set_wait_time(0.1);
|
|
|
|
- frame_delay->set_one_shot(true);
|
|
|
|
- add_child(frame_delay);
|
|
|
|
- frame_delay->connect("timeout", callable_mp(this, &EditorNetworkProfiler::_update_frame));
|
|
|
|
|
|
+ refresh_timer = memnew(Timer);
|
|
|
|
+ refresh_timer->set_wait_time(0.5);
|
|
|
|
+ refresh_timer->connect("timeout", callable_mp(this, &EditorNetworkProfiler::_refresh));
|
|
|
|
+ add_child(refresh_timer);
|
|
}
|
|
}
|