editor_profiler.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*************************************************************************/
  2. /* editor_profiler.h */
  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. #ifndef EDITORPROFILER_H
  31. #define EDITORPROFILER_H
  32. #include "scene/gui/box_container.h"
  33. #include "scene/gui/button.h"
  34. #include "scene/gui/label.h"
  35. #include "scene/gui/option_button.h"
  36. #include "scene/gui/spin_box.h"
  37. #include "scene/gui/split_container.h"
  38. #include "scene/gui/texture_rect.h"
  39. #include "scene/gui/tree.h"
  40. class EditorProfiler : public VBoxContainer {
  41. GDCLASS(EditorProfiler, VBoxContainer)
  42. public:
  43. struct Metric {
  44. bool valid;
  45. int frame_number;
  46. float frame_time;
  47. float idle_time;
  48. float physics_time;
  49. float physics_frame_time;
  50. struct Category {
  51. StringName signature;
  52. String name;
  53. float total_time; //total for category
  54. struct Item {
  55. StringName signature;
  56. String name;
  57. String script;
  58. int line;
  59. float self;
  60. float total;
  61. int calls;
  62. };
  63. Vector<Item> items;
  64. };
  65. Vector<Category> categories;
  66. Map<StringName, Category *> category_ptrs;
  67. Map<StringName, Category::Item *> item_ptrs;
  68. Metric() {
  69. valid = false;
  70. frame_number = 0;
  71. }
  72. };
  73. enum DisplayMode {
  74. DISPLAY_FRAME_TIME,
  75. DISPLAY_AVERAGE_TIME,
  76. DISPLAY_FRAME_PERCENT,
  77. DISPLAY_PHYSICS_FRAME_PERCENT,
  78. };
  79. enum DisplayTime {
  80. DISPLAY_TOTAL_TIME,
  81. DISPLAY_SELF_TIME,
  82. };
  83. private:
  84. Button *activate;
  85. Button *clear_button;
  86. TextureRect *graph;
  87. Ref<ImageTexture> graph_texture;
  88. PoolVector<uint8_t> graph_image;
  89. Tree *variables;
  90. HSplitContainer *h_split;
  91. Set<StringName> plot_sigs;
  92. OptionButton *display_mode;
  93. OptionButton *display_time;
  94. SpinBox *cursor_metric_edit;
  95. Vector<Metric> frame_metrics;
  96. int last_metric;
  97. int max_functions;
  98. bool updating_frame;
  99. //int cursor_metric;
  100. int hover_metric;
  101. float graph_height;
  102. bool seeking;
  103. Timer *frame_delay;
  104. Timer *plot_delay;
  105. void _update_frame();
  106. void _activate_pressed();
  107. void _clear_pressed();
  108. String _get_time_as_text(const Metric &m, float p_time, int p_calls);
  109. void _make_metric_ptrs(Metric &m);
  110. void _item_edited();
  111. void _update_plot();
  112. void _graph_tex_mouse_exit();
  113. void _graph_tex_draw();
  114. void _graph_tex_input(const Ref<InputEvent> &p_ev);
  115. int _get_cursor_index() const;
  116. Color _get_color_from_signature(const StringName &p_signature) const;
  117. void _cursor_metric_changed(double);
  118. void _combo_changed(int);
  119. protected:
  120. void _notification(int p_what);
  121. static void _bind_methods();
  122. public:
  123. void add_frame_metric(const Metric &p_metric, bool p_final = false);
  124. void set_enabled(bool p_enable);
  125. bool is_profiling();
  126. bool is_seeking() { return seeking; }
  127. void disable_seeking();
  128. void clear();
  129. EditorProfiler();
  130. };
  131. #endif // EDITORPROFILER_H