main_window.cpp 99 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858
  1. /************************************************************************
  2. * file name : main_window.cpp
  3. * ----------------- :
  4. * creation time : 2016/06/26
  5. * author : Victor Zarubkin
  6. * email : [email protected]
  7. * ----------------- :
  8. * description : The file contains implementation of MainWindow for easy_profiler GUI.
  9. * ----------------- :
  10. * change log : * 2016/06/26 Victor Zarubkin: Initial commit.
  11. * :
  12. * : * 2016/06/27 Victor Zarubkin: Passing blocks number to EasyTreeWidget::setTree().
  13. * :
  14. * : * 2016/06/29 Victor Zarubkin: Added menu with tests.
  15. * :
  16. * : * 2016/06/30 Sergey Yagovtsev: Open file by command line argument
  17. * :
  18. * : *
  19. * ----------------- :
  20. * license : Lightweight profiler library for c++
  21. * : Copyright(C) 2016-2017 Sergey Yagovtsev, Victor Zarubkin
  22. * :
  23. * : Licensed under either of
  24. * : * MIT license (LICENSE.MIT or http://opensource.org/licenses/MIT)
  25. * : * Apache License, Version 2.0, (LICENSE.APACHE or http://www.apache.org/licenses/LICENSE-2.0)
  26. * : at your option.
  27. * :
  28. * : The MIT License
  29. * :
  30. * : Permission is hereby granted, free of charge, to any person obtaining a copy
  31. * : of this software and associated documentation files (the "Software"), to deal
  32. * : in the Software without restriction, including without limitation the rights
  33. * : to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  34. * : of the Software, and to permit persons to whom the Software is furnished
  35. * : to do so, subject to the following conditions:
  36. * :
  37. * : The above copyright notice and this permission notice shall be included in all
  38. * : copies or substantial portions of the Software.
  39. * :
  40. * : THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  41. * : INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  42. * : PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  43. * : LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  44. * : TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  45. * : USE OR OTHER DEALINGS IN THE SOFTWARE.
  46. * :
  47. * : The Apache License, Version 2.0 (the "License")
  48. * :
  49. * : You may not use this file except in compliance with the License.
  50. * : You may obtain a copy of the License at
  51. * :
  52. * : http://www.apache.org/licenses/LICENSE-2.0
  53. * :
  54. * : Unless required by applicable law or agreed to in writing, software
  55. * : distributed under the License is distributed on an "AS IS" BASIS,
  56. * : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  57. * : See the License for the specific language governing permissions and
  58. * : limitations under the License.
  59. ************************************************************************/
  60. #include <chrono>
  61. #include <fstream>
  62. #include <QApplication>
  63. #include <QCoreApplication>
  64. #include <QStatusBar>
  65. #include <QDockWidget>
  66. #include <QFileDialog>
  67. #include <QAction>
  68. #include <QMenu>
  69. #include <QMenuBar>
  70. #include <QCloseEvent>
  71. #include <QSettings>
  72. #include <QTextCodec>
  73. #include <QFont>
  74. #include <QProgressDialog>
  75. #include <QSignalBlocker>
  76. #include <QDebug>
  77. #include <QToolBar>
  78. #include <QToolButton>
  79. #include <QWidgetAction>
  80. #include <QSpinBox>
  81. #include <QMessageBox>
  82. #include <QLineEdit>
  83. #include <QLabel>
  84. #include <QDialog>
  85. #include <QVBoxLayout>
  86. #include <QFile>
  87. #include <QFileInfo>
  88. #include <QDragEnterEvent>
  89. #include <QDragMoveEvent>
  90. #include <QDragLeaveEvent>
  91. #include <QDropEvent>
  92. #include <QMimeData>
  93. #include <QDateTime>
  94. #include "main_window.h"
  95. #include "blocks_tree_widget.h"
  96. #include "blocks_graphics_view.h"
  97. #include "descriptors_tree_widget.h"
  98. #include "easy_frame_rate_viewer.h"
  99. #include "globals.h"
  100. #include <easy/easy_net.h>
  101. #ifdef max
  102. #undef max
  103. #endif
  104. #ifdef min
  105. #undef min
  106. #endif
  107. //////////////////////////////////////////////////////////////////////////
  108. #define EASY_DEFAULT_WINDOW_TITLE "EasyProfiler"
  109. const int LOADER_TIMER_INTERVAL = 40;
  110. const auto NETWORK_CACHE_FILE = "easy_profiler_stream.cache";
  111. //////////////////////////////////////////////////////////////////////////
  112. inline void clear_stream(std::stringstream& _stream)
  113. {
  114. #if defined(__GNUC__) && __GNUC__ < 5
  115. // gcc 4 has a known bug which has been solved in gcc 5:
  116. // std::stringstream has no swap() method :(
  117. _stream.str(std::string());
  118. #else
  119. std::stringstream().swap(_stream);
  120. #endif
  121. }
  122. //////////////////////////////////////////////////////////////////////////
  123. EasyMainWindow::EasyMainWindow() : Parent(), m_lastAddress("localhost"), m_lastPort(::profiler::DEFAULT_PORT)
  124. {
  125. { QIcon icon(":/logo"); if (!icon.isNull()) QApplication::setWindowIcon(icon); }
  126. setObjectName("ProfilerGUI_MainWindow");
  127. setWindowTitle(EASY_DEFAULT_WINDOW_TITLE);
  128. setDockNestingEnabled(true);
  129. setAcceptDrops(true);
  130. resize(800, 600);
  131. setStatusBar(nullptr);
  132. m_graphicsView = new QDockWidget("Diagram", this);
  133. m_graphicsView->setObjectName("ProfilerGUI_Diagram");
  134. m_graphicsView->setMinimumHeight(50);
  135. m_graphicsView->setAllowedAreas(Qt::AllDockWidgetAreas);
  136. auto graphicsView = new EasyGraphicsViewWidget(this);
  137. m_graphicsView->setWidget(graphicsView);
  138. m_treeWidget = new QDockWidget("Hierarchy", this);
  139. m_treeWidget->setObjectName("ProfilerGUI_Hierarchy");
  140. m_treeWidget->setMinimumHeight(50);
  141. m_treeWidget->setAllowedAreas(Qt::AllDockWidgetAreas);
  142. auto treeWidget = new EasyHierarchyWidget(this);
  143. m_treeWidget->setWidget(treeWidget);
  144. m_fpsViewer = new QDockWidget("FPS Monitor", this);
  145. m_fpsViewer->setObjectName("ProfilerGUI_FPS");
  146. m_fpsViewer->setWidget(new EasyFrameRateViewer(this));
  147. m_fpsViewer->setAllowedAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
  148. addDockWidget(Qt::TopDockWidgetArea, m_graphicsView);
  149. addDockWidget(Qt::BottomDockWidgetArea, m_treeWidget);
  150. addDockWidget(Qt::TopDockWidgetArea, m_fpsViewer);
  151. #if EASY_GUI_USE_DESCRIPTORS_DOCK_WINDOW != 0
  152. auto descTree = new EasyDescWidget();
  153. m_descTreeWidget = new QDockWidget("Blocks");
  154. m_descTreeWidget->setObjectName("ProfilerGUI_Blocks");
  155. m_descTreeWidget->setMinimumHeight(50);
  156. m_descTreeWidget->setAllowedAreas(Qt::AllDockWidgetAreas);
  157. m_descTreeWidget->setWidget(descTree);
  158. addDockWidget(Qt::BottomDockWidgetArea, m_descTreeWidget);
  159. #endif
  160. loadSettings();
  161. auto toolbar = addToolBar("FileToolbar");
  162. toolbar->setIconSize(::profiler_gui::ICONS_SIZE);
  163. toolbar->setObjectName("ProfilerGUI_FileToolbar");
  164. toolbar->setContentsMargins(1, 0, 1, 0);
  165. m_loadActionMenu = new QMenu(this);
  166. auto action = m_loadActionMenu->menuAction();
  167. action->setText("Open file");
  168. action->setIcon(QIcon(":/Open"));
  169. connect(action, &QAction::triggered, this, &This::onOpenFileClicked);
  170. toolbar->addAction(action);
  171. for (const auto& f : m_lastFiles)
  172. {
  173. action = new QAction(f, this);
  174. connect(action, &QAction::triggered, this, &This::onOpenFileClicked);
  175. m_loadActionMenu->addAction(action);
  176. }
  177. m_saveAction = toolbar->addAction(QIcon(":/Save"), tr("Save"), this, SLOT(onSaveFileClicked(bool)));
  178. m_deleteAction = toolbar->addAction(QIcon(":/Delete"), tr("Clear all"), this, SLOT(onDeleteClicked(bool)));
  179. m_saveAction->setEnabled(false);
  180. m_deleteAction->setEnabled(false);
  181. toolbar = addToolBar("ProfileToolbar");
  182. toolbar->setIconSize(::profiler_gui::ICONS_SIZE);
  183. toolbar->setObjectName("ProfilerGUI_ProfileToolbar");
  184. toolbar->setContentsMargins(1, 0, 1, 0);
  185. toolbar->addAction(QIcon(":/List"), tr("Blocks"), this, SLOT(onEditBlocksClicked(bool)));
  186. m_captureAction = toolbar->addAction(QIcon(":/Start"), tr("Capture"), this, SLOT(onCaptureClicked(bool)));
  187. m_captureAction->setEnabled(false);
  188. toolbar->addSeparator();
  189. m_connectAction = toolbar->addAction(QIcon(":/Connection"), tr("Connect"), this, SLOT(onConnectClicked(bool)));
  190. auto lbl = new QLabel("Address:", toolbar);
  191. lbl->setContentsMargins(5, 0, 2, 0);
  192. toolbar->addWidget(lbl);
  193. m_addressEdit = new QLineEdit();
  194. m_addressEdit->setToolTip("Enter IP-address or host name");
  195. //QRegExp rx("^0*(2(5[0-5]|[0-4]\\d)|1?\\d{1,2})(\\.0*(2(5[0-5]|[0-4]\\d)|1?\\d{1,2})){3}$");
  196. //m_addressEdit->setValidator(new QRegExpValidator(rx, m_addressEdit));
  197. m_addressEdit->setText(m_lastAddress);
  198. m_addressEdit->setFixedWidth((m_addressEdit->fontMetrics().width(QString("255.255.255.255")) * 3) / 2);
  199. toolbar->addWidget(m_addressEdit);
  200. lbl = new QLabel("Port:", toolbar);
  201. lbl->setContentsMargins(5, 0, 2, 0);
  202. toolbar->addWidget(lbl);
  203. m_portEdit = new QLineEdit();
  204. m_portEdit->setValidator(new QIntValidator(1, 65535, m_portEdit));
  205. m_portEdit->setText(QString::number(m_lastPort));
  206. m_portEdit->setFixedWidth(m_portEdit->fontMetrics().width(QString("000000")) + 10);
  207. toolbar->addWidget(m_portEdit);
  208. connect(m_addressEdit, &QLineEdit::returnPressed, [this](){ onConnectClicked(true); });
  209. connect(m_portEdit, &QLineEdit::returnPressed, [this](){ onConnectClicked(true); });
  210. toolbar = addToolBar("SetupToolbar");
  211. toolbar->setIconSize(::profiler_gui::ICONS_SIZE);
  212. toolbar->setObjectName("ProfilerGUI_SetupToolbar");
  213. toolbar->setContentsMargins(1, 0, 1, 0);
  214. toolbar->addAction(QIcon(":/Expand"), "Expand all", this, SLOT(onExpandAllClicked(bool)));
  215. toolbar->addAction(QIcon(":/Collapse"), "Collapse all", this, SLOT(onCollapseAllClicked(bool)));
  216. toolbar->addSeparator();
  217. auto menu = new QMenu("Settings", this);
  218. menu->setToolTipsVisible(true);
  219. QToolButton* toolButton = new QToolButton(toolbar);
  220. toolButton->setIcon(QIcon(":/Settings"));
  221. toolButton->setMenu(menu);
  222. toolButton->setPopupMode(QToolButton::InstantPopup);
  223. toolbar->addWidget(toolButton);
  224. action = menu->addAction("Statistics enabled");
  225. action->setCheckable(true);
  226. action->setChecked(EASY_GLOBALS.enable_statistics);
  227. connect(action, &QAction::triggered, this, &This::onEnableDisableStatistics);
  228. if (EASY_GLOBALS.enable_statistics)
  229. {
  230. auto f = action->font();
  231. f.setBold(true);
  232. action->setFont(f);
  233. SET_ICON(action, ":/Stats");
  234. }
  235. else
  236. {
  237. action->setText("Statistics disabled");
  238. SET_ICON(action, ":/Stats-off");
  239. }
  240. action = menu->addAction("Only frames on histogram");
  241. action->setToolTip("Display only top-level blocks on histogram.");
  242. action->setCheckable(true);
  243. action->setChecked(EASY_GLOBALS.display_only_frames_on_histogram);
  244. connect(action, &QAction::triggered, [this](bool _checked)
  245. {
  246. EASY_GLOBALS.display_only_frames_on_histogram = _checked;
  247. emit EASY_GLOBALS.events.displayOnlyFramesOnHistogramChanged();
  248. });
  249. menu->addSeparator();
  250. auto submenu = menu->addMenu("View");
  251. submenu->setToolTipsVisible(true);
  252. action = submenu->addAction("Draw items' borders");
  253. action->setToolTip("Draw borders for blocks on diagram.\nThis reduces performance.");
  254. action->setCheckable(true);
  255. action->setChecked(EASY_GLOBALS.draw_graphics_items_borders);
  256. connect(action, &QAction::triggered, [this](bool _checked){ EASY_GLOBALS.draw_graphics_items_borders = _checked; refreshDiagram(); });
  257. action = submenu->addAction("Overlap narrow children");
  258. action->setToolTip("Children blocks will be overlaped by narrow\nparent blocks. See also \'Blocks narrow size\'.\nThis improves performance.");
  259. action->setCheckable(true);
  260. action->setChecked(EASY_GLOBALS.hide_narrow_children);
  261. connect(action, &QAction::triggered, [this](bool _checked){ EASY_GLOBALS.hide_narrow_children = _checked; refreshDiagram(); });
  262. action = submenu->addAction("Hide min-size blocks");
  263. action->setToolTip("Hides blocks which screen size\nis less than \'Min blocks size\'.");
  264. action->setCheckable(true);
  265. action->setChecked(EASY_GLOBALS.hide_minsize_blocks);
  266. connect(action, &QAction::triggered, [this](bool _checked){ EASY_GLOBALS.hide_minsize_blocks = _checked; refreshDiagram(); });
  267. action = submenu->addAction("Build hierarchy only for current thread");
  268. action->setToolTip("Hierarchy tree will be built\nfor blocks from current thread only.\nThis improves performance\nand saves a lot of memory.");
  269. action->setCheckable(true);
  270. action->setChecked(EASY_GLOBALS.only_current_thread_hierarchy);
  271. connect(action, &QAction::triggered, this, &This::onHierarchyFlagChange);
  272. action = submenu->addAction("Add zero blocks to hierarchy");
  273. action->setToolTip("Zero duration blocks will be added into hierarchy tree.\nThis reduces performance and increases memory consumption.");
  274. action->setCheckable(true);
  275. action->setChecked(EASY_GLOBALS.add_zero_blocks_to_hierarchy);
  276. connect(action, &QAction::triggered, [this](bool _checked)
  277. {
  278. EASY_GLOBALS.add_zero_blocks_to_hierarchy = _checked;
  279. emit EASY_GLOBALS.events.hierarchyFlagChanged(_checked);
  280. });
  281. action = submenu->addAction("Enable zero duration blocks on diagram");
  282. action->setToolTip("If checked then allows diagram to paint zero duration blocks\nwith 1px width on each scale. Otherwise, such blocks will be resized\nto 250ns duration.");
  283. action->setCheckable(true);
  284. action->setChecked(EASY_GLOBALS.enable_zero_length);
  285. connect(action, &QAction::triggered, [this](bool _checked){ EASY_GLOBALS.enable_zero_length = _checked; refreshDiagram(); });
  286. action = submenu->addAction("Highlight similar blocks");
  287. action->setToolTip("Highlight all visible blocks which are similar\nto the current selected block.\nThis reduces performance.");
  288. action->setCheckable(true);
  289. action->setChecked(EASY_GLOBALS.highlight_blocks_with_same_id);
  290. connect(action, &QAction::triggered, [this](bool _checked){ EASY_GLOBALS.highlight_blocks_with_same_id = _checked; refreshDiagram(); });
  291. action = submenu->addAction("Collapse blocks on tree reset");
  292. action->setToolTip("This collapses all blocks on diagram\nafter hierarchy tree reset.");
  293. action->setCheckable(true);
  294. action->setChecked(EASY_GLOBALS.collapse_items_on_tree_close);
  295. connect(action, &QAction::triggered, this, &This::onCollapseItemsAfterCloseChanged);
  296. action = submenu->addAction("Expand all on file open");
  297. action->setToolTip("If checked then all blocks on diagram\nwill be initially expanded.");
  298. action->setCheckable(true);
  299. action->setChecked(EASY_GLOBALS.all_items_expanded_by_default);
  300. connect(action, &QAction::triggered, this, &This::onAllItemsExpandedByDefaultChange);
  301. action = submenu->addAction("Bind diagram and tree expand");
  302. action->setToolTip("Expanding/collapsing blocks at diagram expands/collapses\nblocks at hierarchy tree and wise versa.");
  303. action->setCheckable(true);
  304. action->setChecked(EASY_GLOBALS.bind_scene_and_tree_expand_status);
  305. connect(action, &QAction::triggered, this, &This::onBindExpandStatusChange);
  306. action = submenu->addAction("Selecting block changes current thread");
  307. action->setToolTip("Automatically select thread while selecting a block.\nIf not checked then you will have to select current thread\nmanually double clicking on thread name on a diagram.");
  308. action->setCheckable(true);
  309. action->setChecked(EASY_GLOBALS.selecting_block_changes_thread);
  310. connect(action, &QAction::triggered, [this](bool _checked){ EASY_GLOBALS.selecting_block_changes_thread = _checked; });
  311. action = submenu->addAction("Draw event markers");
  312. action->setToolTip("Display event markers under the blocks\n(even if event-blocks are not visible).\nThis slightly reduces performance.");
  313. action->setCheckable(true);
  314. action->setChecked(EASY_GLOBALS.enable_event_markers);
  315. connect(action, &QAction::triggered, [this](bool _checked)
  316. {
  317. EASY_GLOBALS.enable_event_markers = _checked;
  318. refreshDiagram();
  319. });
  320. action = submenu->addAction("Automatically adjust histogram height");
  321. action->setToolTip("You do not need to adjust boundaries manually,\nbut this restricts you from adjusting boundaries at all (zoom mode).\nYou can still adjust boundaries in overview mode though.");
  322. action->setCheckable(true);
  323. action->setChecked(EASY_GLOBALS.auto_adjust_histogram_height);
  324. connect(action, &QAction::triggered, [](bool _checked)
  325. {
  326. EASY_GLOBALS.auto_adjust_histogram_height = _checked;
  327. emit EASY_GLOBALS.events.autoAdjustHistogramChanged();
  328. });
  329. action = submenu->addAction("Use decorated thread names");
  330. action->setToolTip("Add \'Thread\' word into thread name if there is no one already.\nExamples: \'Render\' will change to \'Render Thread\'\n\'WorkerThread\' will not change.");
  331. action->setCheckable(true);
  332. action->setChecked(EASY_GLOBALS.use_decorated_thread_name);
  333. connect(action, &QAction::triggered, [this](bool _checked)
  334. {
  335. EASY_GLOBALS.use_decorated_thread_name = _checked;
  336. emit EASY_GLOBALS.events.threadNameDecorationChanged();
  337. });
  338. action = submenu->addAction("Display hex thread id");
  339. action->setToolTip("Display hex thread id instead of decimal.");
  340. action->setCheckable(true);
  341. action->setChecked(EASY_GLOBALS.hex_thread_id);
  342. connect(action, &QAction::triggered, [this](bool _checked)
  343. {
  344. EASY_GLOBALS.hex_thread_id = _checked;
  345. emit EASY_GLOBALS.events.hexThreadIdChanged();
  346. });
  347. submenu->addSeparator();
  348. auto actionGroup = new QActionGroup(this);
  349. actionGroup->setExclusive(true);
  350. action = new QAction("Chrono text at top", actionGroup);
  351. action->setToolTip("Draw duration of selected interval\nat the top of the screen.");
  352. action->setCheckable(true);
  353. action->setData(static_cast<int>(::profiler_gui::ChronoTextPosition_Top));
  354. if (EASY_GLOBALS.chrono_text_position == ::profiler_gui::ChronoTextPosition_Top)
  355. action->setChecked(true);
  356. submenu->addAction(action);
  357. connect(action, &QAction::triggered, this, &This::onChronoTextPosChanged);
  358. action = new QAction("Chrono text at center", actionGroup);
  359. action->setToolTip("Draw duration of selected interval\nat the center of the screen.");
  360. action->setCheckable(true);
  361. action->setData(static_cast<int>(::profiler_gui::ChronoTextPosition_Center));
  362. if (EASY_GLOBALS.chrono_text_position == ::profiler_gui::ChronoTextPosition_Center)
  363. action->setChecked(true);
  364. submenu->addAction(action);
  365. connect(action, &QAction::triggered, this, &This::onChronoTextPosChanged);
  366. action = new QAction("Chrono text at bottom", actionGroup);
  367. action->setToolTip("Draw duration of selected interval\nat the bottom of the screen.");
  368. action->setCheckable(true);
  369. action->setData(static_cast<int>(::profiler_gui::ChronoTextPosition_Bottom));
  370. if (EASY_GLOBALS.chrono_text_position == ::profiler_gui::ChronoTextPosition_Bottom)
  371. action->setChecked(true);
  372. submenu->addAction(action);
  373. connect(action, &QAction::triggered, this, &This::onChronoTextPosChanged);
  374. submenu->addSeparator();
  375. auto w = new QWidget(submenu);
  376. auto l = new QHBoxLayout(w);
  377. l->setContentsMargins(33, 1, 1, 1);
  378. l->addWidget(new QLabel("Min blocks spacing, px", w), 0, Qt::AlignLeft);
  379. auto spinbox = new QSpinBox(w);
  380. spinbox->setRange(0, 400);
  381. spinbox->setValue(EASY_GLOBALS.blocks_spacing);
  382. spinbox->setFixedWidth(50);
  383. connect(spinbox, SIGNAL(valueChanged(int)), this, SLOT(onSpacingChange(int)));
  384. l->addWidget(spinbox);
  385. w->setLayout(l);
  386. auto waction = new QWidgetAction(submenu);
  387. waction->setDefaultWidget(w);
  388. submenu->addAction(waction);
  389. w = new QWidget(submenu);
  390. l = new QHBoxLayout(w);
  391. l->setContentsMargins(33, 1, 1, 1);
  392. l->addWidget(new QLabel("Min blocks size, px", w), 0, Qt::AlignLeft);
  393. spinbox = new QSpinBox(w);
  394. spinbox->setRange(1, 400);
  395. spinbox->setValue(EASY_GLOBALS.blocks_size_min);
  396. spinbox->setFixedWidth(50);
  397. connect(spinbox, SIGNAL(valueChanged(int)), this, SLOT(onMinSizeChange(int)));
  398. l->addWidget(spinbox);
  399. w->setLayout(l);
  400. waction = new QWidgetAction(submenu);
  401. waction->setDefaultWidget(w);
  402. submenu->addAction(waction);
  403. w = new QWidget(submenu);
  404. l = new QHBoxLayout(w);
  405. l->setContentsMargins(33, 1, 1, 1);
  406. l->addWidget(new QLabel("Blocks narrow size, px", w), 0, Qt::AlignLeft);
  407. spinbox = new QSpinBox(w);
  408. spinbox->setRange(1, 400);
  409. spinbox->setValue(EASY_GLOBALS.blocks_narrow_size);
  410. spinbox->setFixedWidth(50);
  411. connect(spinbox, SIGNAL(valueChanged(int)), this, SLOT(onNarrowSizeChange(int)));
  412. l->addWidget(spinbox);
  413. w->setLayout(l);
  414. waction = new QWidgetAction(submenu);
  415. waction->setDefaultWidget(w);
  416. submenu->addAction(waction);
  417. submenu = menu->addMenu("FPS Monitor");
  418. w = new QWidget(submenu);
  419. l = new QHBoxLayout(w);
  420. l->setContentsMargins(33, 1, 1, 1);
  421. l->addWidget(new QLabel("Request interval, ms", w), 0, Qt::AlignLeft);
  422. spinbox = new QSpinBox(w);
  423. spinbox->setRange(1, 600000);
  424. spinbox->setValue(EASY_GLOBALS.fps_timer_interval);
  425. spinbox->setFixedWidth(50);
  426. connect(spinbox, SIGNAL(valueChanged(int)), this, SLOT(onFpsIntervalChange(int)));
  427. l->addWidget(spinbox);
  428. w->setLayout(l);
  429. waction = new QWidgetAction(submenu);
  430. waction->setDefaultWidget(w);
  431. submenu->addAction(waction);
  432. w = new QWidget(submenu);
  433. l = new QHBoxLayout(w);
  434. l->setContentsMargins(33, 1, 1, 1);
  435. l->addWidget(new QLabel("Max history size", w), 0, Qt::AlignLeft);
  436. spinbox = new QSpinBox(w);
  437. spinbox->setRange(2, 200);
  438. spinbox->setValue(EASY_GLOBALS.max_fps_history);
  439. spinbox->setFixedWidth(50);
  440. connect(spinbox, SIGNAL(valueChanged(int)), this, SLOT(onFpsHistoryChange(int)));
  441. l->addWidget(spinbox);
  442. w->setLayout(l);
  443. waction = new QWidgetAction(submenu);
  444. waction->setDefaultWidget(w);
  445. submenu->addAction(waction);
  446. w = new QWidget(submenu);
  447. l = new QHBoxLayout(w);
  448. l->setContentsMargins(33, 1, 1, 1);
  449. l->addWidget(new QLabel("Line width, px", w), 0, Qt::AlignLeft);
  450. spinbox = new QSpinBox(w);
  451. spinbox->setRange(1, 6);
  452. spinbox->setValue(EASY_GLOBALS.fps_widget_line_width);
  453. spinbox->setFixedWidth(50);
  454. connect(spinbox, SIGNAL(valueChanged(int)), this, SLOT(onFpsMonitorLineWidthChange(int)));
  455. l->addWidget(spinbox);
  456. w->setLayout(l);
  457. waction = new QWidgetAction(submenu);
  458. waction->setDefaultWidget(w);
  459. submenu->addAction(waction);
  460. submenu = menu->addMenu("Units");
  461. actionGroup = new QActionGroup(this);
  462. actionGroup->setExclusive(true);
  463. action = new QAction("Auto", actionGroup);
  464. action->setCheckable(true);
  465. action->setData(static_cast<int>(::profiler_gui::TimeUnits_auto));
  466. if (EASY_GLOBALS.time_units == ::profiler_gui::TimeUnits_auto)
  467. action->setChecked(true);
  468. submenu->addAction(action);
  469. connect(action, &QAction::triggered, this, &This::onUnitsChanged);
  470. action = new QAction("Milliseconds", actionGroup);
  471. action->setCheckable(true);
  472. action->setData(static_cast<int>(::profiler_gui::TimeUnits_ms));
  473. if (EASY_GLOBALS.time_units == ::profiler_gui::TimeUnits_ms)
  474. action->setChecked(true);
  475. submenu->addAction(action);
  476. connect(action, &QAction::triggered, this, &This::onUnitsChanged);
  477. action = new QAction("Microseconds", actionGroup);
  478. action->setCheckable(true);
  479. action->setData(static_cast<int>(::profiler_gui::TimeUnits_us));
  480. if (EASY_GLOBALS.time_units == ::profiler_gui::TimeUnits_us)
  481. action->setChecked(true);
  482. submenu->addAction(action);
  483. connect(action, &QAction::triggered, this, &This::onUnitsChanged);
  484. action = new QAction("Nanoseconds", actionGroup);
  485. action->setCheckable(true);
  486. action->setData(static_cast<int>(::profiler_gui::TimeUnits_ns));
  487. if (EASY_GLOBALS.time_units == ::profiler_gui::TimeUnits_ns)
  488. action->setChecked(true);
  489. submenu->addAction(action);
  490. connect(action, &QAction::triggered, this, &This::onUnitsChanged);
  491. submenu = menu->addMenu("Remote");
  492. m_eventTracingEnableAction = submenu->addAction("Event tracing enabled");
  493. m_eventTracingEnableAction->setCheckable(true);
  494. m_eventTracingEnableAction->setEnabled(false);
  495. connect(m_eventTracingEnableAction, &QAction::triggered, this, &This::onEventTracingEnableChange);
  496. m_eventTracingPriorityAction = submenu->addAction("Low priority event tracing");
  497. m_eventTracingPriorityAction->setCheckable(true);
  498. m_eventTracingPriorityAction->setChecked(EASY_OPTION_LOW_PRIORITY_EVENT_TRACING);
  499. m_eventTracingPriorityAction->setEnabled(false);
  500. connect(m_eventTracingPriorityAction, &QAction::triggered, this, &This::onEventTracingPriorityChange);
  501. submenu = menu->addMenu("Encoding");
  502. actionGroup = new QActionGroup(this);
  503. actionGroup->setExclusive(true);
  504. auto default_codec_mib = QTextCodec::codecForLocale()->mibEnum();
  505. foreach(int mib, QTextCodec::availableMibs())
  506. {
  507. auto codec = QTextCodec::codecForMib(mib)->name();
  508. action = new QAction(codec, actionGroup);
  509. action->setCheckable(true);
  510. if (mib == default_codec_mib)
  511. action->setChecked(true);
  512. submenu->addAction(action);
  513. connect(action, &QAction::triggered, this, &This::onEncodingChanged);
  514. }
  515. auto tb_height = toolbar->height() + 4;
  516. toolbar = addToolBar("FrameToolbar");
  517. toolbar->setIconSize(::profiler_gui::ICONS_SIZE);
  518. toolbar->setObjectName("ProfilerGUI_FrameToolbar");
  519. toolbar->setContentsMargins(1, 0, 1, 0);
  520. toolbar->setMinimumHeight(tb_height);
  521. lbl = new QLabel("Expected frame time:", toolbar);
  522. lbl->setContentsMargins(5, 2, 2, 2);
  523. toolbar->addWidget(lbl);
  524. m_frameTimeEdit = new QLineEdit();
  525. m_frameTimeEdit->setFixedWidth(70);
  526. auto val = new QDoubleValidator(m_frameTimeEdit);
  527. val->setLocale(QLocale::c());
  528. val->setBottom(0);
  529. m_frameTimeEdit->setValidator(val);
  530. m_frameTimeEdit->setText(QString::number(EASY_GLOBALS.frame_time * 1e-3));
  531. connect(m_frameTimeEdit, &QLineEdit::editingFinished, this, &This::onFrameTimeEditFinish);
  532. connect(&EASY_GLOBALS.events, &::profiler_gui::EasyGlobalSignals::expectedFrameTimeChanged, this, &This::onFrameTimeChanged);
  533. toolbar->addWidget(m_frameTimeEdit);
  534. lbl = new QLabel("ms", toolbar);
  535. lbl->setContentsMargins(5, 2, 1, 1);
  536. toolbar->addWidget(lbl);
  537. connect(graphicsView->view(), &EasyGraphicsView::intervalChanged, treeWidget->tree(), &EasyTreeWidget::setTreeBlocks);
  538. connect(&m_readerTimer, &QTimer::timeout, this, &This::onFileReaderTimeout);
  539. connect(&m_listenerTimer, &QTimer::timeout, this, &This::onListenerTimerTimeout);
  540. connect(&m_fpsRequestTimer, &QTimer::timeout, this, &This::onFrameTimeRequestTimeout);
  541. m_progress = new QProgressDialog("Loading file...", "Cancel", 0, 100, this);
  542. m_progress->setFixedWidth(300);
  543. m_progress->setWindowTitle(EASY_DEFAULT_WINDOW_TITLE);
  544. m_progress->setModal(true);
  545. m_progress->setValue(100);
  546. //m_progress->hide();
  547. connect(m_progress, &QProgressDialog::canceled, this, &This::onFileReaderCancel);
  548. loadGeometry();
  549. if(QCoreApplication::arguments().size() > 1)
  550. {
  551. auto opened_filename = QCoreApplication::arguments().at(1);
  552. loadFile(opened_filename);
  553. }
  554. connect(&EASY_GLOBALS.events, &::profiler_gui::EasyGlobalSignals::blockStatusChanged, this, &This::onBlockStatusChange);
  555. connect(&EASY_GLOBALS.events, &::profiler_gui::EasyGlobalSignals::blocksRefreshRequired, this, &This::onGetBlockDescriptionsClicked);
  556. }
  557. EasyMainWindow::~EasyMainWindow()
  558. {
  559. delete m_progress;
  560. }
  561. //////////////////////////////////////////////////////////////////////////
  562. void EasyMainWindow::dragEnterEvent(QDragEnterEvent* drag_event)
  563. {
  564. if (drag_event->mimeData()->hasUrls())
  565. drag_event->acceptProposedAction();
  566. }
  567. void EasyMainWindow::dragMoveEvent(QDragMoveEvent* drag_event)
  568. {
  569. if (drag_event->mimeData()->hasUrls())
  570. drag_event->acceptProposedAction();
  571. }
  572. void EasyMainWindow::dragLeaveEvent(QDragLeaveEvent* drag_event)
  573. {
  574. drag_event->accept();
  575. }
  576. void EasyMainWindow::dropEvent(QDropEvent* drop_event)
  577. {
  578. const auto& urls = drop_event->mimeData()->urls();
  579. if (!urls.empty())
  580. {
  581. if (m_bNetworkFileRegime)
  582. {
  583. // Warn user about unsaved network information and suggest to save
  584. auto result = QMessageBox::question(this, "Unsaved session", "You have unsaved data!\nSave before opening new file?", QMessageBox::Yes, QMessageBox::No, QMessageBox::Cancel);
  585. if (result == QMessageBox::Yes)
  586. {
  587. onSaveFileClicked(true);
  588. }
  589. else if (result != QMessageBox::No)
  590. {
  591. // User cancelled opening new file
  592. return;
  593. }
  594. }
  595. loadFile(urls.front().toLocalFile());
  596. }
  597. }
  598. //////////////////////////////////////////////////////////////////////////
  599. void EasyMainWindow::onOpenFileClicked(bool)
  600. {
  601. auto action = qobject_cast<QAction*>(sender());
  602. if (action == nullptr)
  603. return;
  604. QString filename;
  605. if (action == m_loadActionMenu->menuAction())
  606. filename = QFileDialog::getOpenFileName(this, "Open EasyProfiler File", m_lastFiles.empty() ? QString() : m_lastFiles.front(), "EasyProfiler File (*.prof);;All Files (*.*)");
  607. else
  608. filename = action->text();
  609. if (!filename.isEmpty())
  610. {
  611. if (m_bNetworkFileRegime)
  612. {
  613. // Warn user about unsaved network information and suggest to save
  614. auto result = QMessageBox::question(this, "Unsaved session", "You have unsaved data!\nSave before opening new file?", QMessageBox::Yes, QMessageBox::No, QMessageBox::Cancel);
  615. if (result == QMessageBox::Yes)
  616. {
  617. onSaveFileClicked(true);
  618. }
  619. else if (result != QMessageBox::No)
  620. {
  621. // User cancelled opening new file
  622. return;
  623. }
  624. }
  625. loadFile(filename);
  626. }
  627. }
  628. //////////////////////////////////////////////////////////////////////////
  629. void EasyMainWindow::addFileToList(const QString& filename)
  630. {
  631. m_lastFiles.push_front(filename);
  632. auto action = new QAction(filename, this);
  633. connect(action, &QAction::triggered, this, &This::onOpenFileClicked);
  634. auto fileActions = m_loadActionMenu->actions();
  635. if (fileActions.empty())
  636. m_loadActionMenu->addAction(action);
  637. else
  638. m_loadActionMenu->insertAction(fileActions.front(), action);
  639. if (m_lastFiles.size() > 10)
  640. {
  641. // Keep 10 files at the list
  642. m_lastFiles.pop_back();
  643. m_loadActionMenu->removeAction(fileActions.back());
  644. delete fileActions.back();
  645. }
  646. m_bOpenedCacheFile = filename.contains(NETWORK_CACHE_FILE);
  647. if (m_bOpenedCacheFile)
  648. setWindowTitle(QString(EASY_DEFAULT_WINDOW_TITLE " - [%1] - UNSAVED network cache file").arg(m_lastFiles.front()));
  649. else
  650. setWindowTitle(QString(EASY_DEFAULT_WINDOW_TITLE " - [%1]").arg(m_lastFiles.front()));
  651. }
  652. void EasyMainWindow::loadFile(const QString& filename)
  653. {
  654. const auto i = filename.lastIndexOf(QChar('/'));
  655. const auto j = filename.lastIndexOf(QChar('\\'));
  656. m_progress->setLabelText(QString("Loading %1...").arg(filename.mid(::std::max(i, j) + 1)));
  657. m_progress->setValue(0);
  658. m_progress->show();
  659. m_readerTimer.start(LOADER_TIMER_INTERVAL);
  660. m_reader.load(filename);
  661. }
  662. void EasyMainWindow::readStream(::std::stringstream& data)
  663. {
  664. m_progress->setLabelText(tr("Reading from stream..."));
  665. m_progress->setValue(0);
  666. m_progress->show();
  667. m_readerTimer.start(LOADER_TIMER_INTERVAL);
  668. m_reader.load(data);
  669. }
  670. //////////////////////////////////////////////////////////////////////////
  671. void EasyMainWindow::onSaveFileClicked(bool)
  672. {
  673. if (m_serializedBlocks.empty())
  674. return;
  675. QString lastFile = m_lastFiles.empty() ? QString() : m_lastFiles.front();
  676. const auto i = lastFile.lastIndexOf(QChar('/'));
  677. const auto j = lastFile.lastIndexOf(QChar('\\'));
  678. auto k = ::std::max(i, j);
  679. QString dir;
  680. if (k > 0)
  681. dir = lastFile.mid(0, ++k);
  682. if (m_bNetworkFileRegime)
  683. {
  684. // Current file is network cache file, use current system time as output file name
  685. if (!dir.isEmpty())
  686. dir += QDateTime::currentDateTime().toString("/yyyy-MM-dd_HH-mm-ss.prof");
  687. else
  688. dir = QDateTime::currentDateTime().toString("yyyy-MM-dd_HH-mm-ss.prof");
  689. }
  690. else if (m_bOpenedCacheFile)
  691. {
  692. // Opened old network cache file, use it's last modification time as output file name
  693. QFileInfo fileInfo(lastFile);
  694. if (!fileInfo.exists())
  695. {
  696. // Can not open the file!
  697. QMessageBox::warning(this, "Warning", "Can not open source file.\nSaving incomplete.", QMessageBox::Close);
  698. m_lastFiles.pop_front();
  699. auto action = m_loadActionMenu->actions().front();
  700. m_loadActionMenu->removeAction(action);
  701. delete action;
  702. return;
  703. }
  704. if (!dir.isEmpty())
  705. dir += fileInfo.lastModified().toString("/yyyy-MM-dd_HH-mm-ss.prof");
  706. else
  707. dir = fileInfo.lastModified().toString("yyyy-MM-dd_HH-mm-ss.prof");
  708. }
  709. else
  710. {
  711. dir = lastFile;
  712. }
  713. auto filename = QFileDialog::getSaveFileName(this, "Save EasyProfiler File", dir, "EasyProfiler File (*.prof);;All Files (*.*)");
  714. if (!filename.isEmpty())
  715. {
  716. // Check if the same file has been selected
  717. {
  718. QFileInfo fileInfo1(m_bNetworkFileRegime ? QString(NETWORK_CACHE_FILE) : lastFile), fileInfo2(filename);
  719. if (fileInfo1.exists() && fileInfo2.exists() && fileInfo1 == fileInfo2)
  720. {
  721. // Selected the same file - do nothing
  722. return;
  723. }
  724. }
  725. bool inOk = false, outOk = false;
  726. int8_t retry1 = -1;
  727. while (++retry1 < 4)
  728. {
  729. ::std::ifstream inFile(m_bNetworkFileRegime ? NETWORK_CACHE_FILE : lastFile.toStdString().c_str(), ::std::fstream::binary);
  730. if (!inFile.is_open())
  731. {
  732. ::std::this_thread::sleep_for(::std::chrono::milliseconds(500));
  733. continue;
  734. }
  735. inOk = true;
  736. int8_t retry2 = -1;
  737. while (++retry2 < 4)
  738. {
  739. ::std::ofstream outFile(filename.toStdString(), ::std::fstream::binary);
  740. if (!outFile.is_open())
  741. {
  742. ::std::this_thread::sleep_for(::std::chrono::milliseconds(500));
  743. continue;
  744. }
  745. outFile << inFile.rdbuf();
  746. outOk = true;
  747. break;
  748. }
  749. break;
  750. }
  751. if (outOk)
  752. {
  753. if (m_bNetworkFileRegime)
  754. {
  755. // Remove temporary network cahche file
  756. QFile::remove(QString(NETWORK_CACHE_FILE));
  757. }
  758. else if (m_bOpenedCacheFile)
  759. {
  760. // Remove old temporary network cahche file
  761. QFile::remove(lastFile.toStdString().c_str());
  762. m_lastFiles.pop_front();
  763. auto action = m_loadActionMenu->actions().front();
  764. m_loadActionMenu->removeAction(action);
  765. delete action;
  766. }
  767. addFileToList(filename);
  768. m_bNetworkFileRegime = false;
  769. }
  770. else if (inOk)
  771. {
  772. QMessageBox::warning(this, "Warning", "Can not open destination file.\nSaving incomplete.", QMessageBox::Close);
  773. }
  774. else
  775. {
  776. if (m_bNetworkFileRegime)
  777. QMessageBox::warning(this, "Warning", "Can not open network cache file.\nSaving incomplete.", QMessageBox::Close);
  778. else
  779. QMessageBox::warning(this, "Warning", "Can not open source file.\nSaving incomplete.", QMessageBox::Close);
  780. }
  781. }
  782. }
  783. //////////////////////////////////////////////////////////////////////////
  784. void EasyMainWindow::clear()
  785. {
  786. static_cast<EasyHierarchyWidget*>(m_treeWidget->widget())->clear(true);
  787. static_cast<EasyGraphicsViewWidget*>(m_graphicsView->widget())->clear();
  788. #if EASY_GUI_USE_DESCRIPTORS_DOCK_WINDOW != 0
  789. static_cast<EasyDescWidget*>(m_descTreeWidget->widget())->clear();
  790. #endif
  791. if (m_dialogDescTree != nullptr)
  792. m_dialogDescTree->clear();
  793. EASY_GLOBALS.selected_thread = 0;
  794. ::profiler_gui::set_max(EASY_GLOBALS.selected_block);
  795. ::profiler_gui::set_max(EASY_GLOBALS.selected_block_id);
  796. EASY_GLOBALS.profiler_blocks.clear();
  797. EASY_GLOBALS.descriptors.clear();
  798. EASY_GLOBALS.gui_blocks.clear();
  799. m_serializedBlocks.clear();
  800. m_serializedDescriptors.clear();
  801. m_saveAction->setEnabled(false);
  802. m_deleteAction->setEnabled(false);
  803. if (m_bNetworkFileRegime)
  804. QFile::remove(QString(NETWORK_CACHE_FILE));
  805. m_bNetworkFileRegime = false;
  806. m_bOpenedCacheFile = false;
  807. setWindowTitle(EASY_DEFAULT_WINDOW_TITLE);
  808. }
  809. //////////////////////////////////////////////////////////////////////////
  810. void EasyMainWindow::refreshDiagram()
  811. {
  812. static_cast<EasyGraphicsViewWidget*>(m_graphicsView->widget())->view()->scene()->update();
  813. }
  814. //////////////////////////////////////////////////////////////////////////
  815. void EasyMainWindow::onDeleteClicked(bool)
  816. {
  817. int button = QMessageBox::Yes;
  818. if (m_bNetworkFileRegime)
  819. button = QMessageBox::question(this, "Clear all profiled data", "All profiled data and network cache file\nare going to be deleted!\nContinue?", QMessageBox::Yes, QMessageBox::No);
  820. if (button == QMessageBox::Yes)
  821. clear();
  822. }
  823. //////////////////////////////////////////////////////////////////////////
  824. void EasyMainWindow::onExitClicked(bool)
  825. {
  826. close();
  827. }
  828. //////////////////////////////////////////////////////////////////////////
  829. void EasyMainWindow::onEncodingChanged(bool)
  830. {
  831. auto _sender = qobject_cast<QAction*>(sender());
  832. auto name = _sender->text();
  833. QTextCodec *codec = QTextCodec::codecForName(name.toStdString().c_str());
  834. QTextCodec::setCodecForLocale(codec);
  835. }
  836. void EasyMainWindow::onChronoTextPosChanged(bool)
  837. {
  838. auto _sender = qobject_cast<QAction*>(sender());
  839. EASY_GLOBALS.chrono_text_position = static_cast<::profiler_gui::ChronometerTextPosition>(_sender->data().toInt());
  840. refreshDiagram();
  841. }
  842. void EasyMainWindow::onUnitsChanged(bool)
  843. {
  844. auto _sender = qobject_cast<QAction*>(sender());
  845. EASY_GLOBALS.time_units = static_cast<::profiler_gui::TimeUnits>(_sender->data().toInt());
  846. }
  847. void EasyMainWindow::onEnableDisableStatistics(bool _checked)
  848. {
  849. EASY_GLOBALS.enable_statistics = _checked;
  850. auto action = qobject_cast<QAction*>(sender());
  851. if (action != nullptr)
  852. {
  853. auto f = action->font();
  854. f.setBold(_checked);
  855. action->setFont(f);
  856. if (_checked)
  857. {
  858. action->setText("Statistics enabled");
  859. SET_ICON(action, ":/Stats");
  860. }
  861. else
  862. {
  863. action->setText("Statistics disabled");
  864. SET_ICON(action, ":/Stats-off");
  865. }
  866. }
  867. }
  868. void EasyMainWindow::onCollapseItemsAfterCloseChanged(bool _checked)
  869. {
  870. EASY_GLOBALS.collapse_items_on_tree_close = _checked;
  871. }
  872. void EasyMainWindow::onAllItemsExpandedByDefaultChange(bool _checked)
  873. {
  874. EASY_GLOBALS.all_items_expanded_by_default = _checked;
  875. }
  876. void EasyMainWindow::onBindExpandStatusChange(bool _checked)
  877. {
  878. EASY_GLOBALS.bind_scene_and_tree_expand_status = _checked;
  879. }
  880. void EasyMainWindow::onHierarchyFlagChange(bool _checked)
  881. {
  882. EASY_GLOBALS.only_current_thread_hierarchy = _checked;
  883. emit EASY_GLOBALS.events.hierarchyFlagChanged(_checked);
  884. }
  885. //////////////////////////////////////////////////////////////////////////
  886. void EasyMainWindow::onExpandAllClicked(bool)
  887. {
  888. for (auto& block : EASY_GLOBALS.gui_blocks)
  889. block.expanded = true;
  890. emit EASY_GLOBALS.events.itemsExpandStateChanged();
  891. auto tree = static_cast<EasyHierarchyWidget*>(m_treeWidget->widget())->tree();
  892. const QSignalBlocker b(tree);
  893. tree->expandAll();
  894. }
  895. void EasyMainWindow::onCollapseAllClicked(bool)
  896. {
  897. for (auto& block : EASY_GLOBALS.gui_blocks)
  898. block.expanded = false;
  899. emit EASY_GLOBALS.events.itemsExpandStateChanged();
  900. auto tree = static_cast<EasyHierarchyWidget*>(m_treeWidget->widget())->tree();
  901. const QSignalBlocker b(tree);
  902. tree->collapseAll();
  903. }
  904. //////////////////////////////////////////////////////////////////////////
  905. void EasyMainWindow::onSpacingChange(int _value)
  906. {
  907. EASY_GLOBALS.blocks_spacing = _value;
  908. refreshDiagram();
  909. }
  910. void EasyMainWindow::onMinSizeChange(int _value)
  911. {
  912. EASY_GLOBALS.blocks_size_min = _value;
  913. refreshDiagram();
  914. }
  915. void EasyMainWindow::onNarrowSizeChange(int _value)
  916. {
  917. EASY_GLOBALS.blocks_narrow_size = _value;
  918. refreshDiagram();
  919. }
  920. //////////////////////////////////////////////////////////////////////////
  921. void EasyMainWindow::onFpsIntervalChange(int _value)
  922. {
  923. EASY_GLOBALS.fps_timer_interval = _value;
  924. if (m_fpsRequestTimer.isActive())
  925. m_fpsRequestTimer.stop();
  926. if (EASY_GLOBALS.connected)
  927. m_fpsRequestTimer.start(_value);
  928. }
  929. void EasyMainWindow::onFpsHistoryChange(int _value)
  930. {
  931. EASY_GLOBALS.max_fps_history = _value;
  932. }
  933. void EasyMainWindow::onFpsMonitorLineWidthChange(int _value)
  934. {
  935. EASY_GLOBALS.fps_widget_line_width = _value;
  936. }
  937. //////////////////////////////////////////////////////////////////////////
  938. void EasyMainWindow::onEditBlocksClicked(bool)
  939. {
  940. if (m_descTreeDialog != nullptr)
  941. {
  942. m_descTreeDialog->raise();
  943. return;
  944. }
  945. m_descTreeDialog = new QDialog();
  946. m_descTreeDialog->setAttribute(Qt::WA_DeleteOnClose, true);
  947. m_descTreeDialog->setWindowTitle(EASY_DEFAULT_WINDOW_TITLE);
  948. m_descTreeDialog->resize(800, 600);
  949. connect(m_descTreeDialog, &QDialog::finished, this, &This::onDescTreeDialogClose);
  950. auto l = new QVBoxLayout(m_descTreeDialog);
  951. m_dialogDescTree = new EasyDescWidget(m_descTreeDialog);
  952. l->addWidget(m_dialogDescTree);
  953. m_descTreeDialog->setLayout(l);
  954. m_dialogDescTree->build();
  955. m_descTreeDialog->show();
  956. }
  957. void EasyMainWindow::onDescTreeDialogClose(int)
  958. {
  959. disconnect(m_descTreeDialog, &QDialog::finished, this, &This::onDescTreeDialogClose);
  960. m_dialogDescTree = nullptr;
  961. m_descTreeDialog = nullptr;
  962. }
  963. //////////////////////////////////////////////////////////////////////////
  964. void EasyMainWindow::closeEvent(QCloseEvent* close_event)
  965. {
  966. if (m_bNetworkFileRegime)
  967. {
  968. // Warn user about unsaved network information and suggest to save
  969. if (QMessageBox::Yes == QMessageBox::question(this, "Unsaved session", "You unsaved data!\nSave before exit?", QMessageBox::Yes, QMessageBox::No))
  970. {
  971. onSaveFileClicked(true);
  972. }
  973. }
  974. saveSettingsAndGeometry();
  975. if (m_descTreeDialog != nullptr)
  976. {
  977. m_descTreeDialog->reject();
  978. m_descTreeDialog = nullptr;
  979. m_dialogDescTree = nullptr;
  980. }
  981. Parent::closeEvent(close_event);
  982. }
  983. //////////////////////////////////////////////////////////////////////////
  984. void EasyMainWindow::loadSettings()
  985. {
  986. QSettings settings(::profiler_gui::ORGANAZATION_NAME, ::profiler_gui::APPLICATION_NAME);
  987. settings.beginGroup("main");
  988. auto last_files = settings.value("last_files");
  989. if (!last_files.isNull())
  990. m_lastFiles = last_files.toStringList();
  991. auto last_addr = settings.value("ip_address");
  992. if (!last_addr.isNull())
  993. m_lastAddress = last_addr.toString();
  994. auto last_port = settings.value("port");
  995. if (!last_port.isNull())
  996. m_lastPort = (uint16_t)last_port.toUInt();
  997. auto val = settings.value("chrono_text_position");
  998. if (!val.isNull())
  999. EASY_GLOBALS.chrono_text_position = static_cast<::profiler_gui::ChronometerTextPosition>(val.toInt());
  1000. val = settings.value("time_units");
  1001. if (!val.isNull())
  1002. EASY_GLOBALS.time_units = static_cast<::profiler_gui::TimeUnits>(val.toInt());
  1003. val = settings.value("frame_time");
  1004. if (!val.isNull())
  1005. EASY_GLOBALS.frame_time = val.toFloat();
  1006. val = settings.value("blocks_spacing");
  1007. if (!val.isNull())
  1008. EASY_GLOBALS.blocks_spacing = val.toInt();
  1009. val = settings.value("blocks_size_min");
  1010. if (!val.isNull())
  1011. EASY_GLOBALS.blocks_size_min = val.toInt();
  1012. val = settings.value("blocks_narrow_size");
  1013. if (!val.isNull())
  1014. EASY_GLOBALS.blocks_narrow_size = val.toInt();
  1015. auto flag = settings.value("draw_graphics_items_borders");
  1016. if (!flag.isNull())
  1017. EASY_GLOBALS.draw_graphics_items_borders = flag.toBool();
  1018. flag = settings.value("hide_narrow_children");
  1019. if (!flag.isNull())
  1020. EASY_GLOBALS.hide_narrow_children = flag.toBool();
  1021. flag = settings.value("hide_minsize_blocks");
  1022. if (!flag.isNull())
  1023. EASY_GLOBALS.hide_minsize_blocks = flag.toBool();
  1024. flag = settings.value("collapse_items_on_tree_close");
  1025. if (!flag.isNull())
  1026. EASY_GLOBALS.collapse_items_on_tree_close = flag.toBool();
  1027. flag = settings.value("all_items_expanded_by_default");
  1028. if (!flag.isNull())
  1029. EASY_GLOBALS.all_items_expanded_by_default = flag.toBool();
  1030. flag = settings.value("only_current_thread_hierarchy");
  1031. if (!flag.isNull())
  1032. EASY_GLOBALS.only_current_thread_hierarchy = flag.toBool();
  1033. flag = settings.value("enable_zero_length");
  1034. if (!flag.isNull())
  1035. EASY_GLOBALS.enable_zero_length = flag.toBool();
  1036. flag = settings.value("add_zero_blocks_to_hierarchy");
  1037. if (!flag.isNull())
  1038. EASY_GLOBALS.add_zero_blocks_to_hierarchy = flag.toBool();
  1039. flag = settings.value("highlight_blocks_with_same_id");
  1040. if (!flag.isNull())
  1041. EASY_GLOBALS.highlight_blocks_with_same_id = flag.toBool();
  1042. flag = settings.value("bind_scene_and_tree_expand_status");
  1043. if (!flag.isNull())
  1044. EASY_GLOBALS.bind_scene_and_tree_expand_status = flag.toBool();
  1045. flag = settings.value("selecting_block_changes_thread");
  1046. if (!flag.isNull())
  1047. EASY_GLOBALS.selecting_block_changes_thread = flag.toBool();
  1048. flag = settings.value("enable_event_indicators");
  1049. if (!flag.isNull())
  1050. EASY_GLOBALS.enable_event_markers = flag.toBool();
  1051. flag = settings.value("auto_adjust_histogram_height");
  1052. if (!flag.isNull())
  1053. EASY_GLOBALS.auto_adjust_histogram_height = flag.toBool();
  1054. flag = settings.value("display_only_frames_on_histogram");
  1055. if (!flag.isNull())
  1056. EASY_GLOBALS.display_only_frames_on_histogram = flag.toBool();
  1057. flag = settings.value("use_decorated_thread_name");
  1058. if (!flag.isNull())
  1059. EASY_GLOBALS.use_decorated_thread_name = flag.toBool();
  1060. flag = settings.value("hex_thread_id");
  1061. if (!flag.isNull())
  1062. EASY_GLOBALS.hex_thread_id = flag.toBool();
  1063. flag = settings.value("fps_timer_interval");
  1064. if (!flag.isNull())
  1065. EASY_GLOBALS.fps_timer_interval = flag.toInt();
  1066. flag = settings.value("max_fps_history");
  1067. if (!flag.isNull())
  1068. EASY_GLOBALS.max_fps_history = flag.toInt();
  1069. flag = settings.value("fps_widget_line_width");
  1070. if (!flag.isNull())
  1071. EASY_GLOBALS.fps_widget_line_width = flag.toInt();
  1072. flag = settings.value("enable_statistics");
  1073. if (!flag.isNull())
  1074. EASY_GLOBALS.enable_statistics = flag.toBool();
  1075. QString encoding = settings.value("encoding", "UTF-8").toString();
  1076. auto default_codec_mib = QTextCodec::codecForName(encoding.toStdString().c_str())->mibEnum();
  1077. auto default_codec = QTextCodec::codecForMib(default_codec_mib);
  1078. QTextCodec::setCodecForLocale(default_codec);
  1079. settings.endGroup();
  1080. }
  1081. void EasyMainWindow::loadGeometry()
  1082. {
  1083. QSettings settings(::profiler_gui::ORGANAZATION_NAME, ::profiler_gui::APPLICATION_NAME);
  1084. settings.beginGroup("main");
  1085. auto geometry = settings.value("geometry").toByteArray();
  1086. if (!geometry.isEmpty())
  1087. restoreGeometry(geometry);
  1088. auto state = settings.value("windowState").toByteArray();
  1089. if (!state.isEmpty())
  1090. restoreState(state);
  1091. settings.endGroup();
  1092. }
  1093. void EasyMainWindow::saveSettingsAndGeometry()
  1094. {
  1095. QSettings settings(::profiler_gui::ORGANAZATION_NAME, ::profiler_gui::APPLICATION_NAME);
  1096. settings.beginGroup("main");
  1097. settings.setValue("geometry", this->saveGeometry());
  1098. settings.setValue("windowState", this->saveState());
  1099. settings.setValue("last_files", m_lastFiles);
  1100. settings.setValue("ip_address", m_lastAddress);
  1101. settings.setValue("port", (quint32)m_lastPort);
  1102. settings.setValue("chrono_text_position", static_cast<int>(EASY_GLOBALS.chrono_text_position));
  1103. settings.setValue("time_units", static_cast<int>(EASY_GLOBALS.time_units));
  1104. settings.setValue("frame_time", EASY_GLOBALS.frame_time);
  1105. settings.setValue("blocks_spacing", EASY_GLOBALS.blocks_spacing);
  1106. settings.setValue("blocks_size_min", EASY_GLOBALS.blocks_size_min);
  1107. settings.setValue("blocks_narrow_size", EASY_GLOBALS.blocks_narrow_size);
  1108. settings.setValue("draw_graphics_items_borders", EASY_GLOBALS.draw_graphics_items_borders);
  1109. settings.setValue("hide_narrow_children", EASY_GLOBALS.hide_narrow_children);
  1110. settings.setValue("hide_minsize_blocks", EASY_GLOBALS.hide_minsize_blocks);
  1111. settings.setValue("collapse_items_on_tree_close", EASY_GLOBALS.collapse_items_on_tree_close);
  1112. settings.setValue("all_items_expanded_by_default", EASY_GLOBALS.all_items_expanded_by_default);
  1113. settings.setValue("only_current_thread_hierarchy", EASY_GLOBALS.only_current_thread_hierarchy);
  1114. settings.setValue("enable_zero_length", EASY_GLOBALS.enable_zero_length);
  1115. settings.setValue("add_zero_blocks_to_hierarchy", EASY_GLOBALS.add_zero_blocks_to_hierarchy);
  1116. settings.setValue("highlight_blocks_with_same_id", EASY_GLOBALS.highlight_blocks_with_same_id);
  1117. settings.setValue("bind_scene_and_tree_expand_status", EASY_GLOBALS.bind_scene_and_tree_expand_status);
  1118. settings.setValue("selecting_block_changes_thread", EASY_GLOBALS.selecting_block_changes_thread);
  1119. settings.setValue("enable_event_indicators", EASY_GLOBALS.enable_event_markers);
  1120. settings.setValue("auto_adjust_histogram_height", EASY_GLOBALS.auto_adjust_histogram_height);
  1121. settings.setValue("display_only_frames_on_histogram", EASY_GLOBALS.display_only_frames_on_histogram);
  1122. settings.setValue("use_decorated_thread_name", EASY_GLOBALS.use_decorated_thread_name);
  1123. settings.setValue("hex_thread_id", EASY_GLOBALS.hex_thread_id);
  1124. settings.setValue("enable_statistics", EASY_GLOBALS.enable_statistics);
  1125. settings.setValue("fps_timer_interval", EASY_GLOBALS.fps_timer_interval);
  1126. settings.setValue("max_fps_history", EASY_GLOBALS.max_fps_history);
  1127. settings.setValue("fps_widget_line_width", EASY_GLOBALS.fps_widget_line_width);
  1128. settings.setValue("encoding", QTextCodec::codecForLocale()->name());
  1129. settings.endGroup();
  1130. }
  1131. void EasyMainWindow::setDisconnected(bool _showMessage)
  1132. {
  1133. if (m_fpsRequestTimer.isActive())
  1134. m_fpsRequestTimer.stop();
  1135. if (_showMessage)
  1136. QMessageBox::warning(this, "Warning", "Connection has lost", QMessageBox::Close);
  1137. EASY_GLOBALS.connected = false;
  1138. m_captureAction->setEnabled(false);
  1139. SET_ICON(m_connectAction, ":/Connection");
  1140. m_connectAction->setText(tr("Connect"));
  1141. m_eventTracingEnableAction->setEnabled(false);
  1142. m_eventTracingPriorityAction->setEnabled(false);
  1143. m_addressEdit->setEnabled(true);
  1144. m_portEdit->setEnabled(true);
  1145. emit EASY_GLOBALS.events.connectionChanged(false);
  1146. }
  1147. //////////////////////////////////////////////////////////////////////////
  1148. void EasyMainWindow::onFrameTimeRequestTimeout()
  1149. {
  1150. if (EASY_GLOBALS.fps_enabled && EASY_GLOBALS.connected && (m_listener.regime() == LISTENER_IDLE || m_listener.regime() == LISTENER_CAPTURE))
  1151. {
  1152. if (m_listener.requestFrameTime())
  1153. {
  1154. QTimer::singleShot(100, this, &This::checkFrameTimeReady);
  1155. }
  1156. else if (!m_listener.connected())
  1157. {
  1158. setDisconnected();
  1159. }
  1160. }
  1161. }
  1162. void EasyMainWindow::checkFrameTimeReady()
  1163. {
  1164. if (EASY_GLOBALS.fps_enabled && EASY_GLOBALS.connected && (m_listener.regime() == LISTENER_IDLE || m_listener.regime() == LISTENER_CAPTURE))
  1165. {
  1166. uint32_t maxTime = 0, avgTime = 0;
  1167. if (m_listener.frameTime(maxTime, avgTime))
  1168. {
  1169. static_cast<EasyFrameRateViewer*>(m_fpsViewer->widget())->addPoint(maxTime, avgTime);
  1170. }
  1171. else if (m_fpsRequestTimer.isActive())
  1172. {
  1173. QTimer::singleShot(100, this, &This::checkFrameTimeReady);
  1174. }
  1175. }
  1176. }
  1177. //////////////////////////////////////////////////////////////////////////
  1178. void EasyMainWindow::onListenerTimerTimeout()
  1179. {
  1180. if (!m_listener.connected())
  1181. {
  1182. if (m_listener.regime() == LISTENER_CAPTURE_RECEIVE)
  1183. m_listener.finalizeCapture();
  1184. m_listenerDialog->reject();
  1185. }
  1186. else if (m_listener.regime() == LISTENER_CAPTURE_RECEIVE)
  1187. {
  1188. if (m_listener.captured())
  1189. {
  1190. if (m_listenerTimer.isActive())
  1191. m_listenerTimer.stop();
  1192. m_listener.finalizeCapture();
  1193. m_listenerDialog->accept();
  1194. m_listenerDialog = nullptr;
  1195. if (m_listener.size() != 0)
  1196. {
  1197. readStream(m_listener.data());
  1198. m_listener.clearData();
  1199. }
  1200. }
  1201. }
  1202. }
  1203. void EasyMainWindow::onListenerDialogClose(int _result)
  1204. {
  1205. if (m_listener.regime() != LISTENER_CAPTURE_RECEIVE || !m_listener.connected())
  1206. {
  1207. if (m_listenerTimer.isActive())
  1208. m_listenerTimer.stop();
  1209. }
  1210. disconnect(m_listenerDialog, &QDialog::finished, this, &This::onListenerDialogClose);
  1211. m_listenerDialog = nullptr;
  1212. switch (m_listener.regime())
  1213. {
  1214. case LISTENER_CAPTURE:
  1215. {
  1216. m_listenerDialog = new QMessageBox(QMessageBox::Information, "Receiving data...", "This process may take some time.", QMessageBox::Cancel, this);
  1217. m_listenerDialog->setAttribute(Qt::WA_DeleteOnClose, true);
  1218. m_listenerDialog->show();
  1219. m_listener.stopCapture();
  1220. if (m_listener.regime() != LISTENER_CAPTURE_RECEIVE)
  1221. {
  1222. m_listenerDialog->reject();
  1223. m_listenerDialog = nullptr;
  1224. }
  1225. else
  1226. {
  1227. connect(m_listenerDialog, &QDialog::finished, this, &This::onListenerDialogClose);
  1228. m_listenerTimer.start(250);
  1229. }
  1230. break;
  1231. }
  1232. case LISTENER_CAPTURE_RECEIVE:
  1233. {
  1234. if (!m_listener.captured())
  1235. {
  1236. if (_result == QDialog::Accepted)
  1237. {
  1238. m_listenerDialog = new QMessageBox(QMessageBox::Information, "Receiving data...", "This process may take some time.", QMessageBox::Cancel, this);
  1239. connect(m_listenerDialog, &QDialog::finished, this, &This::onListenerDialogClose);
  1240. m_listenerDialog->setAttribute(Qt::WA_DeleteOnClose, true);
  1241. m_listenerDialog->show();
  1242. }
  1243. else
  1244. {
  1245. m_listener.finalizeCapture();
  1246. m_listener.clearData();
  1247. if (m_listener.connected())
  1248. {
  1249. // make reconnect to clear socket buffers
  1250. std::string address = m_listener.address();
  1251. profiler::net::EasyProfilerStatus reply(false, false, false);
  1252. if (m_listener.connect(address.c_str(), m_listener.port(), reply))
  1253. {
  1254. disconnect(m_eventTracingEnableAction, &QAction::triggered, this, &This::onEventTracingEnableChange);
  1255. disconnect(m_eventTracingPriorityAction, &QAction::triggered, this, &This::onEventTracingPriorityChange);
  1256. m_eventTracingEnableAction->setChecked(reply.isEventTracingEnabled);
  1257. m_eventTracingPriorityAction->setChecked(reply.isLowPriorityEventTracing);
  1258. connect(m_eventTracingEnableAction, &QAction::triggered, this, &This::onEventTracingEnableChange);
  1259. connect(m_eventTracingPriorityAction, &QAction::triggered, this, &This::onEventTracingPriorityChange);
  1260. if (reply.isProfilerEnabled)
  1261. {
  1262. // Connected application is already profiling.
  1263. // Show capture dialog immediately
  1264. onCaptureClicked(true);
  1265. }
  1266. }
  1267. }
  1268. }
  1269. break;
  1270. }
  1271. if (m_listenerTimer.isActive())
  1272. m_listenerTimer.stop();
  1273. m_listener.finalizeCapture();
  1274. if (m_listener.size() != 0)
  1275. {
  1276. readStream(m_listener.data());
  1277. m_listener.clearData();
  1278. }
  1279. break;
  1280. }
  1281. case LISTENER_DESCRIBE:
  1282. {
  1283. break;
  1284. }
  1285. default:
  1286. return;
  1287. }
  1288. if (!m_listener.connected())
  1289. {
  1290. setDisconnected();
  1291. }
  1292. }
  1293. //////////////////////////////////////////////////////////////////////////
  1294. void EasyMainWindow::onFileReaderTimeout()
  1295. {
  1296. if (m_reader.done())
  1297. {
  1298. auto nblocks = m_reader.size();
  1299. if (nblocks != 0)
  1300. {
  1301. static_cast<EasyHierarchyWidget*>(m_treeWidget->widget())->clear(true);
  1302. ::profiler::SerializedData serialized_blocks;
  1303. ::profiler::SerializedData serialized_descriptors;
  1304. ::profiler::descriptors_list_t descriptors;
  1305. ::profiler::blocks_t blocks;
  1306. ::profiler::thread_blocks_tree_t threads_map;
  1307. QString filename;
  1308. uint32_t descriptorsNumberInFile = 0;
  1309. uint32_t version = 0;
  1310. m_reader.get(serialized_blocks, serialized_descriptors, descriptors, blocks, threads_map, descriptorsNumberInFile, version, filename);
  1311. if (threads_map.size() > 0xff)
  1312. {
  1313. if (m_reader.isFile())
  1314. qWarning() << "Warning: file " << filename << " contains " << threads_map.size() << " threads!";
  1315. else
  1316. qWarning() << "Warning: input stream contains " << threads_map.size() << " threads!";
  1317. qWarning() << "Warning: Currently, maximum number of displayed threads is 255! Some threads will not be displayed.";
  1318. }
  1319. m_bNetworkFileRegime = !m_reader.isFile();
  1320. if (!m_bNetworkFileRegime)
  1321. {
  1322. auto index = m_lastFiles.indexOf(filename, 0);
  1323. if (index == -1)
  1324. {
  1325. // This file is totally new. Add it to the list.
  1326. addFileToList(filename);
  1327. }
  1328. else
  1329. {
  1330. if (index != 0)
  1331. {
  1332. // This file has been already loaded. Move it to the front.
  1333. m_lastFiles.move(index, 0);
  1334. auto fileActions = m_loadActionMenu->actions();
  1335. auto action = fileActions.at(index);
  1336. m_loadActionMenu->removeAction(action);
  1337. m_loadActionMenu->insertAction(fileActions.front(), action);
  1338. }
  1339. m_bOpenedCacheFile = filename.contains(NETWORK_CACHE_FILE);
  1340. if (m_bOpenedCacheFile)
  1341. setWindowTitle(QString(EASY_DEFAULT_WINDOW_TITLE " - [%1] - UNSAVED network cache file").arg(filename));
  1342. else
  1343. setWindowTitle(QString(EASY_DEFAULT_WINDOW_TITLE " - [%1]").arg(filename));
  1344. }
  1345. }
  1346. else
  1347. {
  1348. m_bOpenedCacheFile = false;
  1349. setWindowTitle(EASY_DEFAULT_WINDOW_TITLE " - UNSAVED network cache");
  1350. }
  1351. m_serializedBlocks = ::std::move(serialized_blocks);
  1352. m_serializedDescriptors = ::std::move(serialized_descriptors);
  1353. m_descriptorsNumberInFile = descriptorsNumberInFile;
  1354. EASY_GLOBALS.selected_thread = 0;
  1355. EASY_GLOBALS.version = version;
  1356. ::profiler_gui::set_max(EASY_GLOBALS.selected_block);
  1357. ::profiler_gui::set_max(EASY_GLOBALS.selected_block_id);
  1358. EASY_GLOBALS.profiler_blocks.swap(threads_map);
  1359. EASY_GLOBALS.descriptors.swap(descriptors);
  1360. EASY_GLOBALS.gui_blocks.clear();
  1361. EASY_GLOBALS.gui_blocks.resize(nblocks);
  1362. memset(EASY_GLOBALS.gui_blocks.data(), 0, sizeof(::profiler_gui::EasyBlock) * nblocks);
  1363. for (decltype(nblocks) i = 0; i < nblocks; ++i) {
  1364. auto& guiblock = EASY_GLOBALS.gui_blocks[i];
  1365. guiblock.tree = ::std::move(blocks[i]);
  1366. #ifdef EASY_TREE_WIDGET__USE_VECTOR
  1367. ::profiler_gui::set_max(guiblock.tree_item);
  1368. #endif
  1369. }
  1370. static_cast<EasyGraphicsViewWidget*>(m_graphicsView->widget())->view()->setTree(EASY_GLOBALS.profiler_blocks);
  1371. #if EASY_GUI_USE_DESCRIPTORS_DOCK_WINDOW != 0
  1372. static_cast<EasyDescWidget*>(m_descTreeWidget->widget())->build();
  1373. #endif
  1374. if (m_dialogDescTree != nullptr)
  1375. m_dialogDescTree->build();
  1376. m_saveAction->setEnabled(true);
  1377. m_deleteAction->setEnabled(true);
  1378. }
  1379. else
  1380. {
  1381. QMessageBox::warning(this, "Warning", QString("Can not read profiled blocks.\n\nReason:\n%1").arg(m_reader.getError()), QMessageBox::Close);
  1382. if (m_reader.isFile())
  1383. {
  1384. auto index = m_lastFiles.indexOf(m_reader.filename(), 0);
  1385. if (index >= 0)
  1386. {
  1387. // Remove unexisting file from list
  1388. m_lastFiles.removeAt(index);
  1389. auto action = m_loadActionMenu->actions().at(index);
  1390. m_loadActionMenu->removeAction(action);
  1391. delete action;
  1392. }
  1393. }
  1394. }
  1395. m_reader.interrupt();
  1396. m_readerTimer.stop();
  1397. m_progress->setValue(100);
  1398. //m_progress->hide();
  1399. if (EASY_GLOBALS.all_items_expanded_by_default)
  1400. {
  1401. onExpandAllClicked(true);
  1402. }
  1403. }
  1404. else
  1405. {
  1406. m_progress->setValue(m_reader.progress());
  1407. }
  1408. }
  1409. void EasyMainWindow::onFileReaderCancel()
  1410. {
  1411. m_readerTimer.stop();
  1412. m_reader.interrupt();
  1413. m_progress->setValue(100);
  1414. //m_progress->hide();
  1415. }
  1416. //////////////////////////////////////////////////////////////////////////
  1417. EasyFileReader::EasyFileReader()
  1418. {
  1419. }
  1420. EasyFileReader::~EasyFileReader()
  1421. {
  1422. interrupt();
  1423. }
  1424. const bool EasyFileReader::isFile() const
  1425. {
  1426. return m_isFile;
  1427. }
  1428. bool EasyFileReader::done() const
  1429. {
  1430. return m_bDone.load(::std::memory_order_acquire);
  1431. }
  1432. int EasyFileReader::progress() const
  1433. {
  1434. return m_progress.load(::std::memory_order_acquire);
  1435. }
  1436. unsigned int EasyFileReader::size() const
  1437. {
  1438. return m_size.load(::std::memory_order_acquire);
  1439. }
  1440. const QString& EasyFileReader::filename() const
  1441. {
  1442. return m_filename;
  1443. }
  1444. void EasyFileReader::load(const QString& _filename)
  1445. {
  1446. interrupt();
  1447. m_isFile = true;
  1448. m_filename = _filename;
  1449. m_thread = ::std::thread([this](bool _enableStatistics) {
  1450. m_size.store(fillTreesFromFile(m_progress, m_filename.toStdString().c_str(), m_serializedBlocks, m_serializedDescriptors,
  1451. m_descriptors, m_blocks, m_blocksTree, m_descriptorsNumberInFile, m_version, _enableStatistics, m_errorMessage), ::std::memory_order_release);
  1452. m_progress.store(100, ::std::memory_order_release);
  1453. m_bDone.store(true, ::std::memory_order_release);
  1454. }, EASY_GLOBALS.enable_statistics);
  1455. }
  1456. void EasyFileReader::load(::std::stringstream& _stream)
  1457. {
  1458. interrupt();
  1459. m_isFile = false;
  1460. m_filename.clear();
  1461. #if defined(__GNUC__) && __GNUC__ < 5 && !defined(__llvm__)
  1462. // gcc 4 has a known bug which has been solved in gcc 5:
  1463. // std::stringstream has no swap() method :(
  1464. // have to copy all contents... Use gcc 5 or higher!
  1465. #pragma message "Warning: in gcc 4 and lower std::stringstream has no swap()! Memory consumption may increase! Better use gcc 5 or higher instead."
  1466. m_stream.str(_stream.str());
  1467. #else
  1468. m_stream.swap(_stream);
  1469. #endif
  1470. m_thread = ::std::thread([this](bool _enableStatistics) {
  1471. ::std::ofstream cache_file(NETWORK_CACHE_FILE, ::std::fstream::binary);
  1472. if (cache_file.is_open()) {
  1473. cache_file << m_stream.str();
  1474. cache_file.close();
  1475. }
  1476. m_size.store(fillTreesFromStream(m_progress, m_stream, m_serializedBlocks, m_serializedDescriptors, m_descriptors,
  1477. m_blocks, m_blocksTree, m_descriptorsNumberInFile, m_version, _enableStatistics, m_errorMessage), ::std::memory_order_release);
  1478. m_progress.store(100, ::std::memory_order_release);
  1479. m_bDone.store(true, ::std::memory_order_release);
  1480. }, EASY_GLOBALS.enable_statistics);
  1481. }
  1482. void EasyFileReader::interrupt()
  1483. {
  1484. m_progress.store(-100, ::std::memory_order_release);
  1485. if (m_thread.joinable())
  1486. m_thread.join();
  1487. m_bDone.store(false, ::std::memory_order_release);
  1488. m_progress.store(0, ::std::memory_order_release);
  1489. m_size.store(0, ::std::memory_order_release);
  1490. m_serializedBlocks.clear();
  1491. m_serializedDescriptors.clear();
  1492. m_descriptors.clear();
  1493. m_blocks.clear();
  1494. m_blocksTree.clear();
  1495. m_descriptorsNumberInFile = 0;
  1496. m_version = 0;
  1497. clear_stream(m_stream);
  1498. clear_stream(m_errorMessage);
  1499. }
  1500. void EasyFileReader::get(::profiler::SerializedData& _serializedBlocks, ::profiler::SerializedData& _serializedDescriptors,
  1501. ::profiler::descriptors_list_t& _descriptors, ::profiler::blocks_t& _blocks,
  1502. ::profiler::thread_blocks_tree_t& _tree, uint32_t& _descriptorsNumberInFile, uint32_t& _version, QString& _filename)
  1503. {
  1504. if (done())
  1505. {
  1506. m_serializedBlocks.swap(_serializedBlocks);
  1507. m_serializedDescriptors.swap(_serializedDescriptors);
  1508. ::profiler::descriptors_list_t(::std::move(m_descriptors)).swap(_descriptors);
  1509. m_blocks.swap(_blocks);
  1510. m_blocksTree.swap(_tree);
  1511. m_filename.swap(_filename);
  1512. _descriptorsNumberInFile = m_descriptorsNumberInFile;
  1513. _version = m_version;
  1514. }
  1515. }
  1516. QString EasyFileReader::getError()
  1517. {
  1518. return QString(m_errorMessage.str().c_str());
  1519. }
  1520. //////////////////////////////////////////////////////////////////////////
  1521. void EasyMainWindow::onEventTracingPriorityChange(bool _checked)
  1522. {
  1523. if (EASY_GLOBALS.connected)
  1524. m_listener.send(profiler::net::BoolMessage(profiler::net::MESSAGE_TYPE_EVENT_TRACING_PRIORITY, _checked));
  1525. }
  1526. void EasyMainWindow::onEventTracingEnableChange(bool _checked)
  1527. {
  1528. if (EASY_GLOBALS.connected)
  1529. m_listener.send(profiler::net::BoolMessage(profiler::net::MESSAGE_TYPE_EVENT_TRACING_STATUS, _checked));
  1530. }
  1531. //////////////////////////////////////////////////////////////////////////
  1532. void EasyMainWindow::onFrameTimeEditFinish()
  1533. {
  1534. auto text = m_frameTimeEdit->text();
  1535. if (text.contains(QChar(',')))
  1536. {
  1537. text.remove(QChar('.')).replace(QChar(','), QChar('.'));
  1538. m_frameTimeEdit->setText(text);
  1539. }
  1540. EASY_GLOBALS.frame_time = text.toFloat() * 1e3f;
  1541. disconnect(&EASY_GLOBALS.events, &::profiler_gui::EasyGlobalSignals::expectedFrameTimeChanged, this, &This::onFrameTimeChanged);
  1542. emit EASY_GLOBALS.events.expectedFrameTimeChanged();
  1543. connect(&EASY_GLOBALS.events, &::profiler_gui::EasyGlobalSignals::expectedFrameTimeChanged, this, &This::onFrameTimeChanged);
  1544. }
  1545. void EasyMainWindow::onFrameTimeChanged()
  1546. {
  1547. m_frameTimeEdit->setText(QString::number(EASY_GLOBALS.frame_time * 1e-3));
  1548. }
  1549. //////////////////////////////////////////////////////////////////////////
  1550. void EasyMainWindow::onConnectClicked(bool)
  1551. {
  1552. if (EASY_GLOBALS.connected)
  1553. {
  1554. // Disconnect if already connected
  1555. m_listener.disconnect();
  1556. setDisconnected(false);
  1557. return;
  1558. }
  1559. QString address = m_addressEdit->text();
  1560. const decltype(m_lastPort) port = m_portEdit->text().toUShort();
  1561. const bool isSameAddress = (EASY_GLOBALS.connected && m_listener.port() == port && address.toStdString() == m_listener.address());
  1562. profiler::net::EasyProfilerStatus reply(false, false, false);
  1563. if (!m_listener.connect(address.toStdString().c_str(), port, reply))
  1564. {
  1565. /*if (EASY_GLOBALS.connected && !isSameAddress)
  1566. {
  1567. if (QMessageBox::warning(this, "Warning", QString("Cannot connect to %1\n\nRestore previous connection?").arg(address),
  1568. QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes)
  1569. {
  1570. if (!m_listener.connect(m_lastAddress.toStdString().c_str(), m_lastPort, reply))
  1571. {
  1572. QMessageBox::warning(this, "Warning", "Cannot restore previous connection", QMessageBox::Close);
  1573. setDisconnected(false);
  1574. m_lastAddress = ::std::move(address);
  1575. m_lastPort = port;
  1576. }
  1577. else
  1578. {
  1579. m_addressEdit->setText(m_lastAddress);
  1580. m_portEdit->setText(QString::number(m_lastPort));
  1581. //QMessageBox::information(this, "Information", "Previous connection restored", QMessageBox::Close);
  1582. }
  1583. }
  1584. else
  1585. {
  1586. setDisconnected(false);
  1587. m_lastAddress = ::std::move(address);
  1588. m_lastPort = port;
  1589. }
  1590. }
  1591. else*/
  1592. {
  1593. QMessageBox::warning(this, "Warning", QString("Cannot connect to %1").arg(address), QMessageBox::Close);
  1594. if (EASY_GLOBALS.connected)
  1595. setDisconnected(false);
  1596. if (!isSameAddress)
  1597. {
  1598. m_lastAddress = ::std::move(address);
  1599. m_lastPort = port;
  1600. }
  1601. }
  1602. return;
  1603. }
  1604. m_lastAddress = ::std::move(address);
  1605. m_lastPort = port;
  1606. qInfo() << "Connected successfully";
  1607. EASY_GLOBALS.connected = true;
  1608. m_captureAction->setEnabled(true);
  1609. SET_ICON(m_connectAction, ":/Connection-on");
  1610. m_connectAction->setText(tr("Disconnect"));
  1611. if (m_fpsViewer->isVisible())
  1612. static_cast<EasyFrameRateViewer*>(m_fpsViewer->widget())->clear();
  1613. if (!m_fpsRequestTimer.isActive())
  1614. m_fpsRequestTimer.start(EASY_GLOBALS.fps_timer_interval);
  1615. disconnect(m_eventTracingEnableAction, &QAction::triggered, this, &This::onEventTracingEnableChange);
  1616. disconnect(m_eventTracingPriorityAction, &QAction::triggered, this, &This::onEventTracingPriorityChange);
  1617. m_eventTracingEnableAction->setEnabled(true);
  1618. m_eventTracingPriorityAction->setEnabled(true);
  1619. m_eventTracingEnableAction->setChecked(reply.isEventTracingEnabled);
  1620. m_eventTracingPriorityAction->setChecked(reply.isLowPriorityEventTracing);
  1621. connect(m_eventTracingEnableAction, &QAction::triggered, this, &This::onEventTracingEnableChange);
  1622. connect(m_eventTracingPriorityAction, &QAction::triggered, this, &This::onEventTracingPriorityChange);
  1623. m_addressEdit->setEnabled(false);
  1624. m_portEdit->setEnabled(false);
  1625. emit EASY_GLOBALS.events.connectionChanged(true);
  1626. if (reply.isProfilerEnabled)
  1627. {
  1628. // Connected application is already profiling.
  1629. // Show capture dialog immediately
  1630. onCaptureClicked(true);
  1631. }
  1632. }
  1633. void EasyMainWindow::onCaptureClicked(bool)
  1634. {
  1635. if (!EASY_GLOBALS.connected)
  1636. {
  1637. QMessageBox::warning(this, "Warning", "No connection with profiling app", QMessageBox::Close);
  1638. return;
  1639. }
  1640. if (m_listener.regime() != LISTENER_IDLE)
  1641. {
  1642. if (m_listener.regime() == LISTENER_CAPTURE || m_listener.regime() == LISTENER_CAPTURE_RECEIVE)
  1643. QMessageBox::warning(this, "Warning", "Already capturing frames.\nFinish old capturing session first.", QMessageBox::Close);
  1644. else
  1645. QMessageBox::warning(this, "Warning", "Capturing blocks description.\nFinish old capturing session first.", QMessageBox::Close);
  1646. return;
  1647. }
  1648. if (!m_listener.startCapture())
  1649. {
  1650. // Connection lost. Try to restore connection.
  1651. profiler::net::EasyProfilerStatus reply(false, false, false);
  1652. if (!m_listener.connect(m_lastAddress.toStdString().c_str(), m_lastPort, reply))
  1653. {
  1654. setDisconnected();
  1655. return;
  1656. }
  1657. if (!m_listener.startCapture())
  1658. {
  1659. setDisconnected();
  1660. return;
  1661. }
  1662. }
  1663. m_listenerTimer.start(250);
  1664. m_listenerDialog = new QMessageBox(QMessageBox::Information, "Capturing frames...", "Close this dialog to stop capturing.", QMessageBox::NoButton, this);
  1665. auto button = new QToolButton(m_listenerDialog);
  1666. button->setAutoRaise(true);
  1667. button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
  1668. button->setIconSize(::profiler_gui::ICONS_SIZE);
  1669. button->setIcon(QIcon(":/Stop"));
  1670. button->setText("Stop");
  1671. m_listenerDialog->addButton(button, QMessageBox::AcceptRole);
  1672. m_listenerDialog->setAttribute(Qt::WA_DeleteOnClose, true);
  1673. connect(m_listenerDialog, &QDialog::finished, this, &This::onListenerDialogClose);
  1674. m_listenerDialog->show();
  1675. }
  1676. void EasyMainWindow::onGetBlockDescriptionsClicked(bool)
  1677. {
  1678. if (!EASY_GLOBALS.connected)
  1679. {
  1680. QMessageBox::warning(this, "Warning", "No connection with profiling app", QMessageBox::Close);
  1681. return;
  1682. }
  1683. if (m_listener.regime() != LISTENER_IDLE)
  1684. {
  1685. if (m_listener.regime() == LISTENER_DESCRIBE)
  1686. QMessageBox::warning(this, "Warning", "Already capturing blocks description.\nFinish old capturing session first.", QMessageBox::Close);
  1687. else
  1688. QMessageBox::warning(this, "Warning", "Capturing capturing frames.\nFinish old capturing session first.", QMessageBox::Close);
  1689. return;
  1690. }
  1691. m_listenerDialog = new QMessageBox(QMessageBox::Information, "Waiting for blocks...", "This may take some time.", QMessageBox::NoButton, this);
  1692. m_listenerDialog->setAttribute(Qt::WA_DeleteOnClose, true);
  1693. m_listenerDialog->show();
  1694. m_listener.requestBlocksDescription();
  1695. m_listenerDialog->reject();
  1696. m_listenerDialog = nullptr;
  1697. if (m_listener.size() != 0)
  1698. {
  1699. // Read descriptions from stream
  1700. decltype(EASY_GLOBALS.descriptors) descriptors;
  1701. decltype(m_serializedDescriptors) serializedDescriptors;
  1702. ::std::stringstream errorMessage;
  1703. if (readDescriptionsFromStream(m_listener.data(), serializedDescriptors, descriptors, errorMessage))
  1704. {
  1705. // Merge old and new descriptions
  1706. bool cancel = false;
  1707. const bool doFlush = m_descriptorsNumberInFile > descriptors.size();
  1708. if (doFlush && !m_serializedBlocks.empty())
  1709. {
  1710. auto button = QMessageBox::question(this, "Information",
  1711. QString("New blocks description number = %1\nis less than the old one = %2.\nTo avoid possible conflicts\nall profiled data will be deleted.\nContinue?")
  1712. .arg(descriptors.size())
  1713. .arg(m_descriptorsNumberInFile),
  1714. QMessageBox::Yes, QMessageBox::No);
  1715. if (button == QMessageBox::Yes)
  1716. clear(); // Clear all contents because new descriptors list conflicts with old one
  1717. else
  1718. cancel = true;
  1719. }
  1720. if (!cancel)
  1721. {
  1722. if (!doFlush && m_descriptorsNumberInFile < EASY_GLOBALS.descriptors.size())
  1723. {
  1724. // There are dynamically added descriptors, add them to the new list too
  1725. auto newnumber = static_cast<decltype(m_descriptorsNumberInFile)>(descriptors.size());
  1726. auto size = static_cast<decltype(m_descriptorsNumberInFile)>(EASY_GLOBALS.descriptors.size());
  1727. auto diff = newnumber - size;
  1728. decltype(newnumber) failnumber = 0;
  1729. descriptors.reserve(descriptors.size() + EASY_GLOBALS.descriptors.size() - m_descriptorsNumberInFile);
  1730. for (auto i = m_descriptorsNumberInFile; i < size; ++i)
  1731. {
  1732. auto id = EASY_GLOBALS.descriptors[i]->id();
  1733. if (id < newnumber)
  1734. descriptors.push_back(descriptors[id]);
  1735. else
  1736. ++failnumber;
  1737. }
  1738. if (failnumber != 0)
  1739. {
  1740. // There are some errors...
  1741. // revert changes
  1742. descriptors.resize(newnumber);
  1743. // clear all profiled data to avoid conflicts
  1744. auto button = QMessageBox::question(this, "Information",
  1745. "There are errors while merging block descriptions lists.\nTo avoid possible conflicts\nall profiled data will be deleted.\nContinue?",
  1746. QMessageBox::Yes, QMessageBox::No);
  1747. if (button == QMessageBox::Yes)
  1748. clear(); // Clear all contents because new descriptors list conflicts with old one
  1749. else
  1750. cancel = true;
  1751. }
  1752. if (!cancel && diff != 0)
  1753. {
  1754. for (auto& b : EASY_GLOBALS.gui_blocks)
  1755. {
  1756. if (b.tree.node->id() >= m_descriptorsNumberInFile)
  1757. b.tree.node->setId(b.tree.node->id() + diff);
  1758. }
  1759. m_descriptorsNumberInFile = newnumber;
  1760. }
  1761. }
  1762. if (!cancel)
  1763. {
  1764. EASY_GLOBALS.descriptors.swap(descriptors);
  1765. m_serializedDescriptors.swap(serializedDescriptors);
  1766. m_descriptorsNumberInFile = static_cast<uint32_t>(EASY_GLOBALS.descriptors.size());
  1767. if (m_descTreeDialog != nullptr)
  1768. {
  1769. #if EASY_GUI_USE_DESCRIPTORS_DOCK_WINDOW != 0
  1770. static_cast<EasyDescWidget*>(m_descTreeWidget->widget())->build();
  1771. #endif
  1772. m_dialogDescTree->build();
  1773. m_descTreeDialog->raise();
  1774. }
  1775. else
  1776. {
  1777. onEditBlocksClicked(true);
  1778. }
  1779. }
  1780. }
  1781. }
  1782. else
  1783. {
  1784. QMessageBox::warning(this, "Warning", QString("Can not read blocks description from stream.\n\nReason:\n%1").arg(errorMessage.str().c_str()), QMessageBox::Close);
  1785. }
  1786. m_listener.clearData();
  1787. }
  1788. if (!m_listener.connected())
  1789. {
  1790. setDisconnected();
  1791. }
  1792. }
  1793. //////////////////////////////////////////////////////////////////////////
  1794. void EasyMainWindow::onBlockStatusChange(::profiler::block_id_t _id, ::profiler::EasyBlockStatus _status)
  1795. {
  1796. if (EASY_GLOBALS.connected)
  1797. m_listener.send(profiler::net::BlockStatusMessage(_id, static_cast<uint8_t>(_status)));
  1798. }
  1799. //////////////////////////////////////////////////////////////////////////
  1800. EasySocketListener::EasySocketListener() : m_receivedSize(0), m_port(0), m_regime(LISTENER_IDLE)
  1801. {
  1802. m_bInterrupt = ATOMIC_VAR_INIT(false);
  1803. m_bConnected = ATOMIC_VAR_INIT(false);
  1804. m_bStopReceive = ATOMIC_VAR_INIT(false);
  1805. m_bFrameTimeReady = ATOMIC_VAR_INIT(false);
  1806. m_bCaptureReady = ATOMIC_VAR_INIT(false);
  1807. m_frameMax = ATOMIC_VAR_INIT(0);
  1808. m_frameAvg = ATOMIC_VAR_INIT(0);
  1809. }
  1810. EasySocketListener::~EasySocketListener()
  1811. {
  1812. m_bInterrupt.store(true, ::std::memory_order_release);
  1813. if (m_thread.joinable())
  1814. m_thread.join();
  1815. }
  1816. bool EasySocketListener::connected() const
  1817. {
  1818. return m_bConnected.load(::std::memory_order_acquire);
  1819. }
  1820. bool EasySocketListener::captured() const
  1821. {
  1822. return m_bCaptureReady.load(::std::memory_order_acquire);
  1823. }
  1824. EasyListenerRegime EasySocketListener::regime() const
  1825. {
  1826. return m_regime;
  1827. }
  1828. uint64_t EasySocketListener::size() const
  1829. {
  1830. return m_receivedSize;
  1831. }
  1832. ::std::stringstream& EasySocketListener::data()
  1833. {
  1834. return m_receivedData;
  1835. }
  1836. const ::std::string& EasySocketListener::address() const
  1837. {
  1838. return m_address;
  1839. }
  1840. uint16_t EasySocketListener::port() const
  1841. {
  1842. return m_port;
  1843. }
  1844. void EasySocketListener::clearData()
  1845. {
  1846. clear_stream(m_receivedData);
  1847. m_receivedSize = 0;
  1848. }
  1849. void EasySocketListener::disconnect()
  1850. {
  1851. if (connected())
  1852. {
  1853. m_bInterrupt.store(true, ::std::memory_order_release);
  1854. if (m_thread.joinable())
  1855. m_thread.join();
  1856. m_bConnected.store(false, ::std::memory_order_release);
  1857. m_bInterrupt.store(false, ::std::memory_order_release);
  1858. m_bCaptureReady.store(false, ::std::memory_order_release);
  1859. m_bStopReceive.store(false, ::std::memory_order_release);
  1860. }
  1861. m_address.clear();
  1862. m_port = 0;
  1863. m_easySocket.flush();
  1864. m_easySocket.init();
  1865. }
  1866. bool EasySocketListener::connect(const char* _ipaddress, uint16_t _port, profiler::net::EasyProfilerStatus& _reply)
  1867. {
  1868. if (connected())
  1869. {
  1870. m_bInterrupt.store(true, ::std::memory_order_release);
  1871. if (m_thread.joinable())
  1872. m_thread.join();
  1873. m_bConnected.store(false, ::std::memory_order_release);
  1874. m_bInterrupt.store(false, ::std::memory_order_release);
  1875. m_bCaptureReady.store(false, ::std::memory_order_release);
  1876. m_bStopReceive.store(false, ::std::memory_order_release);
  1877. }
  1878. m_address.clear();
  1879. m_port = 0;
  1880. //m_easySocket.flush();
  1881. //m_easySocket.init();
  1882. int res = m_easySocket.setAddress(_ipaddress, _port);
  1883. res = m_easySocket.connect();
  1884. const bool isConnected = res == 0;
  1885. if (isConnected)
  1886. {
  1887. static const size_t buffer_size = sizeof(profiler::net::EasyProfilerStatus) << 1;
  1888. char buffer[buffer_size] = {};
  1889. int bytes = 0;
  1890. while (true)
  1891. {
  1892. bytes = m_easySocket.receive(buffer, buffer_size);
  1893. if (bytes == -1)
  1894. {
  1895. if (m_easySocket.isDisconnected())
  1896. return false;
  1897. bytes = 0;
  1898. continue;
  1899. }
  1900. break;
  1901. }
  1902. if (bytes == 0)
  1903. {
  1904. m_address = _ipaddress;
  1905. m_port = _port;
  1906. m_bConnected.store(isConnected, ::std::memory_order_release);
  1907. return isConnected;
  1908. }
  1909. size_t seek = bytes;
  1910. while (seek < sizeof(profiler::net::EasyProfilerStatus))
  1911. {
  1912. bytes = m_easySocket.receive(buffer + seek, buffer_size - seek);
  1913. if (bytes == -1)
  1914. {
  1915. if (m_easySocket.isDisconnected())
  1916. return false;
  1917. break;
  1918. }
  1919. seek += bytes;
  1920. }
  1921. auto message = reinterpret_cast<const ::profiler::net::EasyProfilerStatus*>(buffer);
  1922. if (message->isEasyNetMessage() && message->type == profiler::net::MESSAGE_TYPE_ACCEPTED_CONNECTION)
  1923. _reply = *message;
  1924. m_address = _ipaddress;
  1925. m_port = _port;
  1926. }
  1927. m_bConnected.store(isConnected, ::std::memory_order_release);
  1928. return isConnected;
  1929. }
  1930. bool EasySocketListener::startCapture()
  1931. {
  1932. //if (m_thread.joinable())
  1933. //{
  1934. // m_bInterrupt.store(true, ::std::memory_order_release);
  1935. // m_thread.join();
  1936. // m_bInterrupt.store(false, ::std::memory_order_release);
  1937. //}
  1938. clearData();
  1939. profiler::net::Message request(profiler::net::MESSAGE_TYPE_REQUEST_START_CAPTURE);
  1940. m_easySocket.send(&request, sizeof(request));
  1941. if (m_easySocket.isDisconnected()) {
  1942. m_bConnected.store(false, ::std::memory_order_release);
  1943. return false;
  1944. }
  1945. m_regime = LISTENER_CAPTURE;
  1946. m_bCaptureReady.store(false, ::std::memory_order_release);
  1947. //m_thread = ::std::thread(&EasySocketListener::listenCapture, this);
  1948. return true;
  1949. }
  1950. void EasySocketListener::stopCapture()
  1951. {
  1952. //if (!m_thread.joinable() || m_regime != LISTENER_CAPTURE)
  1953. // return;
  1954. if (m_regime != LISTENER_CAPTURE)
  1955. return;
  1956. //m_bStopReceive.store(true, ::std::memory_order_release);
  1957. profiler::net::Message request(profiler::net::MESSAGE_TYPE_REQUEST_STOP_CAPTURE);
  1958. m_easySocket.send(&request, sizeof(request));
  1959. //m_thread.join();
  1960. if (m_easySocket.isDisconnected()) {
  1961. m_bConnected.store(false, ::std::memory_order_release);
  1962. m_bStopReceive.store(false, ::std::memory_order_release);
  1963. m_regime = LISTENER_IDLE;
  1964. m_bCaptureReady.store(true, ::std::memory_order_release);
  1965. return;
  1966. }
  1967. m_regime = LISTENER_CAPTURE_RECEIVE;
  1968. if (m_thread.joinable())
  1969. {
  1970. m_bInterrupt.store(true, ::std::memory_order_release);
  1971. m_thread.join();
  1972. m_bInterrupt.store(false, ::std::memory_order_release);
  1973. }
  1974. m_thread = ::std::thread(&EasySocketListener::listenCapture, this);
  1975. //m_regime = LISTENER_IDLE;
  1976. //m_bStopReceive.store(false, ::std::memory_order_release);
  1977. }
  1978. void EasySocketListener::finalizeCapture()
  1979. {
  1980. if (m_thread.joinable())
  1981. {
  1982. m_bInterrupt.store(true, ::std::memory_order_release);
  1983. m_thread.join();
  1984. m_bInterrupt.store(false, ::std::memory_order_release);
  1985. }
  1986. m_regime = LISTENER_IDLE;
  1987. m_bCaptureReady.store(false, ::std::memory_order_release);
  1988. m_bStopReceive.store(false, ::std::memory_order_release);
  1989. }
  1990. void EasySocketListener::requestBlocksDescription()
  1991. {
  1992. if (m_thread.joinable())
  1993. {
  1994. m_bInterrupt.store(true, ::std::memory_order_release);
  1995. m_thread.join();
  1996. m_bInterrupt.store(false, ::std::memory_order_release);
  1997. }
  1998. clearData();
  1999. profiler::net::Message request(profiler::net::MESSAGE_TYPE_REQUEST_BLOCKS_DESCRIPTION);
  2000. m_easySocket.send(&request, sizeof(request));
  2001. if(m_easySocket.isDisconnected() ){
  2002. m_bConnected.store(false, ::std::memory_order_release);
  2003. }
  2004. m_regime = LISTENER_DESCRIBE;
  2005. listenDescription();
  2006. m_regime = LISTENER_IDLE;
  2007. }
  2008. bool EasySocketListener::frameTime(uint32_t& _maxTime, uint32_t& _avgTime)
  2009. {
  2010. if (m_bFrameTimeReady.exchange(false, ::std::memory_order_acquire))
  2011. {
  2012. _maxTime = m_frameMax.load(::std::memory_order_acquire);
  2013. _avgTime = m_frameAvg.load(::std::memory_order_acquire);
  2014. return true;
  2015. }
  2016. return false;
  2017. }
  2018. bool EasySocketListener::requestFrameTime()
  2019. {
  2020. if (m_regime != LISTENER_IDLE && m_regime != LISTENER_CAPTURE)
  2021. return false;
  2022. if (m_thread.joinable())
  2023. {
  2024. m_bInterrupt.store(true, ::std::memory_order_release);
  2025. m_thread.join();
  2026. m_bInterrupt.store(false, ::std::memory_order_release);
  2027. }
  2028. profiler::net::Message request(profiler::net::MESSAGE_TYPE_REQUEST_MAIN_FRAME_TIME_MAX_AVG_US);
  2029. m_easySocket.send(&request, sizeof(request));
  2030. if (m_easySocket.isDisconnected())
  2031. {
  2032. m_bConnected.store(false, ::std::memory_order_release);
  2033. return false;
  2034. }
  2035. m_bFrameTimeReady.store(false, ::std::memory_order_release);
  2036. m_thread = ::std::thread(&EasySocketListener::listenFrameTime, this);
  2037. return true;
  2038. }
  2039. //////////////////////////////////////////////////////////////////////////
  2040. void EasySocketListener::listenCapture()
  2041. {
  2042. // TODO: Merge functions listenCapture() and listenDescription()
  2043. static const int buffer_size = 8 * 1024 * 1024;
  2044. char* buffer = new char[buffer_size];
  2045. int seek = 0, bytes = 0;
  2046. auto timeBegin = ::std::chrono::system_clock::now();
  2047. bool isListen = true, disconnected = false;
  2048. while (isListen && !m_bInterrupt.load(::std::memory_order_acquire))
  2049. {
  2050. if (m_bStopReceive.load(::std::memory_order_acquire))
  2051. {
  2052. profiler::net::Message request(profiler::net::MESSAGE_TYPE_REQUEST_STOP_CAPTURE);
  2053. m_easySocket.send(&request, sizeof(request));
  2054. m_bStopReceive.store(false, ::std::memory_order_release);
  2055. }
  2056. if ((bytes - seek) == 0)
  2057. {
  2058. bytes = m_easySocket.receive(buffer, buffer_size);
  2059. if (bytes == -1)
  2060. {
  2061. if (m_easySocket.isDisconnected())
  2062. {
  2063. m_bConnected.store(false, ::std::memory_order_release);
  2064. isListen = false;
  2065. disconnected = true;
  2066. }
  2067. seek = 0;
  2068. bytes = 0;
  2069. continue;
  2070. }
  2071. seek = 0;
  2072. }
  2073. if (bytes == 0)
  2074. {
  2075. isListen = false;
  2076. break;
  2077. }
  2078. char* buf = buffer + seek;
  2079. if (bytes > 0)
  2080. {
  2081. auto message = reinterpret_cast<const ::profiler::net::Message*>(buf);
  2082. if (!message->isEasyNetMessage())
  2083. continue;
  2084. switch (message->type)
  2085. {
  2086. case profiler::net::MESSAGE_TYPE_ACCEPTED_CONNECTION:
  2087. {
  2088. qInfo() << "Receive MESSAGE_TYPE_ACCEPTED_CONNECTION";
  2089. //m_easySocket.send(&request, sizeof(request));
  2090. seek += sizeof(profiler::net::Message);
  2091. break;
  2092. }
  2093. case profiler::net::MESSAGE_TYPE_REPLY_START_CAPTURING:
  2094. {
  2095. qInfo() << "Receive MESSAGE_TYPE_REPLY_START_CAPTURING";
  2096. seek += sizeof(profiler::net::Message);
  2097. break;
  2098. }
  2099. case profiler::net::MESSAGE_TYPE_REPLY_BLOCKS_END:
  2100. {
  2101. qInfo() << "Receive MESSAGE_TYPE_REPLY_BLOCKS_END";
  2102. seek += sizeof(profiler::net::Message);
  2103. const auto dt = ::std::chrono::duration_cast<std::chrono::milliseconds>(::std::chrono::system_clock::now() - timeBegin);
  2104. const auto bytesNumber = m_receivedData.str().size();
  2105. qInfo() << "recieved " << bytesNumber << " bytes, " << dt.count() << " ms, average speed = " << double(bytesNumber) * 1e3 / double(dt.count()) / 1024. << " kBytes/sec";
  2106. seek = 0;
  2107. bytes = 0;
  2108. isListen = false;
  2109. break;
  2110. }
  2111. case profiler::net::MESSAGE_TYPE_REPLY_BLOCKS:
  2112. {
  2113. qInfo() << "Receive MESSAGE_TYPE_REPLY_BLOCKS";
  2114. seek += sizeof(profiler::net::DataMessage);
  2115. profiler::net::DataMessage* dm = (profiler::net::DataMessage*)message;
  2116. timeBegin = std::chrono::system_clock::now();
  2117. int neededSize = dm->size;
  2118. buf = buffer + seek;
  2119. auto bytesNumber = ::std::min((int)dm->size, bytes - seek);
  2120. m_receivedSize += bytesNumber;
  2121. m_receivedData.write(buf, bytesNumber);
  2122. neededSize -= bytesNumber;
  2123. if (neededSize == 0)
  2124. seek += bytesNumber;
  2125. else
  2126. {
  2127. seek = 0;
  2128. bytes = 0;
  2129. }
  2130. int loaded = 0;
  2131. while (neededSize > 0)
  2132. {
  2133. bytes = m_easySocket.receive(buffer, buffer_size);
  2134. if (bytes == -1)
  2135. {
  2136. if (m_easySocket.isDisconnected())
  2137. {
  2138. m_bConnected.store(false, ::std::memory_order_release);
  2139. isListen = false;
  2140. disconnected = true;
  2141. neededSize = 0;
  2142. }
  2143. break;
  2144. }
  2145. buf = buffer;
  2146. int toWrite = ::std::min(bytes, neededSize);
  2147. m_receivedSize += toWrite;
  2148. m_receivedData.write(buf, toWrite);
  2149. neededSize -= toWrite;
  2150. loaded += toWrite;
  2151. seek = toWrite;
  2152. }
  2153. if (m_bStopReceive.load(::std::memory_order_acquire))
  2154. {
  2155. profiler::net::Message request(profiler::net::MESSAGE_TYPE_REQUEST_STOP_CAPTURE);
  2156. m_easySocket.send(&request, sizeof(request));
  2157. m_bStopReceive.store(false, ::std::memory_order_release);
  2158. }
  2159. break;
  2160. }
  2161. default:
  2162. //qInfo() << "Receive unknown " << message->type;
  2163. break;
  2164. }
  2165. }
  2166. }
  2167. if (disconnected)
  2168. clearData();
  2169. delete [] buffer;
  2170. m_bCaptureReady.store(true, ::std::memory_order_release);
  2171. }
  2172. void EasySocketListener::listenDescription()
  2173. {
  2174. // TODO: Merge functions listenDescription() and listenCapture()
  2175. static const int buffer_size = 8 * 1024 * 1024;
  2176. char* buffer = new char[buffer_size];
  2177. int seek = 0, bytes = 0;
  2178. bool isListen = true, disconnected = false;
  2179. while (isListen && !m_bInterrupt.load(::std::memory_order_acquire))
  2180. {
  2181. if ((bytes - seek) == 0)
  2182. {
  2183. bytes = m_easySocket.receive(buffer, buffer_size);
  2184. if (bytes == -1)
  2185. {
  2186. if (m_easySocket.isDisconnected())
  2187. {
  2188. m_bConnected.store(false, ::std::memory_order_release);
  2189. isListen = false;
  2190. disconnected = true;
  2191. }
  2192. seek = 0;
  2193. bytes = 0;
  2194. continue;
  2195. }
  2196. seek = 0;
  2197. }
  2198. if (bytes == 0)
  2199. {
  2200. isListen = false;
  2201. break;
  2202. }
  2203. char* buf = buffer + seek;
  2204. if (bytes > 0)
  2205. {
  2206. auto message = reinterpret_cast<const ::profiler::net::Message*>(buf);
  2207. if (!message->isEasyNetMessage())
  2208. continue;
  2209. switch (message->type)
  2210. {
  2211. case profiler::net::MESSAGE_TYPE_ACCEPTED_CONNECTION:
  2212. {
  2213. qInfo() << "Receive MESSAGE_TYPE_ACCEPTED_CONNECTION";
  2214. seek += sizeof(profiler::net::Message);
  2215. break;
  2216. }
  2217. case profiler::net::MESSAGE_TYPE_REPLY_BLOCKS_DESCRIPTION_END:
  2218. {
  2219. qInfo() << "Receive MESSAGE_TYPE_REPLY_BLOCKS_DESCRIPTION_END";
  2220. seek += sizeof(profiler::net::Message);
  2221. seek = 0;
  2222. bytes = 0;
  2223. isListen = false;
  2224. break;
  2225. }
  2226. case profiler::net::MESSAGE_TYPE_REPLY_BLOCKS_DESCRIPTION:
  2227. {
  2228. qInfo() << "Receive MESSAGE_TYPE_REPLY_BLOCKS";
  2229. seek += sizeof(profiler::net::DataMessage);
  2230. profiler::net::DataMessage* dm = (profiler::net::DataMessage*)message;
  2231. int neededSize = dm->size;
  2232. buf = buffer + seek;
  2233. auto bytesNumber = ::std::min((int)dm->size, bytes - seek);
  2234. m_receivedSize += bytesNumber;
  2235. m_receivedData.write(buf, bytesNumber);
  2236. neededSize -= bytesNumber;
  2237. if (neededSize == 0)
  2238. seek += bytesNumber;
  2239. else{
  2240. seek = 0;
  2241. bytes = 0;
  2242. }
  2243. int loaded = 0;
  2244. while (neededSize > 0)
  2245. {
  2246. bytes = m_easySocket.receive(buffer, buffer_size);
  2247. if (bytes == -1)
  2248. {
  2249. if (m_easySocket.isDisconnected())
  2250. {
  2251. m_bConnected.store(false, ::std::memory_order_release);
  2252. isListen = false;
  2253. disconnected = true;
  2254. neededSize = 0;
  2255. }
  2256. break;
  2257. }
  2258. buf = buffer;
  2259. int toWrite = ::std::min(bytes, neededSize);
  2260. m_receivedSize += toWrite;
  2261. m_receivedData.write(buf, toWrite);
  2262. neededSize -= toWrite;
  2263. loaded += toWrite;
  2264. seek = toWrite;
  2265. }
  2266. break;
  2267. }
  2268. default:
  2269. break;
  2270. }
  2271. }
  2272. }
  2273. if (disconnected)
  2274. clearData();
  2275. delete[] buffer;
  2276. }
  2277. void EasySocketListener::listenFrameTime()
  2278. {
  2279. // TODO: Merge functions listenDescription() and listenCapture()
  2280. static const int buffer_size = sizeof(::profiler::net::TimestampMessage) << 2;
  2281. char buffer[buffer_size] = {};
  2282. int seek = 0, bytes = 0;
  2283. bool isListen = true;
  2284. while (isListen && !m_bInterrupt.load(::std::memory_order_acquire))
  2285. {
  2286. if ((bytes - seek) == 0)
  2287. {
  2288. bytes = m_easySocket.receive(buffer, buffer_size);
  2289. if (bytes == -1)
  2290. {
  2291. if (m_easySocket.isDisconnected())
  2292. {
  2293. m_bConnected.store(false, ::std::memory_order_release);
  2294. isListen = false;
  2295. }
  2296. seek = 0;
  2297. bytes = 0;
  2298. continue;
  2299. }
  2300. seek = 0;
  2301. }
  2302. if (bytes == 0)
  2303. {
  2304. isListen = false;
  2305. break;
  2306. }
  2307. char* buf = buffer + seek;
  2308. if (bytes > 0)
  2309. {
  2310. auto message = reinterpret_cast<const ::profiler::net::Message*>(buf);
  2311. if (!message->isEasyNetMessage())
  2312. continue;
  2313. switch (message->type)
  2314. {
  2315. case profiler::net::MESSAGE_TYPE_ACCEPTED_CONNECTION:
  2316. case profiler::net::MESSAGE_TYPE_REPLY_START_CAPTURING:
  2317. {
  2318. seek += sizeof(profiler::net::Message);
  2319. break;
  2320. }
  2321. case profiler::net::MESSAGE_TYPE_REPLY_MAIN_FRAME_TIME_MAX_AVG_US:
  2322. {
  2323. //qInfo() << "Receive MESSAGE_TYPE_REPLY_MAIN_FRAME_TIME_MAX_AVG_US";
  2324. seek += sizeof(profiler::net::TimestampMessage);
  2325. if (seek <= buffer_size)
  2326. {
  2327. profiler::net::TimestampMessage* timestampMessage = (profiler::net::TimestampMessage*)message;
  2328. m_frameMax.store(timestampMessage->maxValue, ::std::memory_order_release);
  2329. m_frameAvg.store(timestampMessage->avgValue, ::std::memory_order_release);
  2330. m_bFrameTimeReady.store(true, ::std::memory_order_release);
  2331. }
  2332. isListen = false;
  2333. break;
  2334. }
  2335. default:
  2336. break;
  2337. }
  2338. }
  2339. }
  2340. }
  2341. //////////////////////////////////////////////////////////////////////////