diff --git a/editor/script_editor_debugger.cpp b/editor/script_editor_debugger.cpp index ef61aad3413..040d30e99c7 100644 --- a/editor/script_editor_debugger.cpp +++ b/editor/script_editor_debugger.cpp @@ -574,7 +574,38 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da for (int i = 0; i < arr.size(); i++) { p[i] = arr[i]; if (i < perf_items.size()) { - perf_items[i]->set_text(1, rtos(p[i])); + + float v = p[i]; + String vs = rtos(v); + String tt = vs; + switch (Performance::MonitorType((int)perf_items[i]->get_metadata(1))) { + case Performance::MONITOR_TYPE_MEMORY: { + // for the time being, going above GBs is a bad sign. + String unit = "B"; + if ((int)v > 1073741824) { + unit = "GB"; + v /= 1073741824.0; + } else if ((int)v > 1048576) { + unit = "MB"; + v /= 1048576.0; + } else if ((int)v > 1024) { + unit = "KB"; + v /= 1024.0; + } + tt += " bytes"; + vs = rtos(v) + " " + unit; + } break; + case Performance::MONITOR_TYPE_TIME: { + tt += " seconds"; + vs += " s"; + } break; + default: { + tt += " " + perf_items[i]->get_text(0); + } break; + } + + perf_items[i]->set_text(1, vs); + perf_items[i]->set_tooltip(1, tt); if (p[i] > perf_max[i]) perf_max[i] = p[i]; } @@ -816,14 +847,14 @@ void ScriptEditorDebugger::_performance_draw() { r.position += graph_sb->get_offset(); r.size -= graph_sb->get_minimum_size(); int pi = which[i]; - Color c = get_color("success_color", "Editor"); - c.set_hsv(Math::fmod(c.get_h() + pi * 0.7654, 1), c.get_s(), c.get_v()); - //c = c.linear_interpolate(get_color("base_color", "Editor"), 0.9); + Color c = get_color("accent_color", "Editor"); + float h = (float)which[i] / (float)(perf_items.size()); + c.set_hsv(Math::fmod(h + 0.4, 0.9), c.get_s() * 0.9, c.get_v() * 1.4); - c.a = 0.8; - perf_draw->draw_string(graph_font, r.position + Point2(0, graph_font->get_ascent()), perf_items[pi]->get_text(0), c, r.size.x); c.a = 0.6; - perf_draw->draw_string(graph_font, r.position + Point2(graph_font->get_char_size('X').width, graph_font->get_ascent() + graph_font->get_height()), perf_items[pi]->get_text(1), c, r.size.y); + perf_draw->draw_string(graph_font, r.position + Point2(0, graph_font->get_ascent()), perf_items[pi]->get_text(0), c, r.size.x); + c.a = 0.9; + perf_draw->draw_string(graph_font, r.position + Point2(0, graph_font->get_ascent() + graph_font->get_height()), perf_items[pi]->get_text(1), c, r.size.y); float spacing = point_sep / float(cols); float from = r.size.width; @@ -1801,6 +1832,7 @@ ScriptEditorDebugger::ScriptEditorDebugger(EditorNode *p_editor) { for (int i = 0; i < Performance::MONITOR_MAX; i++) { String n = Performance::get_singleton()->get_monitor_name(Performance::Monitor(i)); + Performance::MonitorType mtype = Performance::get_singleton()->get_monitor_type(Performance::Monitor(i)); String base = n.get_slice("/", 0); String name = n.get_slice("/", 1); if (!bases.has(base)) { @@ -1812,6 +1844,7 @@ ScriptEditorDebugger::ScriptEditorDebugger(EditorNode *p_editor) { } TreeItem *it = perf_monitors->create_item(bases[base]); + it->set_metadata(1, mtype); it->set_editable(0, false); it->set_selectable(0, true); it->set_text(0, name.capitalize()); diff --git a/main/performance.cpp b/main/performance.cpp index c4b62559c7b..39b42e803cb 100644 --- a/main/performance.cpp +++ b/main/performance.cpp @@ -153,6 +153,44 @@ float Performance::get_monitor(Monitor p_monitor) const { return 0; } +Performance::MonitorType Performance::get_monitor_type(Monitor p_monitor) const { + ERR_FAIL_INDEX_V(p_monitor, MONITOR_MAX, MONITOR_TYPE_QUANTITY); + // ugly + static const MonitorType types[MONITOR_MAX] = { + + MONITOR_TYPE_QUANTITY, + MONITOR_TYPE_TIME, + MONITOR_TYPE_TIME, + MONITOR_TYPE_MEMORY, + MONITOR_TYPE_MEMORY, + MONITOR_TYPE_MEMORY, + MONITOR_TYPE_MEMORY, + MONITOR_TYPE_MEMORY, + MONITOR_TYPE_QUANTITY, + MONITOR_TYPE_QUANTITY, + MONITOR_TYPE_QUANTITY, + MONITOR_TYPE_QUANTITY, + MONITOR_TYPE_QUANTITY, + MONITOR_TYPE_QUANTITY, + MONITOR_TYPE_QUANTITY, + MONITOR_TYPE_QUANTITY, + MONITOR_TYPE_QUANTITY, + MONITOR_TYPE_MEMORY, + MONITOR_TYPE_MEMORY, + MONITOR_TYPE_MEMORY, + MONITOR_TYPE_MEMORY, + MONITOR_TYPE_QUANTITY, + MONITOR_TYPE_QUANTITY, + MONITOR_TYPE_QUANTITY, + MONITOR_TYPE_QUANTITY, + MONITOR_TYPE_QUANTITY, + MONITOR_TYPE_QUANTITY, + + }; + + return types[p_monitor]; +} + void Performance::set_process_time(float p_pt) { _process_time = p_pt; diff --git a/main/performance.h b/main/performance.h index 900e6434b74..21fbd7a1d2d 100644 --- a/main/performance.h +++ b/main/performance.h @@ -79,9 +79,17 @@ public: MONITOR_MAX }; + enum MonitorType { + MONITOR_TYPE_QUANTITY, + MONITOR_TYPE_MEMORY, + MONITOR_TYPE_TIME + }; + float get_monitor(Monitor p_monitor) const; String get_monitor_name(Monitor p_monitor) const; + MonitorType get_monitor_type(Monitor p_monitor) const; + void set_process_time(float p_pt); void set_physics_process_time(float p_pt);