objectdb_profiler_panel.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /**************************************************************************/
  2. /* objectdb_profiler_panel.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. #pragma once
  31. #include "data_viewers/snapshot_view.h"
  32. #include "snapshot_data.h"
  33. #include "core/io/dir_access.h"
  34. #include "core/templates/lru.h"
  35. class TabContainer;
  36. class Tree;
  37. // UI loaded by the debugger.
  38. class ObjectDBProfilerPanel : public Control {
  39. GDCLASS(ObjectDBProfilerPanel, Control);
  40. protected:
  41. static constexpr int SNAPSHOT_CACHE_MAX_SIZE = 10;
  42. enum OdbProfilerMenuOptions {
  43. ODB_MENU_RENAME,
  44. ODB_MENU_SHOW_IN_FOLDER,
  45. ODB_MENU_DELETE,
  46. };
  47. struct PartialSnapshot {
  48. int total_size;
  49. Vector<uint8_t> data;
  50. };
  51. int next_request_id = 0;
  52. bool awaiting_debug_break = false;
  53. bool requested_break_for_snapshot = false;
  54. Tree *snapshot_list = nullptr;
  55. Button *take_snapshot = nullptr;
  56. TabContainer *view_tabs = nullptr;
  57. PopupMenu *rmb_menu = nullptr;
  58. OptionButton *diff_button = nullptr;
  59. HashMap<int, PartialSnapshot> partial_snapshots;
  60. LocalVector<SnapshotView *> views;
  61. Ref<GameStateSnapshot> current_snapshot;
  62. Ref<GameStateSnapshot> diff_snapshot;
  63. LRUCache<String, Ref<GameStateSnapshot>> snapshot_cache;
  64. void _request_object_snapshot();
  65. void _begin_object_snapshot();
  66. void _on_debug_breaked(bool p_reallydid, bool p_can_debug, const String &p_reason, bool p_has_stackdump);
  67. void _show_selected_snapshot();
  68. void _on_snapshot_deselected();
  69. Ref<DirAccess> _get_and_create_snapshot_storage_dir();
  70. TreeItem *_add_snapshot_button(const String &p_snapshot_file_name, const String &p_full_file_path);
  71. void _snapshot_rmb(const Vector2 &p_pos, MouseButton p_button);
  72. void _rmb_menu_pressed(int p_tool, bool p_confirm_override);
  73. void _update_view_tabs();
  74. void _update_diff_items();
  75. void _update_enabled_diff_items();
  76. void _edit_snapshot_name();
  77. void _view_tab_changed(int p_tab_idx);
  78. String _to_mb(int p_x);
  79. public:
  80. ObjectDBProfilerPanel();
  81. void receive_snapshot(int p_request_id);
  82. void show_snapshot(const String &p_snapshot_file_name, const String &p_snapshot_diff_file_name);
  83. void clear_snapshot(bool p_update_view_tabs = true);
  84. Ref<GameStateSnapshot> get_snapshot(const String &p_snapshot_file_name);
  85. void set_enabled(bool p_enabled);
  86. void add_view(SnapshotView *p_to_add);
  87. bool handle_debug_message(const String &p_message, const Array &p_data, int p_index);
  88. };