globals.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /************************************************************************
  2. * file name : globals.h
  3. * ----------------- :
  4. * creation time : 2016/08/03
  5. * author : Victor Zarubkin
  6. * email : [email protected]
  7. * ----------------- :
  8. * description : The file contains declaration of global constants and variables for profiler gui.
  9. * ----------------- :
  10. * change log : * 2016/08/03 Victor Zarubkin: initial commit.
  11. * :
  12. * : *
  13. * ----------------- :
  14. * license : Lightweight profiler library for c++
  15. * : Copyright(C) 2016-2017 Sergey Yagovtsev, Victor Zarubkin
  16. * :
  17. * : Licensed under either of
  18. * : * MIT license (LICENSE.MIT or http://opensource.org/licenses/MIT)
  19. * : * Apache License, Version 2.0, (LICENSE.APACHE or http://www.apache.org/licenses/LICENSE-2.0)
  20. * : at your option.
  21. * :
  22. * : The MIT License
  23. * :
  24. * : Permission is hereby granted, free of charge, to any person obtaining a copy
  25. * : of this software and associated documentation files (the "Software"), to deal
  26. * : in the Software without restriction, including without limitation the rights
  27. * : to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  28. * : of the Software, and to permit persons to whom the Software is furnished
  29. * : to do so, subject to the following conditions:
  30. * :
  31. * : The above copyright notice and this permission notice shall be included in all
  32. * : copies or substantial portions of the Software.
  33. * :
  34. * : THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  35. * : INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  36. * : PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  37. * : LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  38. * : TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  39. * : USE OR OTHER DEALINGS IN THE SOFTWARE.
  40. * :
  41. * : The Apache License, Version 2.0 (the "License")
  42. * :
  43. * : You may not use this file except in compliance with the License.
  44. * : You may obtain a copy of the License at
  45. * :
  46. * : http://www.apache.org/licenses/LICENSE-2.0
  47. * :
  48. * : Unless required by applicable law or agreed to in writing, software
  49. * : distributed under the License is distributed on an "AS IS" BASIS,
  50. * : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  51. * : See the License for the specific language governing permissions and
  52. * : limitations under the License.
  53. ************************************************************************/
  54. #ifndef EASY_PROFILER__GUI_GLOBALS_H
  55. #define EASY_PROFILER__GUI_GLOBALS_H
  56. #include <string>
  57. #include <QObject>
  58. #include <QColor>
  59. #include <QTextCodec>
  60. #include <QSize>
  61. #include "common_types.h"
  62. #include "globals_qobjects.h"
  63. //////////////////////////////////////////////////////////////////////////
  64. //////////////////////////////////////////////////////////////////////////
  65. namespace profiler_gui {
  66. const QString ORGANAZATION_NAME = "EasyProfiler";
  67. const QString APPLICATION_NAME = "Easy profiler gui application";
  68. const QColor CHRONOMETER_COLOR = QColor::fromRgba(0x40000000 | (::profiler::colors::RichBlue & 0x00ffffff));// 0x402020c0);
  69. const QColor CHRONOMETER_COLOR2 = QColor::fromRgba(0x40000000 | (::profiler::colors::Dark & 0x00ffffff));// 0x40408040);
  70. const QRgb SELECTED_THREAD_BACKGROUND = 0x00e0e060;
  71. const QRgb SELECTED_THREAD_FOREGROUND = 0x00ffffff - SELECTED_THREAD_BACKGROUND;
  72. const qreal SCALING_COEFFICIENT = 1.25;
  73. const qreal SCALING_COEFFICIENT_INV = 1.0 / SCALING_COEFFICIENT;
  74. const uint32_t V130 = 0x01030000;
  75. const QSize ICONS_SIZE(28, 28);
  76. const uint16_t GRAPHICS_ROW_SIZE = 18;
  77. const uint16_t GRAPHICS_ROW_SPACING = 0;
  78. const uint16_t GRAPHICS_ROW_SIZE_FULL = GRAPHICS_ROW_SIZE + GRAPHICS_ROW_SPACING;
  79. const uint16_t THREADS_ROW_SPACING = 8;
  80. #ifdef _WIN32
  81. const qreal FONT_METRICS_FACTOR = 1.05;
  82. #else
  83. const qreal FONT_METRICS_FACTOR = 1.;
  84. #endif
  85. //////////////////////////////////////////////////////////////////////////
  86. template <class T>
  87. inline auto toUnicode(const T& _inputString) -> decltype(QTextCodec::codecForLocale()->toUnicode(_inputString))
  88. {
  89. return QTextCodec::codecForLocale()->toUnicode(_inputString);
  90. }
  91. //////////////////////////////////////////////////////////////////////////
  92. inline QString decoratedThreadName(bool _use_decorated_thread_name, const::profiler::BlocksTreeRoot& _root, const QString& _unicodeThreadWord, bool _hex = false)
  93. {
  94. if (_root.got_name())
  95. {
  96. QString rootname(toUnicode(_root.name()));
  97. if (!_use_decorated_thread_name || rootname.contains(_unicodeThreadWord, Qt::CaseInsensitive))
  98. {
  99. if (_hex)
  100. return QString("%1 0x%2").arg(rootname).arg(_root.thread_id, 0, 16);
  101. return QString("%1 %2").arg(rootname).arg(_root.thread_id);
  102. }
  103. if (_hex)
  104. return QString("%1 Thread 0x%2").arg(rootname).arg(_root.thread_id, 0, 16);
  105. return QString("%1 Thread %2").arg(rootname).arg(_root.thread_id);
  106. }
  107. if (_hex)
  108. return QString("Thread 0x%1").arg(_root.thread_id, 0, 16);
  109. return QString("Thread %1").arg(_root.thread_id);
  110. }
  111. inline QString decoratedThreadName(bool _use_decorated_thread_name, const ::profiler::BlocksTreeRoot& _root, bool _hex = false)
  112. {
  113. if (_root.got_name())
  114. {
  115. QString rootname(toUnicode(_root.name()));
  116. if (!_use_decorated_thread_name || rootname.contains(toUnicode("thread"), Qt::CaseInsensitive))
  117. {
  118. if (_hex)
  119. return QString("%1 0x%2").arg(rootname).arg(_root.thread_id, 0, 16);
  120. return QString("%1 %2").arg(rootname).arg(_root.thread_id);
  121. }
  122. if (_hex)
  123. return QString("%1 Thread 0x%2").arg(rootname).arg(_root.thread_id, 0, 16);
  124. return QString("%1 Thread %2").arg(rootname).arg(_root.thread_id);
  125. }
  126. if (_hex)
  127. return QString("Thread 0x%1").arg(_root.thread_id, 0, 16);
  128. return QString("Thread %1").arg(_root.thread_id);
  129. }
  130. //////////////////////////////////////////////////////////////////////////
  131. enum ChronometerTextPosition : int8_t
  132. {
  133. ChronoTextPosition_Center = 0,
  134. ChronoTextPosition_Top,
  135. ChronoTextPosition_Bottom,
  136. }; // END of enum ChronometerTextPosition.
  137. //////////////////////////////////////////////////////////////////////////
  138. struct EasyGlobals Q_DECL_FINAL
  139. {
  140. static EasyGlobals& instance();
  141. EasyGlobalSignals events; ///< Global signals
  142. ::profiler::thread_blocks_tree_t profiler_blocks; ///< Profiler blocks tree loaded from file
  143. ::profiler::descriptors_list_t descriptors; ///< Profiler block descriptors list
  144. EasyBlocks gui_blocks; ///< Profiler graphics blocks builded by GUI
  145. ::profiler::timestamp_t begin_time; ///<
  146. ::profiler::thread_id_t selected_thread; ///< Current selected thread id
  147. ::profiler::block_index_t selected_block; ///< Current selected profiler block index
  148. ::profiler::block_id_t selected_block_id; ///< Current selected profiler block id
  149. uint32_t version; ///< Opened file version (files may have different format)
  150. float frame_time; ///< Expected frame time value in microseconds to be displayed at minimap on graphics scrollbar
  151. int blocks_spacing; ///< Minimum blocks spacing on diagram
  152. int blocks_size_min; ///< Minimum blocks size on diagram
  153. int blocks_narrow_size; ///< Width indicating narrow blocks
  154. int max_fps_history; ///< Max frames history displayed in FPS Monitor
  155. int fps_timer_interval; ///< Interval in milliseconds for sending network requests to the profiled application (used by FPS Monitor)
  156. int fps_widget_line_width; ///< Line width in pixels of FPS lines for FPS Monitor
  157. ChronometerTextPosition chrono_text_position; ///< Selected interval text position
  158. TimeUnits time_units; ///< Units type for time (milliseconds, microseconds, nanoseconds or auto-definition)
  159. bool connected; ///< Is connected to source (to be able to capture profiling information)
  160. bool fps_enabled; ///< Is FPS Monitor enabled
  161. bool use_decorated_thread_name; ///< Add "Thread" to the name of each thread (if there is no one)
  162. bool hex_thread_id; ///< Use hex view for thread-id instead of decimal
  163. bool enable_event_markers; ///< Enable event indicators painting (These are narrow rectangles at the bottom of each thread)
  164. bool enable_statistics; ///< Enable gathering and using statistics (Disable if you want to consume less memory)
  165. bool enable_zero_length; ///< Enable zero length blocks (if true, then such blocks will have width == 1 pixel on each scale)
  166. bool add_zero_blocks_to_hierarchy; ///< Enable adding zero blocks into hierarchy tree
  167. bool draw_graphics_items_borders; ///< Draw borders for graphics blocks or not
  168. bool hide_narrow_children; ///< Hide children for narrow graphics blocks (See blocks_narrow_size)
  169. bool hide_minsize_blocks; ///< Hide blocks which screen size is less than blocks_size_min
  170. bool display_only_relevant_stats; ///< Display only relevant information in ProfTreeWidget (excludes min, max, average times if there are only 1 calls number)
  171. bool collapse_items_on_tree_close; ///< Collapse all items which were displayed in the hierarchy tree after tree close/reset
  172. bool all_items_expanded_by_default; ///< Expand all items after file is opened
  173. bool only_current_thread_hierarchy; ///< Build hierarchy tree for current thread only
  174. bool highlight_blocks_with_same_id; ///< Highlight all blocks with same id on diagram
  175. bool selecting_block_changes_thread; ///< If true then current selected thread will change every time you select block
  176. bool auto_adjust_histogram_height; ///< Automatically adjust histogram height to the visible region
  177. bool display_only_frames_on_histogram; ///< Display only top-level blocks on histogram when drawing histogram by block id
  178. bool bind_scene_and_tree_expand_status; /** \brief If true then items on graphics scene and in the tree (blocks hierarchy) are binded on each other
  179. so expanding/collapsing items on scene also expands/collapse items in the tree. */
  180. private:
  181. EasyGlobals();
  182. }; // END of struct EasyGlobals.
  183. //////////////////////////////////////////////////////////////////////////
  184. } // END of namespace profiler_gui.
  185. #ifndef IGNORE_GLOBALS_DECLARATION
  186. static ::profiler_gui::EasyGlobals& EASY_GLOBALS = ::profiler_gui::EasyGlobals::instance();
  187. inline ::profiler_gui::EasyBlock& easyBlock(::profiler::block_index_t i) {
  188. return EASY_GLOBALS.gui_blocks[i];
  189. }
  190. inline ::profiler::SerializedBlockDescriptor& easyDescriptor(::profiler::block_id_t i) {
  191. return *EASY_GLOBALS.descriptors[i];
  192. }
  193. inline ::profiler::BlocksTree& blocksTree(::profiler::block_index_t i) {
  194. return easyBlock(i).tree;
  195. }
  196. #endif
  197. #define SET_ICON(objectName, iconName) { QIcon icon(iconName); if (!icon.isNull()) objectName->setIcon(icon); }
  198. //////////////////////////////////////////////////////////////////////////
  199. //////////////////////////////////////////////////////////////////////////
  200. #endif // EASY_PROFILER__GUI_GLOBALS_H