diff options
Diffstat (limited to 'editor/editor_profiler.cpp')
-rw-r--r-- | editor/editor_profiler.cpp | 105 |
1 files changed, 50 insertions, 55 deletions
diff --git a/editor/editor_profiler.cpp b/editor/editor_profiler.cpp index 471742948f..dd784c0980 100644 --- a/editor/editor_profiler.cpp +++ b/editor/editor_profiler.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -88,14 +88,13 @@ void EditorProfiler::clear() { frame_metrics.resize(metric_size); last_metric = -1; variables->clear(); - //activate->set_pressed(false); plot_sigs.clear(); plot_sigs.insert("physics_frame_time"); plot_sigs.insert("category_frame_time"); updating_frame = true; cursor_metric_edit->set_min(0); - cursor_metric_edit->set_max(0); + cursor_metric_edit->set_max(100); // Doesn't make much sense, but we can't have min == max. Doesn't hurt. cursor_metric_edit->set_value(0); updating_frame = false; hover_metric = -1; @@ -103,26 +102,28 @@ void EditorProfiler::clear() { } static String _get_percent_txt(float p_value, float p_total) { - if (p_total == 0) + if (p_total == 0) { p_total = 0.00001; + } + return String::num((p_value / p_total) * 100, 1) + "%"; } String EditorProfiler::_get_time_as_text(const Metric &m, float p_time, int p_calls) { - int dmode = display_mode->get_selected(); + const int dmode = display_mode->get_selected(); if (dmode == DISPLAY_FRAME_TIME) { - return rtos(p_time); + return rtos(p_time * 1000).pad_decimals(2) + " ms"; } else if (dmode == DISPLAY_AVERAGE_TIME) { - if (p_calls == 0) - return "0"; - else - return rtos(p_time / p_calls); + if (p_calls == 0) { + return "0.00 ms"; + } else { + return rtos((p_time / p_calls) * 1000).pad_decimals(2) + " ms"; + } } else if (dmode == DISPLAY_FRAME_PERCENT) { return _get_percent_txt(p_time, m.frame_time); } else if (dmode == DISPLAY_PHYSICS_FRAME_PERCENT) { - return _get_percent_txt(p_time, m.physics_frame_time); } @@ -164,31 +165,30 @@ void EditorProfiler::_item_edited() { void EditorProfiler::_update_plot() { - int w = graph->get_size().width; - int h = graph->get_size().height; - + const int w = graph->get_size().width; + const int h = graph->get_size().height; bool reset_texture = false; - - int desired_len = w * h * 4; + const int desired_len = w * h * 4; if (graph_image.size() != desired_len) { reset_texture = true; graph_image.resize(desired_len); } - PoolVector<uint8_t>::Write wr = graph_image.write(); + uint8_t *wr = graph_image.ptrw(); + const Color background_color = get_color("dark_color_2", "Editor"); - //clear + // Clear the previous frame and set the background color. for (int i = 0; i < desired_len; i += 4) { - wr[i + 0] = 0; - wr[i + 1] = 0; - wr[i + 2] = 0; + wr[i + 0] = Math::fast_ftoi(background_color.r * 255); + wr[i + 1] = Math::fast_ftoi(background_color.g * 255); + wr[i + 2] = Math::fast_ftoi(background_color.b * 255); wr[i + 3] = 255; } //find highest value - bool use_self = display_time->get_selected() == DISPLAY_SELF_TIME; + const bool use_self = display_time->get_selected() == DISPLAY_SELF_TIME; float highest = 0; for (int i = 0; i < frame_metrics.size(); i++) { @@ -320,28 +320,28 @@ void EditorProfiler::_update_plot() { for (int j = 0; j < h * 4; j += 4) { - int a = column[j + 3]; + const int a = column[j + 3]; if (a > 0) { column[j + 0] /= a; column[j + 1] /= a; column[j + 2] /= a; } - uint8_t r = uint8_t(column[j + 0]); - uint8_t g = uint8_t(column[j + 1]); - uint8_t b = uint8_t(column[j + 2]); + const uint8_t red = uint8_t(column[j + 0]); + const uint8_t green = uint8_t(column[j + 1]); + const uint8_t blue = uint8_t(column[j + 2]); + const bool is_filled = red >= 1 || green >= 1 || blue >= 1; + const int widx = ((j >> 2) * w + i) * 4; - int widx = ((j >> 2) * w + i) * 4; - wr[widx + 0] = r; - wr[widx + 1] = g; - wr[widx + 2] = b; + // If the pixel isn't filled by any profiler line, apply the background color instead. + wr[widx + 0] = is_filled ? red : Math::fast_ftoi(background_color.r * 255); + wr[widx + 1] = is_filled ? green : Math::fast_ftoi(background_color.g * 255); + wr[widx + 2] = is_filled ? blue : Math::fast_ftoi(background_color.b * 255); wr[widx + 3] = 255; } } } - wr.release(); - Ref<Image> img; img.instance(); img->create(w, h, 0, Image::FORMAT_RGBA8, graph_image); @@ -351,10 +351,10 @@ void EditorProfiler::_update_plot() { if (graph_texture.is_null()) { graph_texture.instance(); } - graph_texture->create(img->get_width(), img->get_height(), img->get_format(), Texture::FLAG_VIDEO_SURFACE); + graph_texture->create_from_image(img); } - graph_texture->set_data(img); + graph_texture->update(img, true); graph->set_texture(graph_texture); graph->update(); @@ -398,6 +398,7 @@ void EditorProfiler::_update_frame() { item->set_metadata(0, it.signature); item->set_metadata(1, it.script); item->set_metadata(2, it.line); + item->set_text_align(2, TreeItem::ALIGN_RIGHT); item->set_tooltip(0, it.script + ":" + itos(it.line)); float time = dtime == DISPLAY_SELF_TIME ? it.self : it.total; @@ -685,12 +686,12 @@ EditorProfiler::EditorProfiler() { activate = memnew(Button); activate->set_toggle_mode(true); activate->set_text(TTR("Start")); - activate->connect("pressed", this, "_activate_pressed"); + activate->connect_compat("pressed", this, "_activate_pressed"); hb->add_child(activate); clear_button = memnew(Button); clear_button->set_text(TTR("Clear")); - clear_button->connect("pressed", this, "_clear_pressed"); + clear_button->connect_compat("pressed", this, "_clear_pressed"); hb->add_child(clear_button); hb->add_child(memnew(Label(TTR("Measure:")))); @@ -700,7 +701,7 @@ EditorProfiler::EditorProfiler() { display_mode->add_item(TTR("Average Time (sec)")); display_mode->add_item(TTR("Frame %")); display_mode->add_item(TTR("Physics Frame %")); - display_mode->connect("item_selected", this, "_combo_changed"); + display_mode->connect_compat("item_selected", this, "_combo_changed"); hb->add_child(display_mode); @@ -709,7 +710,7 @@ EditorProfiler::EditorProfiler() { display_time = memnew(OptionButton); display_time->add_item(TTR("Inclusive")); display_time->add_item(TTR("Self")); - display_time->connect("item_selected", this, "_combo_changed"); + display_time->connect_compat("item_selected", this, "_combo_changed"); hb->add_child(display_time); @@ -720,7 +721,7 @@ EditorProfiler::EditorProfiler() { cursor_metric_edit = memnew(SpinBox); cursor_metric_edit->set_h_size_flags(SIZE_FILL); hb->add_child(cursor_metric_edit); - cursor_metric_edit->connect("value_changed", this, "_cursor_metric_changed"); + cursor_metric_edit->connect_compat("value_changed", this, "_cursor_metric_changed"); hb->add_constant_override("separation", 8 * EDSCALE); @@ -729,7 +730,7 @@ EditorProfiler::EditorProfiler() { h_split->set_v_size_flags(SIZE_EXPAND_FILL); variables = memnew(Tree); - variables->set_custom_minimum_size(Size2(300, 0) * EDSCALE); + variables->set_custom_minimum_size(Size2(320, 0) * EDSCALE); variables->set_hide_folding(true); h_split->add_child(variables); variables->set_hide_root(true); @@ -737,22 +738,21 @@ EditorProfiler::EditorProfiler() { variables->set_column_titles_visible(true); variables->set_column_title(0, TTR("Name")); variables->set_column_expand(0, true); - variables->set_column_min_width(0, 60); + variables->set_column_min_width(0, 60 * EDSCALE); variables->set_column_title(1, TTR("Time")); variables->set_column_expand(1, false); - variables->set_column_min_width(1, 60 * EDSCALE); + variables->set_column_min_width(1, 100 * EDSCALE); variables->set_column_title(2, TTR("Calls")); variables->set_column_expand(2, false); variables->set_column_min_width(2, 60 * EDSCALE); - variables->connect("item_edited", this, "_item_edited"); + variables->connect_compat("item_edited", this, "_item_edited"); graph = memnew(TextureRect); graph->set_expand(true); graph->set_mouse_filter(MOUSE_FILTER_STOP); - //graph->set_ignore_mouse(false); - graph->connect("draw", this, "_graph_tex_draw"); - graph->connect("gui_input", this, "_graph_tex_input"); - graph->connect("mouse_exited", this, "_graph_tex_mouse_exit"); + graph->connect_compat("draw", this, "_graph_tex_draw"); + graph->connect_compat("gui_input", this, "_graph_tex_input"); + graph->connect_compat("mouse_exited", this, "_graph_tex_mouse_exit"); h_split->add_child(graph); graph->set_h_size_flags(SIZE_EXPAND_FILL); @@ -760,30 +760,25 @@ EditorProfiler::EditorProfiler() { int metric_size = CLAMP(int(EDITOR_DEF("debugger/profiler_frame_history_size", 600)), 60, 1024); frame_metrics.resize(metric_size); last_metric = -1; - //cursor_metric=-1; hover_metric = -1; EDITOR_DEF("debugger/profiler_frame_max_functions", 64); - //display_mode=DISPLAY_FRAME_TIME; - 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", this, "_update_frame"); + frame_delay->connect_compat("timeout", this, "_update_frame"); plot_delay = memnew(Timer); plot_delay->set_wait_time(0.1); plot_delay->set_one_shot(true); add_child(plot_delay); - plot_delay->connect("timeout", this, "_update_plot"); + plot_delay->connect_compat("timeout", this, "_update_plot"); plot_sigs.insert("physics_frame_time"); plot_sigs.insert("category_frame_time"); seeking = false; graph_height = 1; - - //activate->set_disabled(true); } |