editor_profiler.cpp 20 KB

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