tree_widget_loader.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /************************************************************************
  2. * file name : tree_widget_loader.h
  3. * ----------------- :
  4. * creation time : 2016/08/18
  5. * author : Victor Zarubkin
  6. * email : [email protected]
  7. * ----------------- :
  8. * description : The file contains declaration of EasyTreeWidgetLoader which aim is
  9. * : to load EasyProfiler blocks hierarchy in separate thread.
  10. * ----------------- :
  11. * change log : * 2016/08/18 Victor Zarubkin: moved sources from blocks_tree_widget.h/.cpp
  12. * : and renamed Prof* to Easy*.
  13. * :
  14. * : *
  15. * ----------------- :
  16. * license : Lightweight profiler library for c++
  17. * : Copyright(C) 2016-2017 Sergey Yagovtsev, Victor Zarubkin
  18. * :
  19. * : Licensed under either of
  20. * : * MIT license (LICENSE.MIT or http://opensource.org/licenses/MIT)
  21. * : * Apache License, Version 2.0, (LICENSE.APACHE or http://www.apache.org/licenses/LICENSE-2.0)
  22. * : at your option.
  23. * :
  24. * : The MIT License
  25. * :
  26. * : Permission is hereby granted, free of charge, to any person obtaining a copy
  27. * : of this software and associated documentation files (the "Software"), to deal
  28. * : in the Software without restriction, including without limitation the rights
  29. * : to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  30. * : of the Software, and to permit persons to whom the Software is furnished
  31. * : to do so, subject to the following conditions:
  32. * :
  33. * : The above copyright notice and this permission notice shall be included in all
  34. * : copies or substantial portions of the Software.
  35. * :
  36. * : THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  37. * : INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  38. * : PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  39. * : LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  40. * : TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  41. * : USE OR OTHER DEALINGS IN THE SOFTWARE.
  42. * :
  43. * : The Apache License, Version 2.0 (the "License")
  44. * :
  45. * : You may not use this file except in compliance with the License.
  46. * : You may obtain a copy of the License at
  47. * :
  48. * : http://www.apache.org/licenses/LICENSE-2.0
  49. * :
  50. * : Unless required by applicable law or agreed to in writing, software
  51. * : distributed under the License is distributed on an "AS IS" BASIS,
  52. * : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  53. * : See the License for the specific language governing permissions and
  54. * : limitations under the License.
  55. ************************************************************************/
  56. #ifndef EASY_TREE_WIDGET_LOADER_H
  57. #define EASY_TREE_WIDGET_LOADER_H
  58. #include <stdlib.h>
  59. #include <vector>
  60. #include <thread>
  61. #include <atomic>
  62. #include <easy/reader.h>
  63. #include "common_types.h"
  64. //////////////////////////////////////////////////////////////////////////
  65. class EasyTreeWidgetItem;
  66. #ifndef EASY_TREE_WIDGET__USE_VECTOR
  67. typedef ::std::unordered_map<::profiler::block_index_t, EasyTreeWidgetItem*, ::profiler::passthrough_hash<::profiler::block_index_t> > Items;
  68. #else
  69. typedef ::std::vector<EasyTreeWidgetItem*> Items;
  70. #endif
  71. typedef ::std::vector<::std::pair<::profiler::thread_id_t, EasyTreeWidgetItem*> > ThreadedItems;
  72. typedef ::std::unordered_map<::profiler::thread_id_t, EasyTreeWidgetItem*, ::profiler::passthrough_hash<::profiler::thread_id_t> > RootsMap;
  73. typedef ::std::unordered_map<::profiler::block_id_t, EasyTreeWidgetItem*, ::profiler::passthrough_hash<::profiler::block_index_t> > IdItems;
  74. //////////////////////////////////////////////////////////////////////////
  75. enum EasyTreeMode : uint8_t
  76. {
  77. EasyTreeMode_Full,
  78. EasyTreeMode_Plain
  79. };
  80. //////////////////////////////////////////////////////////////////////////
  81. class EasyTreeWidgetLoader Q_DECL_FINAL
  82. {
  83. ThreadedItems m_topLevelItems; ///<
  84. Items m_items; ///<
  85. IdItems m_iditems; ///<
  86. ::std::thread m_thread; ///<
  87. ::std::atomic_bool m_bDone; ///<
  88. ::std::atomic_bool m_bInterrupt; ///<
  89. ::std::atomic<int> m_progress; ///<
  90. EasyTreeMode m_mode; ///<
  91. public:
  92. EasyTreeWidgetLoader();
  93. ~EasyTreeWidgetLoader();
  94. int progress() const;
  95. bool done() const;
  96. void takeTopLevelItems(ThreadedItems& _output);
  97. void takeItems(Items& _output);
  98. void interrupt(bool _wait = false);
  99. void fillTree(::profiler::timestamp_t& _beginTime, const unsigned int _blocksNumber, const ::profiler::thread_blocks_tree_t& _blocksTree, bool _colorizeRows, EasyTreeMode _mode);
  100. void fillTreeBlocks(const::profiler_gui::TreeBlocks& _blocks, ::profiler::timestamp_t _beginTime, ::profiler::timestamp_t _left, ::profiler::timestamp_t _right, bool _strict, bool _colorizeRows, EasyTreeMode _mode);
  101. private:
  102. bool interrupted() const;
  103. void setDone();
  104. void setProgress(int _progress);
  105. void setTreeInternal1(::profiler::timestamp_t& _beginTime, const unsigned int _blocksNumber, const ::profiler::thread_blocks_tree_t& _blocksTree, bool _colorizeRows, bool _addZeroBlocks, bool _decoratedThreadNames, bool _hexThreadId, ::profiler_gui::TimeUnits _units);
  106. void setTreeInternal2(const ::profiler::timestamp_t& _beginTime, const ::profiler_gui::TreeBlocks& _blocks, ::profiler::timestamp_t _left, ::profiler::timestamp_t _right, bool _strict, bool _colorizeRows, bool _addZeroBlocks, bool _decoratedThreadNames, bool _hexThreadId, ::profiler_gui::TimeUnits _units);
  107. size_t setTreeInternal(const ::profiler::BlocksTreeRoot& _threadRoot, ::profiler::block_index_t _firstCswitch, const ::profiler::timestamp_t& _beginTime, const ::profiler::BlocksTree::children_t& _children, EasyTreeWidgetItem* _parent, EasyTreeWidgetItem* _frame, ::profiler::timestamp_t _left, ::profiler::timestamp_t _right, bool _strict, ::profiler::timestamp_t& _duration, bool _colorizeRows, bool _addZeroBlocks, ::profiler_gui::TimeUnits _units);
  108. size_t setTreeInternalPlain(const ::profiler::BlocksTreeRoot& _threadRoot, ::profiler::block_index_t _firstCswitch, const ::profiler::timestamp_t& _beginTime, const ::profiler::BlocksTree::children_t& _children, EasyTreeWidgetItem* _parent, EasyTreeWidgetItem* _frame, ::profiler::timestamp_t _left, ::profiler::timestamp_t _right, bool _strict, ::profiler::timestamp_t& _duration, bool _colorizeRows, bool _addZeroBlocks, ::profiler_gui::TimeUnits _units);
  109. ::profiler::timestamp_t calculateChildrenDurationRecursive(const ::profiler::BlocksTree::children_t& _children, ::profiler::block_id_t _id);
  110. }; // END of class EasyTreeWidgetLoader.
  111. //////////////////////////////////////////////////////////////////////////
  112. #endif // EASY_TREE_WIDGET_LOADER_H