| 
									
										
										
										
											2023-01-05 13:25:55 +01:00
										 |  |  | /**************************************************************************/ | 
					
						
							|  |  |  | /*  editor_visual_profiler.cpp                                            */ | 
					
						
							|  |  |  | /**************************************************************************/ | 
					
						
							|  |  |  | /*                         This file is part of:                          */ | 
					
						
							|  |  |  | /*                             GODOT ENGINE                               */ | 
					
						
							|  |  |  | /*                        https://godotengine.org                         */ | 
					
						
							|  |  |  | /**************************************************************************/ | 
					
						
							|  |  |  | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ | 
					
						
							|  |  |  | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur.                  */ | 
					
						
							|  |  |  | /*                                                                        */ | 
					
						
							|  |  |  | /* Permission is hereby granted, free of charge, to any person obtaining  */ | 
					
						
							|  |  |  | /* a copy of this software and associated documentation files (the        */ | 
					
						
							|  |  |  | /* "Software"), to deal in the Software without restriction, including    */ | 
					
						
							|  |  |  | /* without limitation the rights to use, copy, modify, merge, publish,    */ | 
					
						
							|  |  |  | /* distribute, sublicense, and/or sell copies of the Software, and to     */ | 
					
						
							|  |  |  | /* permit persons to whom the Software is furnished to do so, subject to  */ | 
					
						
							|  |  |  | /* the following conditions:                                              */ | 
					
						
							|  |  |  | /*                                                                        */ | 
					
						
							|  |  |  | /* The above copyright notice and this permission notice shall be         */ | 
					
						
							|  |  |  | /* included in all copies or substantial portions of the Software.        */ | 
					
						
							|  |  |  | /*                                                                        */ | 
					
						
							|  |  |  | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,        */ | 
					
						
							|  |  |  | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF     */ | 
					
						
							|  |  |  | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ | 
					
						
							|  |  |  | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY   */ | 
					
						
							|  |  |  | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,   */ | 
					
						
							|  |  |  | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE      */ | 
					
						
							|  |  |  | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                 */ | 
					
						
							|  |  |  | /**************************************************************************/ | 
					
						
							| 
									
										
										
										
											2019-11-05 12:01:00 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | #include "editor_visual_profiler.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-16 14:13:36 +03:00
										 |  |  | #include "core/io/image.h"
 | 
					
						
							| 
									
										
										
										
											2020-03-08 12:21:08 +01:00
										 |  |  | #include "editor/editor_settings.h"
 | 
					
						
							| 
									
										
										
										
											2023-08-13 02:33:39 +02:00
										 |  |  | #include "editor/editor_string_names.h"
 | 
					
						
							| 
									
										
										
										
											2024-09-26 16:31:00 +02:00
										 |  |  | #include "editor/gui/editor_run_bar.h"
 | 
					
						
							| 
									
										
										
										
											2024-01-15 13:14:55 +01:00
										 |  |  | #include "editor/themes/editor_scale.h"
 | 
					
						
							| 
									
										
										
										
											2023-07-11 22:29:09 +02:00
										 |  |  | #include "scene/resources/image_texture.h"
 | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-11 19:51:54 +01:00
										 |  |  | void EditorVisualProfiler::set_hardware_info(const String &p_cpu_name, const String &p_gpu_name) { | 
					
						
							|  |  |  | 	cpu_name = p_cpu_name; | 
					
						
							|  |  |  | 	gpu_name = p_gpu_name; | 
					
						
							|  |  |  | 	queue_redraw(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | void EditorVisualProfiler::add_frame_metric(const Metric &p_metric) { | 
					
						
							|  |  |  | 	++last_metric; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (last_metric >= frame_metrics.size()) { | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 		last_metric = 0; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	frame_metrics.write[last_metric] = p_metric; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	List<String> stack; | 
					
						
							|  |  |  | 	for (int i = 0; i < frame_metrics[last_metric].areas.size(); i++) { | 
					
						
							|  |  |  | 		String name = frame_metrics[last_metric].areas[i].name; | 
					
						
							|  |  |  | 		frame_metrics.write[last_metric].areas.write[i].color_cache = _get_color_from_signature(name); | 
					
						
							|  |  |  | 		String full_name; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (name[0] == '<') { | 
					
						
							|  |  |  | 			stack.pop_back(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (stack.size()) { | 
					
						
							|  |  |  | 			full_name = stack.back()->get() + name; | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			full_name = name; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (name[0] == '>') { | 
					
						
							|  |  |  | 			stack.push_back(full_name + "/"); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		frame_metrics.write[last_metric].areas.write[i].fullpath_cache = full_name; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	updating_frame = true; | 
					
						
							| 
									
										
										
										
											2022-12-16 22:05:44 +06:30
										 |  |  | 	clear_button->set_disabled(false); | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 	cursor_metric_edit->set_max(frame_metrics[last_metric].frame_number); | 
					
						
							| 
									
										
										
										
											2024-02-02 16:13:32 +01:00
										 |  |  | 	cursor_metric_edit->set_min(MAX(int64_t(frame_metrics[last_metric].frame_number) - frame_metrics.size(), 0)); | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!seeking) { | 
					
						
							|  |  |  | 		cursor_metric_edit->set_value(frame_metrics[last_metric].frame_number); | 
					
						
							|  |  |  | 		if (hover_metric != -1) { | 
					
						
							|  |  |  | 			hover_metric++; | 
					
						
							|  |  |  | 			if (hover_metric >= frame_metrics.size()) { | 
					
						
							|  |  |  | 				hover_metric = 0; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	updating_frame = false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (frame_delay->is_stopped()) { | 
					
						
							|  |  |  | 		frame_delay->set_wait_time(0.1); | 
					
						
							|  |  |  | 		frame_delay->start(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (plot_delay->is_stopped()) { | 
					
						
							|  |  |  | 		plot_delay->set_wait_time(0.1); | 
					
						
							|  |  |  | 		plot_delay->start(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void EditorVisualProfiler::clear() { | 
					
						
							| 
									
										
										
										
											2022-10-18 16:43:37 +02:00
										 |  |  | 	int metric_size = EDITOR_GET("debugger/profiler_frame_history_size"); | 
					
						
							| 
									
										
										
										
											2022-05-28 01:03:32 +02:00
										 |  |  | 	metric_size = CLAMP(metric_size, 60, 10000); | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 	frame_metrics.clear(); | 
					
						
							|  |  |  | 	frame_metrics.resize(metric_size); | 
					
						
							|  |  |  | 	last_metric = -1; | 
					
						
							|  |  |  | 	variables->clear(); | 
					
						
							|  |  |  | 	//activate->set_pressed(false);
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-06 11:47:25 +10:00
										 |  |  | 	graph_limit = 1000.0f / CLAMP(int(EDITOR_GET("debugger/profiler_target_fps")), 1, 1000); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 	updating_frame = true; | 
					
						
							|  |  |  | 	cursor_metric_edit->set_min(0); | 
					
						
							|  |  |  | 	cursor_metric_edit->set_max(0); | 
					
						
							|  |  |  | 	cursor_metric_edit->set_value(0); | 
					
						
							|  |  |  | 	updating_frame = false; | 
					
						
							|  |  |  | 	hover_metric = -1; | 
					
						
							|  |  |  | 	seeking = false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | String EditorVisualProfiler::_get_time_as_text(float p_time) { | 
					
						
							|  |  |  | 	int dmode = display_mode->get_selected(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (dmode == DISPLAY_FRAME_TIME) { | 
					
						
							| 
									
										
										
										
											2023-12-14 13:54:18 -03:00
										 |  |  | 		return TS->format_number(String::num(p_time, 2)) + " " + TTR("ms"); | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 	} else if (dmode == DISPLAY_FRAME_PERCENT) { | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 		return TS->format_number(String::num(p_time * 100 / graph_limit, 2)) + " " + TS->percent_sign(); | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return "err"; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Color EditorVisualProfiler::_get_color_from_signature(const StringName &p_signature) const { | 
					
						
							| 
									
										
										
										
											2023-08-13 02:33:39 +02:00
										 |  |  | 	Color bc = get_theme_color(SNAME("error_color"), EditorStringName(Editor)); | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 	double rot = ABS(double(p_signature.hash()) / double(0x7FFFFFFF)); | 
					
						
							|  |  |  | 	Color c; | 
					
						
							|  |  |  | 	c.set_hsv(rot, bc.get_s(), bc.get_v()); | 
					
						
							| 
									
										
										
										
											2023-08-13 02:33:39 +02:00
										 |  |  | 	return c.lerp(get_theme_color(SNAME("base_color"), EditorStringName(Editor)), 0.07); | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void EditorVisualProfiler::_item_selected() { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (updating_frame) { | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	TreeItem *item = variables->get_selected(); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (!item) { | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 	selected_area = item->get_metadata(0); | 
					
						
							|  |  |  | 	_update_plot(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void EditorVisualProfiler::_update_plot() { | 
					
						
							| 
									
										
										
										
											2024-09-10 19:40:42 +02:00
										 |  |  | 	const int w = graph->get_size().width + 1; // `+1` is to prevent from crashing when visual profiler is auto started.
 | 
					
						
							|  |  |  | 	const int h = graph->get_size().height + 1; | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	bool reset_texture = false; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-04 08:18:03 +01:00
										 |  |  | 	const int desired_len = w * h * 4; | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (graph_image.size() != desired_len) { | 
					
						
							|  |  |  | 		reset_texture = true; | 
					
						
							|  |  |  | 		graph_image.resize(desired_len); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-17 18:06:54 -03:00
										 |  |  | 	uint8_t *wr = graph_image.ptrw(); | 
					
						
							| 
									
										
										
										
											2023-08-13 02:33:39 +02:00
										 |  |  | 	const Color background_color = get_theme_color("dark_color_2", EditorStringName(Editor)); | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-04 08:18:03 +01:00
										 |  |  | 	// Clear the previous frame and set the background color.
 | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 	for (int i = 0; i < desired_len; i += 4) { | 
					
						
							| 
									
										
										
										
											2022-03-04 08:18:03 +01:00
										 |  |  | 		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); | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 		wr[i + 3] = 255; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	//find highest value
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	float highest_cpu = 0; | 
					
						
							|  |  |  | 	float highest_gpu = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (int i = 0; i < frame_metrics.size(); i++) { | 
					
						
							|  |  |  | 		const Metric &m = frame_metrics[i]; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		if (!m.valid) { | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 			continue; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (m.areas.size()) { | 
					
						
							|  |  |  | 			highest_cpu = MAX(highest_cpu, m.areas[m.areas.size() - 1].cpu_time); | 
					
						
							|  |  |  | 			highest_gpu = MAX(highest_gpu, m.areas[m.areas.size() - 1].gpu_time); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (highest_cpu > 0 || highest_gpu > 0) { | 
					
						
							|  |  |  | 		if (frame_relative->is_pressed()) { | 
					
						
							|  |  |  | 			highest_cpu = MAX(graph_limit, highest_cpu); | 
					
						
							|  |  |  | 			highest_gpu = MAX(graph_limit, highest_gpu); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (linked->is_pressed()) { | 
					
						
							|  |  |  | 			float highest = MAX(highest_cpu, highest_gpu); | 
					
						
							|  |  |  | 			highest_cpu = highest_gpu = highest; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		//means some data exists..
 | 
					
						
							|  |  |  | 		highest_cpu *= 1.2; //leave some upper room
 | 
					
						
							|  |  |  | 		highest_gpu *= 1.2; //leave some upper room
 | 
					
						
							|  |  |  | 		graph_height_cpu = highest_cpu; | 
					
						
							|  |  |  | 		graph_height_gpu = highest_gpu; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		Vector<Color> columnv_cpu; | 
					
						
							|  |  |  | 		columnv_cpu.resize(h); | 
					
						
							|  |  |  | 		Color *column_cpu = columnv_cpu.ptrw(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		Vector<Color> columnv_gpu; | 
					
						
							|  |  |  | 		columnv_gpu.resize(h); | 
					
						
							|  |  |  | 		Color *column_gpu = columnv_gpu.ptrw(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		int half_w = w / 2; | 
					
						
							|  |  |  | 		for (int i = 0; i < half_w; i++) { | 
					
						
							|  |  |  | 			for (int j = 0; j < h; j++) { | 
					
						
							|  |  |  | 				column_cpu[j] = Color(0, 0, 0, 0); | 
					
						
							|  |  |  | 				column_gpu[j] = Color(0, 0, 0, 0); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			int current = i * frame_metrics.size() / half_w; | 
					
						
							|  |  |  | 			int next = (i + 1) * frame_metrics.size() / half_w; | 
					
						
							|  |  |  | 			if (next > frame_metrics.size()) { | 
					
						
							|  |  |  | 				next = frame_metrics.size(); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			if (next == current) { | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 				next = current + 1; //just because for loop must work
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			for (int j = current; j < next; j++) { | 
					
						
							|  |  |  | 				//wrap
 | 
					
						
							|  |  |  | 				int idx = last_metric + 1 + j; | 
					
						
							|  |  |  | 				while (idx >= frame_metrics.size()) { | 
					
						
							|  |  |  | 					idx -= frame_metrics.size(); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				int area_count = frame_metrics[idx].areas.size(); | 
					
						
							|  |  |  | 				const Metric::Area *areas = frame_metrics[idx].areas.ptr(); | 
					
						
							|  |  |  | 				int prev_cpu = 0; | 
					
						
							|  |  |  | 				int prev_gpu = 0; | 
					
						
							|  |  |  | 				for (int k = 1; k < area_count; k++) { | 
					
						
							|  |  |  | 					int ofs_cpu = int(areas[k].cpu_time * h / highest_cpu); | 
					
						
							|  |  |  | 					ofs_cpu = CLAMP(ofs_cpu, 0, h - 1); | 
					
						
							|  |  |  | 					Color color = selected_area == areas[k - 1].fullpath_cache ? Color(1, 1, 1, 1) : areas[k - 1].color_cache; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					for (int l = prev_cpu; l < ofs_cpu; l++) { | 
					
						
							|  |  |  | 						column_cpu[h - l - 1] += color; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					prev_cpu = ofs_cpu; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					int ofs_gpu = int(areas[k].gpu_time * h / highest_gpu); | 
					
						
							|  |  |  | 					ofs_gpu = CLAMP(ofs_gpu, 0, h - 1); | 
					
						
							|  |  |  | 					for (int l = prev_gpu; l < ofs_gpu; l++) { | 
					
						
							|  |  |  | 						column_gpu[h - l - 1] += color; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					prev_gpu = ofs_gpu; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			//plot CPU
 | 
					
						
							|  |  |  | 			for (int j = 0; j < h; j++) { | 
					
						
							|  |  |  | 				uint8_t r, g, b; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				if (column_cpu[j].a == 0) { | 
					
						
							| 
									
										
										
										
											2022-03-04 08:18:03 +01:00
										 |  |  | 					r = Math::fast_ftoi(background_color.r * 255); | 
					
						
							|  |  |  | 					g = Math::fast_ftoi(background_color.g * 255); | 
					
						
							|  |  |  | 					b = Math::fast_ftoi(background_color.b * 255); | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 				} else { | 
					
						
							|  |  |  | 					r = CLAMP((column_cpu[j].r / column_cpu[j].a) * 255.0, 0, 255); | 
					
						
							|  |  |  | 					g = CLAMP((column_cpu[j].g / column_cpu[j].a) * 255.0, 0, 255); | 
					
						
							|  |  |  | 					b = CLAMP((column_cpu[j].b / column_cpu[j].a) * 255.0, 0, 255); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				int widx = (j * w + i) * 4; | 
					
						
							|  |  |  | 				wr[widx + 0] = r; | 
					
						
							|  |  |  | 				wr[widx + 1] = g; | 
					
						
							|  |  |  | 				wr[widx + 2] = b; | 
					
						
							|  |  |  | 				wr[widx + 3] = 255; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			//plot GPU
 | 
					
						
							|  |  |  | 			for (int j = 0; j < h; j++) { | 
					
						
							|  |  |  | 				uint8_t r, g, b; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				if (column_gpu[j].a == 0) { | 
					
						
							| 
									
										
										
										
											2022-03-04 08:18:03 +01:00
										 |  |  | 					r = Math::fast_ftoi(background_color.r * 255); | 
					
						
							|  |  |  | 					g = Math::fast_ftoi(background_color.g * 255); | 
					
						
							|  |  |  | 					b = Math::fast_ftoi(background_color.b * 255); | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 				} else { | 
					
						
							|  |  |  | 					r = CLAMP((column_gpu[j].r / column_gpu[j].a) * 255.0, 0, 255); | 
					
						
							|  |  |  | 					g = CLAMP((column_gpu[j].g / column_gpu[j].a) * 255.0, 0, 255); | 
					
						
							|  |  |  | 					b = CLAMP((column_gpu[j].b / column_gpu[j].a) * 255.0, 0, 255); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				int widx = (j * w + w / 2 + i) * 4; | 
					
						
							|  |  |  | 				wr[widx + 0] = r; | 
					
						
							|  |  |  | 				wr[widx + 1] = g; | 
					
						
							|  |  |  | 				wr[widx + 2] = b; | 
					
						
							|  |  |  | 				wr[widx + 3] = 255; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-22 20:06:19 +02:00
										 |  |  | 	Ref<Image> img = Image::create_from_data(w, h, false, Image::FORMAT_RGBA8, graph_image); | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (reset_texture) { | 
					
						
							|  |  |  | 		if (graph_texture.is_null()) { | 
					
						
							| 
									
										
										
										
											2021-06-17 16:03:09 -06:00
										 |  |  | 			graph_texture.instantiate(); | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2022-05-04 01:49:20 +02:00
										 |  |  | 		graph_texture->set_image(img); | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-30 23:17:47 -03:00
										 |  |  | 	graph_texture->update(img); | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	graph->set_texture(graph_texture); | 
					
						
							| 
									
										
										
										
											2022-08-13 23:21:24 +02:00
										 |  |  | 	graph->queue_redraw(); | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void EditorVisualProfiler::_update_frame(bool p_focus_selected) { | 
					
						
							|  |  |  | 	int cursor_metric = _get_cursor_index(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-13 02:33:39 +02:00
										 |  |  | 	Ref<Texture> track_icon = get_editor_theme_icon(SNAME("TrackColor")); | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	ERR_FAIL_INDEX(cursor_metric, frame_metrics.size()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	updating_frame = true; | 
					
						
							|  |  |  | 	variables->clear(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	TreeItem *root = variables->create_item(); | 
					
						
							|  |  |  | 	const Metric &m = frame_metrics[cursor_metric]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	List<TreeItem *> stack; | 
					
						
							|  |  |  | 	List<TreeItem *> categories; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	TreeItem *ensure_selected = nullptr; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (int i = 1; i < m.areas.size() - 1; i++) { | 
					
						
							|  |  |  | 		TreeItem *parent = stack.size() ? stack.back()->get() : root; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		String name = m.areas[i].name; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		float cpu_time = m.areas[i].cpu_time; | 
					
						
							|  |  |  | 		float gpu_time = m.areas[i].gpu_time; | 
					
						
							|  |  |  | 		if (i < m.areas.size() - 1) { | 
					
						
							|  |  |  | 			cpu_time = m.areas[i + 1].cpu_time - cpu_time; | 
					
						
							|  |  |  | 			gpu_time = m.areas[i + 1].gpu_time - gpu_time; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (name.begins_with(">")) { | 
					
						
							|  |  |  | 			TreeItem *category = variables->create_item(parent); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			stack.push_back(category); | 
					
						
							|  |  |  | 			categories.push_back(category); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			name = name.substr(1, name.length()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			category->set_text(0, name); | 
					
						
							|  |  |  | 			category->set_metadata(1, cpu_time); | 
					
						
							|  |  |  | 			category->set_metadata(2, gpu_time); | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (name.begins_with("<")) { | 
					
						
							|  |  |  | 			stack.pop_back(); | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		TreeItem *category = variables->create_item(parent); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-15 23:45:57 -04:00
										 |  |  | 		for (TreeItem *E : stack) { | 
					
						
							|  |  |  | 			float total_cpu = E->get_metadata(1); | 
					
						
							|  |  |  | 			float total_gpu = E->get_metadata(2); | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 			total_cpu += cpu_time; | 
					
						
							|  |  |  | 			total_gpu += gpu_time; | 
					
						
							| 
									
										
										
										
											2021-10-14 08:55:54 -07:00
										 |  |  | 			E->set_metadata(1, total_cpu); | 
					
						
							|  |  |  | 			E->set_metadata(2, total_gpu); | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		category->set_icon(0, track_icon); | 
					
						
							|  |  |  | 		category->set_icon_modulate(0, m.areas[i].color_cache); | 
					
						
							|  |  |  | 		category->set_selectable(0, true); | 
					
						
							|  |  |  | 		category->set_metadata(0, m.areas[i].fullpath_cache); | 
					
						
							|  |  |  | 		category->set_text(0, m.areas[i].name); | 
					
						
							|  |  |  | 		category->set_text(1, _get_time_as_text(cpu_time)); | 
					
						
							|  |  |  | 		category->set_metadata(1, m.areas[i].cpu_time); | 
					
						
							|  |  |  | 		category->set_text(2, _get_time_as_text(gpu_time)); | 
					
						
							|  |  |  | 		category->set_metadata(2, m.areas[i].gpu_time); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (selected_area == m.areas[i].fullpath_cache) { | 
					
						
							|  |  |  | 			category->select(0); | 
					
						
							|  |  |  | 			if (p_focus_selected) { | 
					
						
							|  |  |  | 				ensure_selected = category; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-15 23:45:57 -04:00
										 |  |  | 	for (TreeItem *E : categories) { | 
					
						
							|  |  |  | 		float total_cpu = E->get_metadata(1); | 
					
						
							|  |  |  | 		float total_gpu = E->get_metadata(2); | 
					
						
							|  |  |  | 		E->set_text(1, _get_time_as_text(total_cpu)); | 
					
						
							|  |  |  | 		E->set_text(2, _get_time_as_text(total_gpu)); | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (ensure_selected) { | 
					
						
							|  |  |  | 		variables->ensure_cursor_is_visible(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	updating_frame = false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void EditorVisualProfiler::_activate_pressed() { | 
					
						
							|  |  |  | 	if (activate->is_pressed()) { | 
					
						
							| 
									
										
										
										
											2024-10-09 15:21:47 -07:00
										 |  |  | 		activate->set_button_icon(get_editor_theme_icon(SNAME("Stop"))); | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 		activate->set_text(TTR("Stop")); | 
					
						
							|  |  |  | 		_clear_pressed(); //always clear on start
 | 
					
						
							| 
									
										
										
										
											2022-12-16 22:05:44 +06:30
										 |  |  | 		clear_button->set_disabled(false); | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2024-10-09 15:21:47 -07:00
										 |  |  | 		activate->set_button_icon(get_editor_theme_icon(SNAME("Play"))); | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 		activate->set_text(TTR("Start")); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 	emit_signal(SNAME("enable_profiling"), activate->is_pressed()); | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void EditorVisualProfiler::_clear_pressed() { | 
					
						
							| 
									
										
										
										
											2022-12-16 22:05:44 +06:30
										 |  |  | 	clear_button->set_disabled(true); | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 	clear(); | 
					
						
							|  |  |  | 	_update_plot(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-10 19:40:42 +02:00
										 |  |  | void EditorVisualProfiler::_autostart_toggled(bool p_toggled_on) { | 
					
						
							|  |  |  | 	EditorSettings::get_singleton()->set_project_metadata("debug_options", "autostart_visual_profiler", p_toggled_on); | 
					
						
							| 
									
										
										
										
											2024-09-26 16:31:00 +02:00
										 |  |  | 	EditorRunBar::get_singleton()->update_profiler_autostart_indicator(); | 
					
						
							| 
									
										
										
										
											2024-09-10 19:40:42 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | void EditorVisualProfiler::_notification(int p_what) { | 
					
						
							| 
									
										
										
										
											2022-02-16 00:52:32 +01:00
										 |  |  | 	switch (p_what) { | 
					
						
							| 
									
										
										
										
											2022-08-29 11:04:31 +02:00
										 |  |  | 		case NOTIFICATION_ENTER_TREE: | 
					
						
							| 
									
										
										
										
											2022-02-16 00:52:32 +01:00
										 |  |  | 		case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: | 
					
						
							| 
									
										
										
										
											2022-08-29 11:04:31 +02:00
										 |  |  | 		case NOTIFICATION_THEME_CHANGED: | 
					
						
							|  |  |  | 		case NOTIFICATION_TRANSLATION_CHANGED: { | 
					
						
							| 
									
										
										
										
											2024-10-09 15:21:47 -07:00
										 |  |  | 			activate->set_button_icon(get_editor_theme_icon(SNAME("Play"))); | 
					
						
							|  |  |  | 			clear_button->set_button_icon(get_editor_theme_icon(SNAME("Clear"))); | 
					
						
							| 
									
										
										
										
											2022-02-16 00:52:32 +01:00
										 |  |  | 		} break; | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void EditorVisualProfiler::_graph_tex_draw() { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (last_metric < 0) { | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-03-04 09:37:40 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-14 15:57:29 +02:00
										 |  |  | 	Ref<Font> font = get_theme_font(SceneStringName(font), SNAME("Label")); | 
					
						
							|  |  |  | 	int font_size = get_theme_font_size(SceneStringName(font_size), SNAME("Label")); | 
					
						
							|  |  |  | 	const Color color = get_theme_color(SceneStringName(font_color), EditorStringName(Editor)); | 
					
						
							| 
									
										
										
										
											2022-03-04 09:37:40 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 	if (seeking) { | 
					
						
							|  |  |  | 		int max_frames = frame_metrics.size(); | 
					
						
							|  |  |  | 		int frame = cursor_metric_edit->get_value() - (frame_metrics[last_metric].frame_number - max_frames + 1); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		if (frame < 0) { | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 			frame = 0; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		int half_width = graph->get_size().x / 2; | 
					
						
							|  |  |  | 		int cur_x = frame * half_width / max_frames; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-04 09:37:40 +01:00
										 |  |  | 		graph->draw_line(Vector2(cur_x, 0), Vector2(cur_x, graph->get_size().y), color * Color(1, 1, 1)); | 
					
						
							|  |  |  | 		graph->draw_line(Vector2(cur_x + half_width, 0), Vector2(cur_x + half_width, graph->get_size().y), color * Color(1, 1, 1)); | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (graph_height_cpu > 0) { | 
					
						
							|  |  |  | 		int frame_y = graph->get_size().y - graph_limit * graph->get_size().y / graph_height_cpu - 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		int half_width = graph->get_size().x / 2; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-04 09:37:40 +01:00
										 |  |  | 		graph->draw_line(Vector2(0, frame_y), Vector2(half_width, frame_y), color * Color(1, 1, 1, 0.5)); | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-04 09:37:40 +01:00
										 |  |  | 		const String limit_str = String::num(graph_limit, 2) + " ms"; | 
					
						
							| 
									
										
										
										
											2022-05-09 12:47:10 +03:00
										 |  |  | 		graph->draw_string(font, Vector2(half_width - font->get_string_size(limit_str, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size).x - 2, frame_y - 2), limit_str, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, color * Color(1, 1, 1, 0.75)); | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (graph_height_gpu > 0) { | 
					
						
							|  |  |  | 		int frame_y = graph->get_size().y - graph_limit * graph->get_size().y / graph_height_gpu - 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		int half_width = graph->get_size().x / 2; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-04 09:37:40 +01:00
										 |  |  | 		graph->draw_line(Vector2(half_width, frame_y), Vector2(graph->get_size().x, frame_y), color * Color(1, 1, 1, 0.5)); | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-04 09:37:40 +01:00
										 |  |  | 		const String limit_str = String::num(graph_limit, 2) + " ms"; | 
					
						
							| 
									
										
										
										
											2022-05-09 12:47:10 +03:00
										 |  |  | 		graph->draw_string(font, Vector2(half_width * 2 - font->get_string_size(limit_str, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size).x - 2, frame_y - 2), limit_str, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, color * Color(1, 1, 1, 0.75)); | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-11 19:51:54 +01:00
										 |  |  | 	graph->draw_string(font, Vector2(font->get_string_size("X", HORIZONTAL_ALIGNMENT_LEFT, -1, font_size).x, font->get_ascent(font_size) + 2), "CPU: " + cpu_name, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, color * Color(1, 1, 1, 0.75)); | 
					
						
							|  |  |  | 	graph->draw_string(font, Vector2(font->get_string_size("X", HORIZONTAL_ALIGNMENT_LEFT, -1, font_size).x + graph->get_size().width / 2, font->get_ascent(font_size) + 2), "GPU: " + gpu_name, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, color * Color(1, 1, 1, 0.75)); | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void EditorVisualProfiler::_graph_tex_mouse_exit() { | 
					
						
							|  |  |  | 	hover_metric = -1; | 
					
						
							| 
									
										
										
										
											2022-08-13 23:21:24 +02:00
										 |  |  | 	graph->queue_redraw(); | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void EditorVisualProfiler::_cursor_metric_changed(double) { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (updating_frame) { | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-13 23:21:24 +02:00
										 |  |  | 	graph->queue_redraw(); | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 	_update_frame(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void EditorVisualProfiler::_graph_tex_input(const Ref<InputEvent> &p_ev) { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (last_metric < 0) { | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	Ref<InputEventMouse> me = p_ev; | 
					
						
							|  |  |  | 	Ref<InputEventMouseButton> mb = p_ev; | 
					
						
							|  |  |  | 	Ref<InputEventMouseMotion> mm = p_ev; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if ( | 
					
						
							| 
									
										
										
										
											2021-08-13 16:31:57 -05:00
										 |  |  | 			(mb.is_valid() && mb->get_button_index() == MouseButton::LEFT && mb->is_pressed()) || | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 			(mm.is_valid())) { | 
					
						
							|  |  |  | 		int half_w = graph->get_size().width / 2; | 
					
						
							|  |  |  | 		int x = me->get_position().x; | 
					
						
							|  |  |  | 		if (x > half_w) { | 
					
						
							|  |  |  | 			x -= half_w; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		x = x * frame_metrics.size() / half_w; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		bool show_hover = x >= 0 && x < frame_metrics.size(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (x < 0) { | 
					
						
							|  |  |  | 			x = 0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (x >= frame_metrics.size()) { | 
					
						
							|  |  |  | 			x = frame_metrics.size() - 1; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		int metric = frame_metrics.size() - x - 1; | 
					
						
							|  |  |  | 		metric = last_metric - metric; | 
					
						
							|  |  |  | 		while (metric < 0) { | 
					
						
							|  |  |  | 			metric += frame_metrics.size(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (show_hover) { | 
					
						
							|  |  |  | 			hover_metric = metric; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			hover_metric = -1; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-08 00:55:54 +01:00
										 |  |  | 		if (mb.is_valid() || mm->get_button_mask().has_flag(MouseButtonMask::LEFT)) { | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 			//cursor_metric=x;
 | 
					
						
							|  |  |  | 			updating_frame = true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			//metric may be invalid, so look for closest metric that is valid, this makes snap feel better
 | 
					
						
							|  |  |  | 			bool valid = false; | 
					
						
							|  |  |  | 			for (int i = 0; i < frame_metrics.size(); i++) { | 
					
						
							|  |  |  | 				if (frame_metrics[metric].valid) { | 
					
						
							|  |  |  | 					valid = true; | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				metric++; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 				if (metric >= frame_metrics.size()) { | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 					metric = 0; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (!valid) { | 
					
						
							|  |  |  | 				return; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			cursor_metric_edit->set_value(frame_metrics[metric].frame_number); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			updating_frame = false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (activate->is_pressed()) { | 
					
						
							|  |  |  | 				if (!seeking) { | 
					
						
							| 
									
										
										
										
											2020-02-19 15:22:34 -06:00
										 |  |  | 					// Break request is not required, just stop profiling
 | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			seeking = true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (!frame_delay->is_processing()) { | 
					
						
							|  |  |  | 				frame_delay->set_wait_time(0.1); | 
					
						
							|  |  |  | 				frame_delay->start(); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			bool touched_cpu = me->get_position().x < graph->get_size().width * 0.5; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			const Metric::Area *areas = frame_metrics[metric].areas.ptr(); | 
					
						
							|  |  |  | 			int area_count = frame_metrics[metric].areas.size(); | 
					
						
							|  |  |  | 			float posy = (1.0 - (me->get_position().y / graph->get_size().height)) * (touched_cpu ? graph_height_cpu : graph_height_gpu); | 
					
						
							|  |  |  | 			int last_valid = -1; | 
					
						
							|  |  |  | 			bool found = false; | 
					
						
							|  |  |  | 			for (int i = 0; i < area_count - 1; i++) { | 
					
						
							|  |  |  | 				if (areas[i].name[0] != '<' && areas[i].name[0] != '>') { | 
					
						
							|  |  |  | 					last_valid = i; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				float h = touched_cpu ? areas[i + 1].cpu_time : areas[i + 1].gpu_time; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				if (h > posy) { | 
					
						
							|  |  |  | 					found = true; | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			StringName area_found; | 
					
						
							|  |  |  | 			if (found && last_valid != -1) { | 
					
						
							|  |  |  | 				area_found = areas[last_valid].fullpath_cache; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (area_found != selected_area) { | 
					
						
							|  |  |  | 				selected_area = area_found; | 
					
						
							|  |  |  | 				_update_frame(true); | 
					
						
							|  |  |  | 				_update_plot(); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-13 23:21:24 +02:00
										 |  |  | 		graph->queue_redraw(); | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int EditorVisualProfiler::_get_cursor_index() const { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (last_metric < 0) { | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 		return 0; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	if (!frame_metrics[last_metric].valid) { | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 		return 0; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	int diff = (frame_metrics[last_metric].frame_number - cursor_metric_edit->get_value()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	int idx = last_metric - diff; | 
					
						
							|  |  |  | 	while (idx < 0) { | 
					
						
							|  |  |  | 		idx += frame_metrics.size(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return idx; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void EditorVisualProfiler::disable_seeking() { | 
					
						
							|  |  |  | 	seeking = false; | 
					
						
							| 
									
										
										
										
											2022-08-13 23:21:24 +02:00
										 |  |  | 	graph->queue_redraw(); | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void EditorVisualProfiler::_combo_changed(int) { | 
					
						
							|  |  |  | 	_update_frame(); | 
					
						
							|  |  |  | 	_update_plot(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void EditorVisualProfiler::_bind_methods() { | 
					
						
							|  |  |  | 	ADD_SIGNAL(MethodInfo("enable_profiling", PropertyInfo(Variant::BOOL, "enable"))); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-16 22:05:44 +06:30
										 |  |  | void EditorVisualProfiler::_update_button_text() { | 
					
						
							|  |  |  | 	if (activate->is_pressed()) { | 
					
						
							| 
									
										
										
										
											2024-10-09 15:21:47 -07:00
										 |  |  | 		activate->set_button_icon(get_editor_theme_icon(SNAME("Stop"))); | 
					
						
							| 
									
										
										
										
											2022-12-16 22:05:44 +06:30
										 |  |  | 		activate->set_text(TTR("Stop")); | 
					
						
							|  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2024-10-09 15:21:47 -07:00
										 |  |  | 		activate->set_button_icon(get_editor_theme_icon(SNAME("Play"))); | 
					
						
							| 
									
										
										
										
											2022-12-16 22:05:44 +06:30
										 |  |  | 		activate->set_text(TTR("Start")); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | void EditorVisualProfiler::set_enabled(bool p_enable) { | 
					
						
							|  |  |  | 	activate->set_disabled(!p_enable); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-10 19:40:42 +02:00
										 |  |  | void EditorVisualProfiler::set_profiling(bool p_profiling) { | 
					
						
							|  |  |  | 	activate->set_pressed(p_profiling); | 
					
						
							| 
									
										
										
										
											2022-12-16 22:05:44 +06:30
										 |  |  | 	_update_button_text(); | 
					
						
							| 
									
										
										
										
											2024-09-10 19:40:42 +02:00
										 |  |  | 	emit_signal(SNAME("enable_profiling"), activate->is_pressed()); | 
					
						
							| 
									
										
										
										
											2022-12-16 22:05:44 +06:30
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | bool EditorVisualProfiler::is_profiling() { | 
					
						
							|  |  |  | 	return activate->is_pressed(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-17 07:33:00 +01:00
										 |  |  | Vector<Vector<String>> EditorVisualProfiler::get_data_as_csv() const { | 
					
						
							|  |  |  | 	Vector<Vector<String>> res; | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | #if 0
 | 
					
						
							| 
									
										
										
										
											2020-12-29 09:54:59 +01:00
										 |  |  | 	if (frame_metrics.is_empty()) { | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 		return res; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// signatures
 | 
					
						
							|  |  |  | 	Vector<String> signatures; | 
					
						
							|  |  |  | 	const Vector<EditorFrameProfiler::Metric::Category> &categories = frame_metrics[0].categories; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (int j = 0; j < categories.size(); j++) { | 
					
						
							|  |  |  | 		const EditorFrameProfiler::Metric::Category &c = categories[j]; | 
					
						
							|  |  |  | 		signatures.push_back(c.signature); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for (int k = 0; k < c.items.size(); k++) { | 
					
						
							|  |  |  | 			signatures.push_back(c.items[k].signature); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	res.push_back(signatures); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// values
 | 
					
						
							|  |  |  | 	Vector<String> values; | 
					
						
							|  |  |  | 	values.resize(signatures.size()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	int index = last_metric; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (int i = 0; i < frame_metrics.size(); i++) { | 
					
						
							|  |  |  | 		++index; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (index >= frame_metrics.size()) { | 
					
						
							|  |  |  | 			index = 0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (!frame_metrics[index].valid) { | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		int it = 0; | 
					
						
							|  |  |  | 		const Vector<EditorFrameProfiler::Metric::Category> &frame_cat = frame_metrics[index].categories; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for (int j = 0; j < frame_cat.size(); j++) { | 
					
						
							|  |  |  | 			const EditorFrameProfiler::Metric::Category &c = frame_cat[j]; | 
					
						
							|  |  |  | 			values.write[it++] = String::num_real(c.total_time); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			for (int k = 0; k < c.items.size(); k++) { | 
					
						
							|  |  |  | 				values.write[it++] = String::num_real(c.items[k].total); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		res.push_back(values); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 	return res; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | EditorVisualProfiler::EditorVisualProfiler() { | 
					
						
							|  |  |  | 	HBoxContainer *hb = memnew(HBoxContainer); | 
					
						
							|  |  |  | 	add_child(hb); | 
					
						
							|  |  |  | 	activate = memnew(Button); | 
					
						
							|  |  |  | 	activate->set_toggle_mode(true); | 
					
						
							| 
									
										
										
										
											2022-12-16 22:05:44 +06:30
										 |  |  | 	activate->set_disabled(true); | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 	activate->set_text(TTR("Start")); | 
					
						
							| 
									
										
										
										
											2024-05-14 09:40:21 +02:00
										 |  |  | 	activate->connect(SceneStringName(pressed), callable_mp(this, &EditorVisualProfiler::_activate_pressed)); | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 	hb->add_child(activate); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	clear_button = memnew(Button); | 
					
						
							|  |  |  | 	clear_button->set_text(TTR("Clear")); | 
					
						
							| 
									
										
										
										
											2022-12-16 22:05:44 +06:30
										 |  |  | 	clear_button->set_disabled(true); | 
					
						
							| 
									
										
										
										
											2024-05-14 09:40:21 +02:00
										 |  |  | 	clear_button->connect(SceneStringName(pressed), callable_mp(this, &EditorVisualProfiler::_clear_pressed)); | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 	hb->add_child(clear_button); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-10 19:40:42 +02:00
										 |  |  | 	CheckBox *autostart_checkbox = memnew(CheckBox); | 
					
						
							|  |  |  | 	autostart_checkbox->set_text(TTR("Autostart")); | 
					
						
							|  |  |  | 	autostart_checkbox->set_pressed(EditorSettings::get_singleton()->get_project_metadata("debug_options", "autostart_visual_profiler", false)); | 
					
						
							|  |  |  | 	autostart_checkbox->connect(SceneStringName(toggled), callable_mp(this, &EditorVisualProfiler::_autostart_toggled)); | 
					
						
							|  |  |  | 	hb->add_child(autostart_checkbox); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 	hb->add_child(memnew(Label(TTR("Measure:")))); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	display_mode = memnew(OptionButton); | 
					
						
							| 
									
										
										
										
											2022-03-04 08:50:41 +01:00
										 |  |  | 	display_mode->add_item(TTR("Frame Time (ms)")); | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 	display_mode->add_item(TTR("Frame %")); | 
					
						
							| 
									
										
										
										
											2024-05-14 14:21:31 +02:00
										 |  |  | 	display_mode->connect(SceneStringName(item_selected), callable_mp(this, &EditorVisualProfiler::_combo_changed)); | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	hb->add_child(display_mode); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	frame_relative = memnew(CheckBox(TTR("Fit to Frame"))); | 
					
						
							|  |  |  | 	frame_relative->set_pressed(true); | 
					
						
							|  |  |  | 	hb->add_child(frame_relative); | 
					
						
							| 
									
										
										
										
											2024-05-14 09:40:21 +02:00
										 |  |  | 	frame_relative->connect(SceneStringName(pressed), callable_mp(this, &EditorVisualProfiler::_update_plot)); | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 	linked = memnew(CheckBox(TTR("Linked"))); | 
					
						
							|  |  |  | 	linked->set_pressed(true); | 
					
						
							|  |  |  | 	hb->add_child(linked); | 
					
						
							| 
									
										
										
										
											2024-05-14 09:40:21 +02:00
										 |  |  | 	linked->connect(SceneStringName(pressed), callable_mp(this, &EditorVisualProfiler::_update_plot)); | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	hb->add_spacer(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	hb->add_child(memnew(Label(TTR("Frame #:")))); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	cursor_metric_edit = memnew(SpinBox); | 
					
						
							|  |  |  | 	cursor_metric_edit->set_h_size_flags(SIZE_FILL); | 
					
						
							|  |  |  | 	hb->add_child(cursor_metric_edit); | 
					
						
							| 
									
										
										
										
											2024-05-14 11:42:00 +02:00
										 |  |  | 	cursor_metric_edit->connect(SceneStringName(value_changed), callable_mp(this, &EditorVisualProfiler::_cursor_metric_changed)); | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-08 10:14:58 +01:00
										 |  |  | 	hb->add_theme_constant_override("separation", 8 * EDSCALE); | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	h_split = memnew(HSplitContainer); | 
					
						
							|  |  |  | 	add_child(h_split); | 
					
						
							|  |  |  | 	h_split->set_v_size_flags(SIZE_EXPAND_FILL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	variables = memnew(Tree); | 
					
						
							|  |  |  | 	variables->set_custom_minimum_size(Size2(300, 0) * EDSCALE); | 
					
						
							|  |  |  | 	variables->set_hide_folding(true); | 
					
						
							|  |  |  | 	h_split->add_child(variables); | 
					
						
							|  |  |  | 	variables->set_hide_root(true); | 
					
						
							|  |  |  | 	variables->set_columns(3); | 
					
						
							|  |  |  | 	variables->set_column_titles_visible(true); | 
					
						
							|  |  |  | 	variables->set_column_title(0, TTR("Name")); | 
					
						
							|  |  |  | 	variables->set_column_expand(0, true); | 
					
						
							| 
									
										
										
										
											2021-07-04 00:13:28 -03:00
										 |  |  | 	variables->set_column_clip_content(0, true); | 
					
						
							| 
									
										
										
										
											2021-06-28 15:40:56 +02:00
										 |  |  | 	variables->set_column_custom_minimum_width(0, 60); | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 	variables->set_column_title(1, TTR("CPU")); | 
					
						
							|  |  |  | 	variables->set_column_expand(1, false); | 
					
						
							| 
									
										
										
										
											2021-07-04 00:13:28 -03:00
										 |  |  | 	variables->set_column_clip_content(1, true); | 
					
						
							| 
									
										
										
										
											2023-06-03 11:47:59 +02:00
										 |  |  | 	variables->set_column_custom_minimum_width(1, 75 * EDSCALE); | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 	variables->set_column_title(2, TTR("GPU")); | 
					
						
							|  |  |  | 	variables->set_column_expand(2, false); | 
					
						
							| 
									
										
										
										
											2021-07-04 00:13:28 -03:00
										 |  |  | 	variables->set_column_clip_content(2, true); | 
					
						
							| 
									
										
										
										
											2023-06-03 11:47:59 +02:00
										 |  |  | 	variables->set_column_custom_minimum_width(2, 75 * EDSCALE); | 
					
						
							| 
									
										
										
										
											2024-10-06 17:10:05 +04:00
										 |  |  | 	variables->set_theme_type_variation("TreeSecondary"); | 
					
						
							| 
									
										
										
										
											2020-02-21 18:28:45 +01:00
										 |  |  | 	variables->connect("cell_selected", callable_mp(this, &EditorVisualProfiler::_item_selected)); | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	graph = memnew(TextureRect); | 
					
						
							| 
									
										
										
										
											2024-11-12 12:35:41 +02:00
										 |  |  | 	graph->set_custom_minimum_size(Size2(250 * EDSCALE, 0)); | 
					
						
							| 
									
										
										
										
											2022-02-25 01:19:24 +01:00
										 |  |  | 	graph->set_expand_mode(TextureRect::EXPAND_IGNORE_SIZE); | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 	graph->set_mouse_filter(MOUSE_FILTER_STOP); | 
					
						
							| 
									
										
										
										
											2024-05-13 16:56:03 +02:00
										 |  |  | 	graph->connect(SceneStringName(draw), callable_mp(this, &EditorVisualProfiler::_graph_tex_draw)); | 
					
						
							|  |  |  | 	graph->connect(SceneStringName(gui_input), callable_mp(this, &EditorVisualProfiler::_graph_tex_input)); | 
					
						
							|  |  |  | 	graph->connect(SceneStringName(mouse_exited), callable_mp(this, &EditorVisualProfiler::_graph_tex_mouse_exit)); | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	h_split->add_child(graph); | 
					
						
							|  |  |  | 	graph->set_h_size_flags(SIZE_EXPAND_FILL); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-28 01:03:32 +02:00
										 |  |  | 	int metric_size = CLAMP(int(EDITOR_GET("debugger/profiler_frame_history_size")), 60, 10000); | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 	frame_metrics.resize(metric_size); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-06 11:47:25 +10:00
										 |  |  | 	graph_limit = 1000.0f / CLAMP(int(EDITOR_GET("debugger/profiler_target_fps")), 1, 1000); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 	frame_delay = memnew(Timer); | 
					
						
							|  |  |  | 	frame_delay->set_wait_time(0.1); | 
					
						
							|  |  |  | 	frame_delay->set_one_shot(true); | 
					
						
							|  |  |  | 	add_child(frame_delay); | 
					
						
							| 
									
										
										
										
											2022-07-28 22:56:41 +02:00
										 |  |  | 	frame_delay->connect("timeout", callable_mp(this, &EditorVisualProfiler::_update_frame).bind(false)); | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	plot_delay = memnew(Timer); | 
					
						
							|  |  |  | 	plot_delay->set_wait_time(0.1); | 
					
						
							|  |  |  | 	plot_delay->set_one_shot(true); | 
					
						
							|  |  |  | 	add_child(plot_delay); | 
					
						
							| 
									
										
										
										
											2020-02-21 18:28:45 +01:00
										 |  |  | 	plot_delay->connect("timeout", callable_mp(this, &EditorVisualProfiler::_update_plot)); | 
					
						
							| 
									
										
										
										
											2019-09-20 17:58:06 -03:00
										 |  |  | } |