editor_profiler.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  1. /*************************************************************************/
  2. /* editor_profiler.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "editor_profiler.h"
  31. #include "editor_settings.h"
  32. #include "os/os.h"
  33. void EditorProfiler::_make_metric_ptrs(Metric &m) {
  34. for (int i = 0; i < m.categories.size(); i++) {
  35. m.category_ptrs[m.categories[i].signature] = &m.categories[i];
  36. for (int j = 0; j < m.categories[i].items.size(); j++) {
  37. m.item_ptrs[m.categories[i].items[j].signature] = &m.categories[i].items[j];
  38. }
  39. }
  40. }
  41. void EditorProfiler::add_frame_metric(const Metric &p_metric, bool p_final) {
  42. ++last_metric;
  43. if (last_metric >= frame_metrics.size())
  44. last_metric = 0;
  45. frame_metrics[last_metric] = p_metric;
  46. _make_metric_ptrs(frame_metrics[last_metric]);
  47. updating_frame = true;
  48. cursor_metric_edit->set_max(frame_metrics[last_metric].frame_number);
  49. cursor_metric_edit->set_min(MAX(frame_metrics[last_metric].frame_number - frame_metrics.size(), 0));
  50. if (!seeking) {
  51. cursor_metric_edit->set_val(frame_metrics[last_metric].frame_number);
  52. if (hover_metric != -1) {
  53. hover_metric++;
  54. if (hover_metric >= frame_metrics.size()) {
  55. hover_metric = 0;
  56. }
  57. }
  58. }
  59. updating_frame = false;
  60. if (!frame_delay->is_processing()) {
  61. frame_delay->set_wait_time(p_final ? 0.1 : 1);
  62. frame_delay->start();
  63. }
  64. if (!plot_delay->is_processing()) {
  65. plot_delay->set_wait_time(0.1);
  66. plot_delay->start();
  67. }
  68. }
  69. void EditorProfiler::clear() {
  70. int metric_size = EditorSettings::get_singleton()->get("debugger/profiler_frame_history_size");
  71. metric_size = CLAMP(metric_size, 60, 1024);
  72. frame_metrics.clear();
  73. frame_metrics.resize(metric_size);
  74. last_metric = -1;
  75. variables->clear();
  76. //activate->set_pressed(false);
  77. plot_sigs.clear();
  78. plot_sigs.insert("fixed_frame_time");
  79. plot_sigs.insert("category_frame_time");
  80. updating_frame = true;
  81. cursor_metric_edit->set_min(0);
  82. cursor_metric_edit->set_max(0);
  83. cursor_metric_edit->set_val(0);
  84. updating_frame = false;
  85. hover_metric = -1;
  86. seeking = false;
  87. }
  88. static String _get_percent_txt(float p_value, float p_total) {
  89. if (p_total == 0)
  90. p_total = 0.00001;
  91. return String::num((p_value / p_total) * 100, 1) + "%";
  92. }
  93. String EditorProfiler::_get_time_as_text(Metric &m, float p_time, int p_calls) {
  94. int dmode = display_mode->get_selected();
  95. if (dmode == DISPLAY_FRAME_TIME) {
  96. return rtos(p_time);
  97. } else if (dmode == DISPLAY_AVERAGE_TIME) {
  98. if (p_calls == 0)
  99. return "0";
  100. else
  101. return rtos(p_time / p_calls);
  102. } else if (dmode == DISPLAY_FRAME_PERCENT) {
  103. return _get_percent_txt(p_time, m.frame_time);
  104. } else if (dmode == DISPLAY_FIXED_FRAME_PERCENT) {
  105. return _get_percent_txt(p_time, m.fixed_frame_time);
  106. }
  107. return "err";
  108. }
  109. Color EditorProfiler::_get_color_from_signature(const StringName &p_signature) const {
  110. double rot = ABS(double(p_signature.hash()) / double(0x7FFFFFFF));
  111. Color c;
  112. c.set_hsv(rot, 1, 1);
  113. return c;
  114. }
  115. void EditorProfiler::_item_edited() {
  116. if (updating_frame)
  117. return;
  118. TreeItem *item = variables->get_edited();
  119. if (!item)
  120. return;
  121. StringName signature = item->get_metadata(0);
  122. bool checked = item->is_checked(0);
  123. if (checked)
  124. plot_sigs.insert(signature);
  125. else
  126. plot_sigs.erase(signature);
  127. if (!frame_delay->is_processing()) {
  128. frame_delay->set_wait_time(0.1);
  129. frame_delay->start();
  130. }
  131. _update_plot();
  132. }
  133. void EditorProfiler::_update_plot() {
  134. int w = graph->get_size().width;
  135. int h = graph->get_size().height;
  136. bool reset_texture = false;
  137. int desired_len = w * h * 4;
  138. if (graph_image.size() != desired_len) {
  139. reset_texture = true;
  140. graph_image.resize(desired_len);
  141. }
  142. DVector<uint8_t>::Write wr = graph_image.write();
  143. //clear
  144. for (int i = 0; i < desired_len; i += 4) {
  145. wr[i + 0] = 0;
  146. wr[i + 1] = 0;
  147. wr[i + 2] = 0;
  148. wr[i + 3] = 255;
  149. }
  150. //find highest value
  151. bool use_self = display_time->get_selected() == DISPLAY_SELF_TIME;
  152. float highest = 0;
  153. for (int i = 0; i < frame_metrics.size(); i++) {
  154. Metric &m = frame_metrics[i];
  155. if (!m.valid)
  156. continue;
  157. for (Set<StringName>::Element *E = plot_sigs.front(); E; E = E->next()) {
  158. Map<StringName, Metric::Category *>::Element *F = m.category_ptrs.find(E->get());
  159. if (F) {
  160. highest = MAX(F->get()->total_time, highest);
  161. }
  162. Map<StringName, Metric::Category::Item *>::Element *G = m.item_ptrs.find(E->get());
  163. if (G) {
  164. if (use_self) {
  165. highest = MAX(G->get()->self, highest);
  166. } else {
  167. highest = MAX(G->get()->total, highest);
  168. }
  169. }
  170. }
  171. }
  172. if (highest > 0) {
  173. //means some data exists..
  174. highest *= 1.2; //leave some upper room
  175. graph_height = highest;
  176. Vector<int> columnv;
  177. columnv.resize(h * 4);
  178. int *column = columnv.ptr();
  179. Map<StringName, int> plot_prev;
  180. //Map<StringName,int> plot_max;
  181. uint64_t time = OS::get_singleton()->get_ticks_usec();
  182. for (int i = 0; i < w; i++) {
  183. for (int j = 0; j < h * 4; j++) {
  184. column[j] = 0;
  185. }
  186. int current = i * frame_metrics.size() / w;
  187. int next = (i + 1) * frame_metrics.size() / w;
  188. if (next > frame_metrics.size()) {
  189. next = frame_metrics.size();
  190. }
  191. if (next == current)
  192. next = current + 1; //just because for loop must work
  193. for (Set<StringName>::Element *E = plot_sigs.front(); E; E = E->next()) {
  194. int plot_pos = -1;
  195. for (int j = current; j < next; j++) {
  196. //wrap
  197. int idx = last_metric + 1 + j;
  198. while (idx >= frame_metrics.size()) {
  199. idx -= frame_metrics.size();
  200. }
  201. //get
  202. Metric &m = frame_metrics[idx];
  203. if (m.valid == false)
  204. continue; //skip because invalid
  205. float value = 0;
  206. Map<StringName, Metric::Category *>::Element *F = m.category_ptrs.find(E->get());
  207. if (F) {
  208. value = F->get()->total_time;
  209. }
  210. Map<StringName, Metric::Category::Item *>::Element *G = m.item_ptrs.find(E->get());
  211. if (G) {
  212. if (use_self) {
  213. value = G->get()->self;
  214. } else {
  215. value = G->get()->total;
  216. }
  217. }
  218. plot_pos = MAX(CLAMP(int(value * h / highest), 0, h - 1), plot_pos);
  219. }
  220. int prev_plot = plot_pos;
  221. Map<StringName, int>::Element *H = plot_prev.find(E->get());
  222. if (H) {
  223. prev_plot = H->get();
  224. H->get() = plot_pos;
  225. } else {
  226. plot_prev[E->get()] = plot_pos;
  227. }
  228. if (plot_pos == -1 && prev_plot == -1) {
  229. //don't bother drawing
  230. continue;
  231. }
  232. if (prev_plot != -1 && plot_pos == -1) {
  233. plot_pos = prev_plot;
  234. }
  235. if (prev_plot == -1 && plot_pos != -1) {
  236. prev_plot = plot_pos;
  237. }
  238. plot_pos = h - plot_pos - 1;
  239. prev_plot = h - prev_plot - 1;
  240. if (prev_plot > plot_pos) {
  241. SWAP(prev_plot, plot_pos);
  242. }
  243. Color col = _get_color_from_signature(E->get());
  244. for (int j = prev_plot; j <= plot_pos; j++) {
  245. column[j * 4 + 0] += Math::fast_ftoi(CLAMP(col.r * 255, 0, 255));
  246. column[j * 4 + 1] += Math::fast_ftoi(CLAMP(col.g * 255, 0, 255));
  247. column[j * 4 + 2] += Math::fast_ftoi(CLAMP(col.b * 255, 0, 255));
  248. column[j * 4 + 3] += 1;
  249. }
  250. }
  251. for (int j = 0; j < h * 4; j += 4) {
  252. int a = column[j + 3];
  253. if (a > 0) {
  254. column[j + 0] /= a;
  255. column[j + 1] /= a;
  256. column[j + 2] /= a;
  257. }
  258. uint8_t r = uint8_t(column[j + 0]);
  259. uint8_t g = uint8_t(column[j + 1]);
  260. uint8_t b = uint8_t(column[j + 2]);
  261. int widx = ((j >> 2) * w + i) * 4;
  262. wr[widx + 0] = r;
  263. wr[widx + 1] = g;
  264. wr[widx + 2] = b;
  265. wr[widx + 3] = 255;
  266. }
  267. }
  268. time = OS::get_singleton()->get_ticks_usec() - time;
  269. //print_line("Taken: "+rtos(USEC_TO_SEC(time)));
  270. }
  271. wr = DVector<uint8_t>::Write();
  272. Image img(w, h, 0, Image::FORMAT_RGBA, graph_image);
  273. if (reset_texture) {
  274. if (graph_texture.is_null()) {
  275. graph_texture.instance();
  276. }
  277. graph_texture->create(img.get_width(), img.get_height(), img.get_format(), Texture::FLAG_VIDEO_SURFACE);
  278. }
  279. graph_texture->set_data(img);
  280. graph->set_texture(graph_texture);
  281. graph->update();
  282. }
  283. void EditorProfiler::_update_frame() {
  284. int cursor_metric = _get_cursor_index();
  285. ERR_FAIL_INDEX(cursor_metric, frame_metrics.size());
  286. updating_frame = true;
  287. variables->clear();
  288. TreeItem *root = variables->create_item();
  289. Metric &m = frame_metrics[cursor_metric];
  290. int dtime = display_time->get_selected();
  291. for (int i = 0; i < m.categories.size(); i++) {
  292. TreeItem *category = variables->create_item(root);
  293. category->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
  294. category->set_editable(0, true);
  295. category->set_metadata(0, m.categories[i].signature);
  296. category->set_text(0, String(m.categories[i].name));
  297. category->set_text(1, _get_time_as_text(m, m.categories[i].total_time, 1));
  298. if (plot_sigs.has(m.categories[i].signature)) {
  299. category->set_checked(0, true);
  300. category->set_custom_bg_color(0, Color(0, 0, 0));
  301. category->set_custom_color(0, _get_color_from_signature(m.categories[i].signature));
  302. }
  303. for (int j = 0; j < m.categories[i].items.size(); j++) {
  304. Metric::Category::Item &it = m.categories[i].items[j];
  305. TreeItem *item = variables->create_item(category);
  306. item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
  307. item->set_editable(0, true);
  308. item->set_text(0, it.name);
  309. item->set_metadata(0, it.signature);
  310. item->set_metadata(1, it.script);
  311. item->set_metadata(2, it.line);
  312. item->set_tooltip(0, it.script + ":" + itos(it.line));
  313. float time = dtime == DISPLAY_SELF_TIME ? it.self : it.total;
  314. item->set_text(1, _get_time_as_text(m, time, it.calls));
  315. item->set_text(2, itos(it.calls));
  316. if (plot_sigs.has(it.signature)) {
  317. item->set_checked(0, true);
  318. item->set_custom_bg_color(0, Color(0, 0, 0));
  319. item->set_custom_color(0, _get_color_from_signature(it.signature));
  320. }
  321. }
  322. }
  323. updating_frame = false;
  324. }
  325. void EditorProfiler::_activate_pressed() {
  326. if (activate->is_pressed()) {
  327. clear();
  328. activate->set_icon(get_icon("Stop", "EditorIcons"));
  329. activate->set_text(TTR("Stop Profiling"));
  330. } else {
  331. activate->set_icon(get_icon("Play", "EditorIcons"));
  332. activate->set_text(TTR("Start Profiling"));
  333. }
  334. emit_signal("enable_profiling", activate->is_pressed());
  335. }
  336. void EditorProfiler::_notification(int p_what) {
  337. if (p_what == NOTIFICATION_ENTER_TREE) {
  338. activate->set_icon(get_icon("Play", "EditorIcons"));
  339. }
  340. }
  341. void EditorProfiler::_graph_tex_draw() {
  342. if (last_metric < 0)
  343. return;
  344. if (seeking) {
  345. int max_frames = frame_metrics.size();
  346. int frame = cursor_metric_edit->get_val() - (frame_metrics[last_metric].frame_number - max_frames + 1);
  347. if (frame < 0)
  348. frame = 0;
  349. int cur_x = frame * graph->get_size().x / max_frames;
  350. graph->draw_line(Vector2(cur_x, 0), Vector2(cur_x, graph->get_size().y), Color(1, 1, 1, 0.8));
  351. }
  352. if (hover_metric != -1 && frame_metrics[hover_metric].valid) {
  353. int max_frames = frame_metrics.size();
  354. int frame = frame_metrics[hover_metric].frame_number - (frame_metrics[last_metric].frame_number - max_frames + 1);
  355. if (frame < 0)
  356. frame = 0;
  357. int cur_x = frame * graph->get_size().x / max_frames;
  358. graph->draw_line(Vector2(cur_x, 0), Vector2(cur_x, graph->get_size().y), Color(1, 1, 1, 0.4));
  359. }
  360. }
  361. void EditorProfiler::_graph_tex_mouse_exit() {
  362. hover_metric = -1;
  363. graph->update();
  364. }
  365. void EditorProfiler::_cursor_metric_changed(double) {
  366. if (updating_frame)
  367. return;
  368. graph->update();
  369. _update_frame();
  370. }
  371. void EditorProfiler::_graph_tex_input(const InputEvent &p_ev) {
  372. if (last_metric < 0)
  373. return;
  374. if (
  375. (p_ev.type == InputEvent::MOUSE_BUTTON && p_ev.mouse_button.button_index == BUTTON_LEFT && p_ev.mouse_button.pressed) ||
  376. (p_ev.type == InputEvent::MOUSE_MOTION)) {
  377. int x = p_ev.mouse_button.x;
  378. x = x * frame_metrics.size() / graph->get_size().width;
  379. bool show_hover = x >= 0 && x < frame_metrics.size();
  380. if (x < 0) {
  381. x = 0;
  382. }
  383. if (x >= frame_metrics.size()) {
  384. x = frame_metrics.size() - 1;
  385. }
  386. int metric = frame_metrics.size() - x - 1;
  387. metric = last_metric - metric;
  388. while (metric < 0) {
  389. metric += frame_metrics.size();
  390. }
  391. if (show_hover) {
  392. hover_metric = metric;
  393. } else {
  394. hover_metric = -1;
  395. }
  396. if (p_ev.type == InputEvent::MOUSE_BUTTON || p_ev.mouse_motion.button_mask & BUTTON_MASK_LEFT) {
  397. //cursor_metric=x;
  398. updating_frame = true;
  399. //metric may be invalid, so look for closest metric that is valid, this makes snap feel better
  400. bool valid = false;
  401. for (int i = 0; i < frame_metrics.size(); i++) {
  402. if (frame_metrics[metric].valid) {
  403. valid = true;
  404. break;
  405. }
  406. metric++;
  407. if (metric >= frame_metrics.size())
  408. metric = 0;
  409. }
  410. if (valid)
  411. cursor_metric_edit->set_val(frame_metrics[metric].frame_number);
  412. updating_frame = false;
  413. if (activate->is_pressed()) {
  414. if (!seeking) {
  415. emit_signal("break_request");
  416. }
  417. }
  418. seeking = true;
  419. if (!frame_delay->is_processing()) {
  420. frame_delay->set_wait_time(0.1);
  421. frame_delay->start();
  422. }
  423. }
  424. graph->update();
  425. }
  426. }
  427. int EditorProfiler::_get_cursor_index() const {
  428. if (last_metric < 0)
  429. return 0;
  430. if (!frame_metrics[last_metric].valid)
  431. return 0;
  432. int diff = (frame_metrics[last_metric].frame_number - cursor_metric_edit->get_val());
  433. int idx = last_metric - diff;
  434. while (idx < 0) {
  435. idx += frame_metrics.size();
  436. }
  437. return idx;
  438. }
  439. void EditorProfiler::disable_seeking() {
  440. seeking = false;
  441. graph->update();
  442. }
  443. void EditorProfiler::_combo_changed(int) {
  444. _update_frame();
  445. _update_plot();
  446. }
  447. void EditorProfiler::_bind_methods() {
  448. ObjectTypeDB::bind_method(_MD("_update_frame"), &EditorProfiler::_update_frame);
  449. ObjectTypeDB::bind_method(_MD("_update_plot"), &EditorProfiler::_update_plot);
  450. ObjectTypeDB::bind_method(_MD("_activate_pressed"), &EditorProfiler::_activate_pressed);
  451. ObjectTypeDB::bind_method(_MD("_graph_tex_draw"), &EditorProfiler::_graph_tex_draw);
  452. ObjectTypeDB::bind_method(_MD("_graph_tex_input"), &EditorProfiler::_graph_tex_input);
  453. ObjectTypeDB::bind_method(_MD("_graph_tex_mouse_exit"), &EditorProfiler::_graph_tex_mouse_exit);
  454. ObjectTypeDB::bind_method(_MD("_cursor_metric_changed"), &EditorProfiler::_cursor_metric_changed);
  455. ObjectTypeDB::bind_method(_MD("_combo_changed"), &EditorProfiler::_combo_changed);
  456. ObjectTypeDB::bind_method(_MD("_item_edited"), &EditorProfiler::_item_edited);
  457. ADD_SIGNAL(MethodInfo("enable_profiling", PropertyInfo(Variant::BOOL, "enable")));
  458. ADD_SIGNAL(MethodInfo("break_request"));
  459. }
  460. void EditorProfiler::set_enabled(bool p_enable) {
  461. activate->set_disabled(!p_enable);
  462. }
  463. bool EditorProfiler::is_profiling() {
  464. return activate->is_pressed();
  465. }
  466. EditorProfiler::EditorProfiler() {
  467. HBoxContainer *hb = memnew(HBoxContainer);
  468. add_child(hb);
  469. activate = memnew(Button);
  470. activate->set_toggle_mode(true);
  471. activate->set_text(TTR("Start Profiling"));
  472. activate->connect("pressed", this, "_activate_pressed");
  473. hb->add_child(activate);
  474. hb->add_child(memnew(Label(TTR("Measure:"))));
  475. display_mode = memnew(OptionButton);
  476. display_mode->add_item(TTR("Frame Time (sec)"));
  477. display_mode->add_item(TTR("Average Time (sec)"));
  478. display_mode->add_item(TTR("Frame %"));
  479. display_mode->add_item(TTR("Fixed Frame %"));
  480. display_mode->connect("item_selected", this, "_combo_changed");
  481. hb->add_child(display_mode);
  482. hb->add_child(memnew(Label(TTR("Time:"))));
  483. display_time = memnew(OptionButton);
  484. display_time->add_item(TTR("Inclusive"));
  485. display_time->add_item(TTR("Self"));
  486. display_time->connect("item_selected", this, "_combo_changed");
  487. hb->add_child(display_time);
  488. hb->add_spacer();
  489. hb->add_child(memnew(Label(TTR("Frame #:"))));
  490. cursor_metric_edit = memnew(SpinBox);
  491. cursor_metric_edit->set_h_size_flags(SIZE_FILL);
  492. hb->add_child(cursor_metric_edit);
  493. cursor_metric_edit->connect("value_changed", this, "_cursor_metric_changed");
  494. hb->add_constant_override("separation", 8);
  495. h_split = memnew(HSplitContainer);
  496. add_child(h_split);
  497. h_split->set_v_size_flags(SIZE_EXPAND_FILL);
  498. variables = memnew(Tree);
  499. variables->set_custom_minimum_size(Size2(300, 0));
  500. variables->set_hide_folding(true);
  501. h_split->add_child(variables);
  502. variables->set_hide_root(true);
  503. variables->set_columns(3);
  504. variables->set_column_titles_visible(true);
  505. variables->set_column_title(0, "Name");
  506. variables->set_column_expand(0, true);
  507. variables->set_column_min_width(0, 60);
  508. variables->set_column_title(1, "Time");
  509. variables->set_column_expand(1, false);
  510. variables->set_column_min_width(1, 60);
  511. variables->set_column_title(2, "Calls");
  512. variables->set_column_expand(2, false);
  513. variables->set_column_min_width(2, 60);
  514. variables->connect("item_edited", this, "_item_edited");
  515. graph = memnew(TextureFrame);
  516. graph->set_expand(true);
  517. graph->set_stop_mouse(true);
  518. graph->set_ignore_mouse(false);
  519. graph->connect("draw", this, "_graph_tex_draw");
  520. graph->connect("input_event", this, "_graph_tex_input");
  521. graph->connect("mouse_exit", this, "_graph_tex_mouse_exit");
  522. h_split->add_child(graph);
  523. graph->set_h_size_flags(SIZE_EXPAND_FILL);
  524. add_constant_override("separation", 3);
  525. int metric_size = CLAMP(int(EDITOR_DEF("debugger/profiler_frame_history_size", 600)), 60, 1024);
  526. frame_metrics.resize(metric_size);
  527. last_metric = -1;
  528. // cursor_metric=-1;
  529. hover_metric = -1;
  530. EDITOR_DEF("debugger/profiler_frame_max_functions", 64);
  531. //display_mode=DISPLAY_FRAME_TIME;
  532. frame_delay = memnew(Timer);
  533. frame_delay->set_wait_time(0.1);
  534. frame_delay->set_one_shot(true);
  535. add_child(frame_delay);
  536. frame_delay->connect("timeout", this, "_update_frame");
  537. plot_delay = memnew(Timer);
  538. plot_delay->set_wait_time(0.1);
  539. plot_delay->set_one_shot(true);
  540. add_child(plot_delay);
  541. plot_delay->connect("timeout", this, "_update_plot");
  542. plot_sigs.insert("fixed_frame_time");
  543. plot_sigs.insert("category_frame_time");
  544. seeking = false;
  545. graph_height = 1;
  546. // activate->set_disabled(true);
  547. }