summaryrefslogtreecommitdiff
path: root/editor/editor_profiler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/editor_profiler.cpp')
-rw-r--r--editor/editor_profiler.cpp72
1 files changed, 35 insertions, 37 deletions
diff --git a/editor/editor_profiler.cpp b/editor/editor_profiler.cpp
index 020cb3bada..e5a9c4d699 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 */
@@ -102,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);
}
@@ -163,12 +165,10 @@ 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;
@@ -176,18 +176,19 @@ void EditorProfiler::_update_plot() {
}
PoolVector<uint8_t>::Write wr = graph_image.write();
+ 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++) {
@@ -319,21 +320,23 @@ 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;
}
}
@@ -397,6 +400,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;
@@ -728,7 +732,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);
@@ -736,10 +740,10 @@ 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);
@@ -748,7 +752,6 @@ EditorProfiler::EditorProfiler() {
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");
@@ -759,13 +762,10 @@ 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);
@@ -783,6 +783,4 @@ EditorProfiler::EditorProfiler() {
seeking = false;
graph_height = 1;
-
- //activate->set_disabled(true);
}