editor_performance_profiler.h 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /**************************************************************************/
  2. /* editor_performance_profiler.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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 EDITOR_PERFORMANCE_PROFILER_H
  31. #define EDITOR_PERFORMANCE_PROFILER_H
  32. #include "core/templates/hash_map.h"
  33. #include "core/templates/rb_map.h"
  34. #include "main/performance.h"
  35. #include "scene/gui/control.h"
  36. #include "scene/gui/label.h"
  37. #include "scene/gui/split_container.h"
  38. #include "scene/gui/tree.h"
  39. class EditorPerformanceProfiler : public HSplitContainer {
  40. GDCLASS(EditorPerformanceProfiler, HSplitContainer);
  41. private:
  42. class Monitor {
  43. public:
  44. String name;
  45. String base;
  46. List<float> history;
  47. float max = 0.0f;
  48. TreeItem *item = nullptr;
  49. Performance::MonitorType type = Performance::MONITOR_TYPE_QUANTITY;
  50. int frame_index = 0;
  51. Monitor();
  52. Monitor(const String &p_name, const String &p_base, int p_frame_index, Performance::MonitorType p_type, TreeItem *p_item);
  53. void update_value(float p_value);
  54. void reset();
  55. };
  56. HashMap<StringName, Monitor> monitors;
  57. HashMap<StringName, TreeItem *> base_map;
  58. Tree *monitor_tree = nullptr;
  59. Control *monitor_draw = nullptr;
  60. Label *info_message = nullptr;
  61. StringName marker_key;
  62. int marker_frame = 0;
  63. const int MARGIN = 4;
  64. const int POINT_SEPARATION = 5;
  65. const int MARKER_MARGIN = 2;
  66. static String _create_label(float p_value, Performance::MonitorType p_type);
  67. void _monitor_select();
  68. void _monitor_draw();
  69. void _build_monitor_tree();
  70. TreeItem *_get_monitor_base(const StringName &p_base_name);
  71. TreeItem *_create_monitor_item(const StringName &p_monitor_name, TreeItem *p_base);
  72. void _marker_input(const Ref<InputEvent> &p_event);
  73. protected:
  74. void _notification(int p_what);
  75. public:
  76. void reset();
  77. void update_monitors(const Vector<StringName> &p_names);
  78. void add_profile_frame(const Vector<float> &p_values);
  79. List<float> *get_monitor_data(const StringName &p_name);
  80. EditorPerformanceProfiler();
  81. };
  82. #endif // EDITOR_PERFORMANCE_PROFILER_H