editor_performance_profiler.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 "main/performance.h"
  34. #include "scene/gui/control.h"
  35. #include "scene/gui/label.h"
  36. #include "scene/gui/split_container.h"
  37. #include "scene/gui/tree.h"
  38. class EditorPerformanceProfiler : public HSplitContainer {
  39. GDCLASS(EditorPerformanceProfiler, HSplitContainer);
  40. private:
  41. class Monitor {
  42. public:
  43. String name;
  44. String base;
  45. List<float> history;
  46. float max = 0.0f;
  47. TreeItem *item = nullptr;
  48. Performance::MonitorType type = Performance::MONITOR_TYPE_QUANTITY;
  49. int frame_index = 0;
  50. Monitor();
  51. Monitor(const String &p_name, const String &p_base, int p_frame_index, Performance::MonitorType p_type, TreeItem *p_item);
  52. void update_value(float p_value);
  53. void reset();
  54. };
  55. HashMap<StringName, Monitor> monitors;
  56. HashMap<StringName, TreeItem *> base_map;
  57. Tree *monitor_tree = nullptr;
  58. Control *monitor_draw = nullptr;
  59. Label *info_message = nullptr;
  60. StringName marker_key;
  61. int marker_frame = 0;
  62. const int MARGIN = 4;
  63. const int POINT_SEPARATION = 5;
  64. const int MARKER_MARGIN = 2;
  65. static String _create_label(float p_value, Performance::MonitorType p_type);
  66. void _monitor_select();
  67. void _monitor_draw();
  68. void _build_monitor_tree();
  69. TreeItem *_get_monitor_base(const StringName &p_base_name);
  70. TreeItem *_create_monitor_item(const StringName &p_monitor_name, TreeItem *p_base);
  71. void _marker_input(const Ref<InputEvent> &p_event);
  72. protected:
  73. void _notification(int p_what);
  74. public:
  75. void reset();
  76. void update_monitors(const Vector<StringName> &p_names);
  77. void add_profile_frame(const Vector<float> &p_values);
  78. List<float> *get_monitor_data(const StringName &p_name);
  79. EditorPerformanceProfiler();
  80. };
  81. #endif // EDITOR_PERFORMANCE_PROFILER_H