<commit_before>#include "editor_profiler.h"
#include "editor_settings.h"
#include "os/os.h"

void EditorProfiler::_make_metric_ptrs(Metric& m) {

	for(int i=0;i<m.categories.size();i++) {
		m.category_ptrs[m.categories[i].signature]=&m.categories[i];
		for(int j=0;j<m.categories[i].items.size();j++) {
			m.item_ptrs[m.categories[i].items[j].signature]=&m.categories[i].items[j];
		}
	}
}

void EditorProfiler::add_frame_metric(const Metric& p_metric,bool p_final) {

	++last_metric;
	if (last_metric>=frame_metrics.size())
		last_metric=0;


	frame_metrics[last_metric]=p_metric;
	_make_metric_ptrs(frame_metrics[last_metric]);

	updating_frame=true;
	cursor_metric_edit->set_max(frame_metrics[last_metric].frame_number);
	cursor_metric_edit->set_min(MAX(frame_metrics[last_metric].frame_number-frame_metrics.size(),0));


	if (!seeking) {
		cursor_metric_edit->set_val(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_processing()) {

		frame_delay->set_wait_time(p_final?0.1:1);
		frame_delay->start();
	}

	if (!plot_delay->is_processing()) {
		plot_delay->set_wait_time(0.1);
		plot_delay->start();
	}

}



void EditorProfiler::clear() {

	int metric_size=EditorSettings::get_singleton()->get("debugger/profiler_frame_history_size");
	metric_size = CLAMP(metric_size,60,1024);
	frame_metrics.clear();
	frame_metrics.resize(metric_size);
	last_metric=-1;
	variables->clear();
	//activate->set_pressed(false);
	plot_sigs.clear();
	plot_sigs.insert("fixed_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_val(0);
	updating_frame=false;
	hover_metric=-1;
	seeking=false;
}

static String _get_percent_txt(float p_value,float p_total) {
	if (p_total==0)
		p_total=0.00001;
	return String::num((p_value/p_total)*100,1)+"%";
}


String EditorProfiler::_get_time_as_text(Metric &m,float p_time,int p_calls) {

	int dmode = display_mode->get_selected();


	if (dmode==DISPLAY_FRAME_TIME) {
		return rtos(p_time);
	} else if (dmode==DISPLAY_AVERAGE_TIME) {
		if (p_calls==0)
			return "0";
		else
			return rtos(p_time/p_calls);
	} else if (dmode==DISPLAY_FRAME_PERCENT) {
		return _get_percent_txt(p_time,m.frame_time);
	} else if (dmode==DISPLAY_FIXED_FRAME_PERCENT) {

		return _get_percent_txt(p_time,m.fixed_frame_time);
	}

	return "err";
}

Color EditorProfiler::_get_color_from_signature(const StringName& p_signature) const {

	double rot = ABS(double(p_signature.hash())/double(0x7FFFFFFF));
	Color c;
	c.set_hsv(rot,1,1);
	return c;

}

void EditorProfiler::_item_edited() {

	if (updating_frame)
		return;

	TreeItem *item=variables->get_edited();
	if (!item)
		return;
	StringName signature=item->get_metadata(0);
	bool checked=item->is_checked(0);


	if (checked)
		plot_sigs.insert(signature);
	else
		plot_sigs.erase(signature);

	if (!frame_delay->is_processing()) {
		frame_delay->set_wait_time(0.1);
		frame_delay->start();
	}
}

void EditorProfiler::_update_plot() {

	int w = graph->get_size().width;
	int h = graph->get_size().height;

	bool reset_texture=false;

	int desired_len = w * h * 4;

	if (graph_image.size()!=desired_len) {
		reset_texture=true;
		graph_image.resize(desired_len);
	}


	DVector<uint8_t>::Write wr = graph_image.write();



	//clear
	for(int i=0;i<desired_len;i+=4) {
		wr[i+0]=0;
		wr[i+1]=0;
		wr[i+2]=0;
		wr[i+3]=255;<commit_msg>Update profiler curves on item toggled, closes #5680<commit_after>#include "editor_profiler.h"
#include "editor_settings.h"
#include "os/os.h"

void EditorProfiler::_make_metric_ptrs(Metric& m) {

	for(int i=0;i<m.categories.size();i++) {
		m.category_ptrs[m.categories[i].signature]=&m.categories[i];
		for(int j=0;j<m.categories[i].items.size();j++) {
			m.item_ptrs[m.categories[i].items[j].signature]=&m.categories[i].items[j];
		}
	}
}

void EditorProfiler::add_frame_metric(const Metric& p_metric,bool p_final) {

	++last_metric;
	if (last_metric>=frame_metrics.size())
		last_metric=0;


	frame_metrics[last_metric]=p_metric;
	_make_metric_ptrs(frame_metrics[last_metric]);

	updating_frame=true;
	cursor_metric_edit->set_max(frame_metrics[last_metric].frame_number);
	cursor_metric_edit->set_min(MAX(frame_metrics[last_metric].frame_number-frame_metrics.size(),0));


	if (!seeking) {
		cursor_metric_edit->set_val(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_processing()) {

		frame_delay->set_wait_time(p_final?0.1:1);
		frame_delay->start();
	}

	if (!plot_delay->is_processing()) {
		plot_delay->set_wait_time(0.1);
		plot_delay->start();
	}

}



void EditorProfiler::clear() {

	int metric_size=EditorSettings::get_singleton()->get("debugger/profiler_frame_history_size");
	metric_size = CLAMP(metric_size,60,1024);
	frame_metrics.clear();
	frame_metrics.resize(metric_size);
	last_metric=-1;
	variables->clear();
	//activate->set_pressed(false);
	plot_sigs.clear();
	plot_sigs.insert("fixed_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_val(0);
	updating_frame=false;
	hover_metric=-1;
	seeking=false;
}

static String _get_percent_txt(float p_value,float p_total) {
	if (p_total==0)
		p_total=0.00001;
	return String::num((p_value/p_total)*100,1)+"%";
}


String EditorProfiler::_get_time_as_text(Metric &m,float p_time,int p_calls) {

	int dmode = display_mode->get_selected();


	if (dmode==DISPLAY_FRAME_TIME) {
		return rtos(p_time);
	} else if (dmode==DISPLAY_AVERAGE_TIME) {
		if (p_calls==0)
			return "0";
		else
			return rtos(p_time/p_calls);
	} else if (dmode==DISPLAY_FRAME_PERCENT) {
		return _get_percent_txt(p_time,m.frame_time);
	} else if (dmode==DISPLAY_FIXED_FRAME_PERCENT) {

		return _get_percent_txt(p_time,m.fixed_frame_time);
	}

	return "err";
}

Color EditorProfiler::_get_color_from_signature(const StringName& p_signature) const {

	double rot = ABS(double(p_signature.hash())/double(0x7FFFFFFF));
	Color c;
	c.set_hsv(rot,1,1);
	return c;

}

void EditorProfiler::_item_edited() {

	if (updating_frame)
		return;

	TreeItem *item=variables->get_edited();
	if (!item)
		return;
	StringName signature=item->get_metadata(0);
	bool checked=item->is_checked(0);


	if (checked)
		plot_sigs.insert(signature);
	else
		plot_sigs.erase(signature);

	if (!frame_delay->is_processing()) {
		frame_delay->set_wait_time(0.1);
		frame_delay->start();
	}

	_update_plot();
}

void EditorProfiler::_update_plot() {

	int w = graph->get_size().width;
	int h = graph->get_size().height;

	bool reset_texture=false;

	int desired_len = w * h * 4;

	if (graph_image.size()!=desired_len) {
		reset_texture=true;
		graph_image.resize(desired_len);
	}


	DVector<uint8_t>::Write wr = graph_image.write();



	//clear
	for(int i=0;i<desired_len;i+=4) {
		wr[i+0]=0;
		wr[i+1]=0;
		wr[i+2]=0;
		wr[i+3]=255;
{'fraction_non_alphanumeric': 0.15861300654504942, 'fraction_numerical': 0.01643225177551873, 'mean_word_length': 6.132075471698113, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '951000', 'n_tokens_mistral': 3034, 'n_tokens_neox': 2867, 'n_words': 361}