main_window.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. /************************************************************************
  2. * file name : main_window.h
  3. * ----------------- :
  4. * creation time : 2016/06/26
  5. * author : Victor Zarubkin
  6. * email : [email protected]
  7. * ----------------- :
  8. * description : The file contains declaration of MainWindow for easy_profiler GUI.
  9. * ----------------- :
  10. * change log : * 2016/06/26 Victor Zarubkin: initial commit.
  11. * : *
  12. * ----------------- :
  13. * license : Lightweight profiler library for c++
  14. * : Copyright(C) 2016-2017 Sergey Yagovtsev, Victor Zarubkin
  15. * :
  16. * : Licensed under either of
  17. * : * MIT license (LICENSE.MIT or http://opensource.org/licenses/MIT)
  18. * : * Apache License, Version 2.0, (LICENSE.APACHE or http://www.apache.org/licenses/LICENSE-2.0)
  19. * : at your option.
  20. * :
  21. * : The MIT License
  22. * :
  23. * : Permission is hereby granted, free of charge, to any person obtaining a copy
  24. * : of this software and associated documentation files (the "Software"), to deal
  25. * : in the Software without restriction, including without limitation the rights
  26. * : to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  27. * : of the Software, and to permit persons to whom the Software is furnished
  28. * : to do so, subject to the following conditions:
  29. * :
  30. * : The above copyright notice and this permission notice shall be included in all
  31. * : copies or substantial portions of the Software.
  32. * :
  33. * : THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  34. * : INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  35. * : PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  36. * : LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  37. * : TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  38. * : USE OR OTHER DEALINGS IN THE SOFTWARE.
  39. * :
  40. * : The Apache License, Version 2.0 (the "License")
  41. * :
  42. * : You may not use this file except in compliance with the License.
  43. * : You may obtain a copy of the License at
  44. * :
  45. * : http://www.apache.org/licenses/LICENSE-2.0
  46. * :
  47. * : Unless required by applicable law or agreed to in writing, software
  48. * : distributed under the License is distributed on an "AS IS" BASIS,
  49. * : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  50. * : See the License for the specific language governing permissions and
  51. * : limitations under the License.
  52. ************************************************************************/
  53. #ifndef EASY_PROFILER_GUI__MAIN_WINDOW__H
  54. #define EASY_PROFILER_GUI__MAIN_WINDOW__H
  55. #include <string>
  56. #include <thread>
  57. #include <atomic>
  58. #include <sstream>
  59. #include <QMainWindow>
  60. #include <QTimer>
  61. #include <QStringList>
  62. #include <easy/easy_socket.h>
  63. #include <easy/reader.h>
  64. #ifdef max
  65. #undef max
  66. #endif
  67. #ifdef min
  68. #undef min
  69. #endif
  70. //////////////////////////////////////////////////////////////////////////
  71. #define EASY_GUI_USE_DESCRIPTORS_DOCK_WINDOW 0
  72. class QDockWidget;
  73. namespace profiler { namespace net { struct EasyProfilerStatus; } }
  74. //////////////////////////////////////////////////////////////////////////
  75. class EasyFileReader Q_DECL_FINAL
  76. {
  77. ::profiler::SerializedData m_serializedBlocks; ///<
  78. ::profiler::SerializedData m_serializedDescriptors; ///<
  79. ::profiler::descriptors_list_t m_descriptors; ///<
  80. ::profiler::blocks_t m_blocks; ///<
  81. ::profiler::thread_blocks_tree_t m_blocksTree; ///<
  82. ::std::stringstream m_stream; ///<
  83. ::std::stringstream m_errorMessage; ///<
  84. QString m_filename; ///<
  85. uint32_t m_descriptorsNumberInFile = 0; ///<
  86. uint32_t m_version = 0; ///<
  87. ::std::thread m_thread; ///<
  88. ::std::atomic_bool m_bDone; ///<
  89. ::std::atomic<int> m_progress; ///<
  90. ::std::atomic<unsigned int> m_size; ///<
  91. bool m_isFile = false; ///<
  92. public:
  93. EasyFileReader();
  94. ~EasyFileReader();
  95. const bool isFile() const;
  96. bool done() const;
  97. int progress() const;
  98. unsigned int size() const;
  99. const QString& filename() const;
  100. void load(const QString& _filename);
  101. void load(::std::stringstream& _stream);
  102. void interrupt();
  103. void get(::profiler::SerializedData& _serializedBlocks, ::profiler::SerializedData& _serializedDescriptors,
  104. ::profiler::descriptors_list_t& _descriptors, ::profiler::blocks_t& _blocks, ::profiler::thread_blocks_tree_t& _tree,
  105. uint32_t& _descriptorsNumberInFile, uint32_t& _version, QString& _filename);
  106. QString getError();
  107. }; // END of class EasyFileReader.
  108. //////////////////////////////////////////////////////////////////////////
  109. enum EasyListenerRegime : uint8_t
  110. {
  111. LISTENER_IDLE = 0,
  112. LISTENER_CAPTURE,
  113. LISTENER_CAPTURE_RECEIVE,
  114. LISTENER_DESCRIBE
  115. };
  116. class EasySocketListener Q_DECL_FINAL
  117. {
  118. EasySocket m_easySocket; ///<
  119. ::std::string m_address; ///<
  120. ::std::stringstream m_receivedData; ///<
  121. ::std::thread m_thread; ///<
  122. uint64_t m_receivedSize; ///<
  123. uint16_t m_port; ///<
  124. ::std::atomic<uint32_t> m_frameMax; ///<
  125. ::std::atomic<uint32_t> m_frameAvg; ///<
  126. ::std::atomic_bool m_bInterrupt; ///<
  127. ::std::atomic_bool m_bConnected; ///<
  128. ::std::atomic_bool m_bStopReceive; ///<
  129. ::std::atomic_bool m_bCaptureReady; ///<
  130. ::std::atomic_bool m_bFrameTimeReady; ///<
  131. EasyListenerRegime m_regime; ///<
  132. public:
  133. EasySocketListener();
  134. ~EasySocketListener();
  135. bool connected() const;
  136. bool captured() const;
  137. EasyListenerRegime regime() const;
  138. uint64_t size() const;
  139. const ::std::string& address() const;
  140. uint16_t port() const;
  141. ::std::stringstream& data();
  142. void clearData();
  143. void disconnect();
  144. bool connect(const char* _ipaddress, uint16_t _port, ::profiler::net::EasyProfilerStatus& _reply);
  145. bool startCapture();
  146. void stopCapture();
  147. void finalizeCapture();
  148. void requestBlocksDescription();
  149. bool frameTime(uint32_t& _maxTime, uint32_t& _avgTime);
  150. bool requestFrameTime();
  151. template <class T>
  152. inline void send(const T& _message) {
  153. m_easySocket.send(&_message, sizeof(T));
  154. }
  155. private:
  156. void listenCapture();
  157. void listenDescription();
  158. void listenFrameTime();
  159. }; // END of class EasySocketListener.
  160. //////////////////////////////////////////////////////////////////////////
  161. class EasyMainWindow : public QMainWindow
  162. {
  163. Q_OBJECT
  164. protected:
  165. typedef EasyMainWindow This;
  166. typedef QMainWindow Parent;
  167. QStringList m_lastFiles;
  168. QString m_lastAddress;
  169. QDockWidget* m_treeWidget = nullptr;
  170. QDockWidget* m_graphicsView = nullptr;
  171. QDockWidget* m_fpsViewer = nullptr;
  172. #if EASY_GUI_USE_DESCRIPTORS_DOCK_WINDOW != 0
  173. QDockWidget* m_descTreeWidget = nullptr;
  174. #endif
  175. class QProgressDialog* m_progress = nullptr;
  176. class QDialog* m_descTreeDialog = nullptr;
  177. class EasyDescWidget* m_dialogDescTree = nullptr;
  178. class QMessageBox* m_listenerDialog = nullptr;
  179. QTimer m_readerTimer;
  180. QTimer m_listenerTimer;
  181. QTimer m_fpsRequestTimer;
  182. ::profiler::SerializedData m_serializedBlocks;
  183. ::profiler::SerializedData m_serializedDescriptors;
  184. EasyFileReader m_reader;
  185. EasySocketListener m_listener;
  186. class QLineEdit* m_addressEdit = nullptr;
  187. class QLineEdit* m_portEdit = nullptr;
  188. class QLineEdit* m_frameTimeEdit = nullptr;
  189. class QMenu* m_loadActionMenu = nullptr;
  190. class QAction* m_saveAction = nullptr;
  191. class QAction* m_deleteAction = nullptr;
  192. class QAction* m_captureAction = nullptr;
  193. class QAction* m_connectAction = nullptr;
  194. class QAction* m_eventTracingEnableAction = nullptr;
  195. class QAction* m_eventTracingPriorityAction = nullptr;
  196. uint32_t m_descriptorsNumberInFile = 0;
  197. uint16_t m_lastPort = 0;
  198. bool m_bNetworkFileRegime = false;
  199. bool m_bOpenedCacheFile = false;
  200. public:
  201. explicit EasyMainWindow();
  202. virtual ~EasyMainWindow();
  203. // Public virtual methods
  204. void closeEvent(QCloseEvent* close_event) override;
  205. void dragEnterEvent(QDragEnterEvent* drag_event) override;
  206. void dragMoveEvent(QDragMoveEvent* drag_event) override;
  207. void dragLeaveEvent(QDragLeaveEvent* drag_event) override;
  208. void dropEvent(QDropEvent* drop_event) override;
  209. protected slots:
  210. void onOpenFileClicked(bool);
  211. void onSaveFileClicked(bool);
  212. void onDeleteClicked(bool);
  213. void onExitClicked(bool);
  214. void onEncodingChanged(bool);
  215. void onChronoTextPosChanged(bool);
  216. void onUnitsChanged(bool);
  217. void onEnableDisableStatistics(bool);
  218. void onCollapseItemsAfterCloseChanged(bool);
  219. void onAllItemsExpandedByDefaultChange(bool);
  220. void onBindExpandStatusChange(bool);
  221. void onHierarchyFlagChange(bool);
  222. void onExpandAllClicked(bool);
  223. void onCollapseAllClicked(bool);
  224. void onSpacingChange(int _value);
  225. void onMinSizeChange(int _value);
  226. void onNarrowSizeChange(int _value);
  227. void onFpsIntervalChange(int _value);
  228. void onFpsHistoryChange(int _value);
  229. void onFpsMonitorLineWidthChange(int _value);
  230. void onFileReaderTimeout();
  231. void onFrameTimeRequestTimeout();
  232. void onListenerTimerTimeout();
  233. void onFileReaderCancel();
  234. void onEditBlocksClicked(bool);
  235. void onDescTreeDialogClose(int);
  236. void onListenerDialogClose(int);
  237. void onCaptureClicked(bool);
  238. void onGetBlockDescriptionsClicked(bool);
  239. void onConnectClicked(bool);
  240. void onEventTracingPriorityChange(bool _checked);
  241. void onEventTracingEnableChange(bool _checked);
  242. void onFrameTimeEditFinish();
  243. void onFrameTimeChanged();
  244. void onBlockStatusChange(::profiler::block_id_t _id, ::profiler::EasyBlockStatus _status);
  245. void checkFrameTimeReady();
  246. private:
  247. // Private non-virtual methods
  248. void clear();
  249. void refreshDiagram();
  250. void addFileToList(const QString& filename);
  251. void loadFile(const QString& filename);
  252. void readStream(::std::stringstream& data);
  253. void loadSettings();
  254. void loadGeometry();
  255. void saveSettingsAndGeometry();
  256. void setDisconnected(bool _showMessage = true);
  257. }; // END of class EasyMainWindow.
  258. //////////////////////////////////////////////////////////////////////////
  259. #endif // EASY_PROFILER_GUI__MAIN_WINDOW__H