From f5ed51e13aec75aeeb971d2d9b19799aa512ec9a Mon Sep 17 00:00:00 2001 From: Victor Zarubkin Date: Sun, 4 Sep 2016 19:35:58 +0300 Subject: [PATCH] Event tracing fixes! Now working :) --- include/profiler/profiler.h | 5 +++++ profiler_gui/blocks_graphics_view.cpp | 16 +++++++++++----- sample/main.cpp | 5 +++++ src/event_trace_win.cpp | 16 ++-------------- src/profile_manager.cpp | 5 ----- src/profile_manager.h | 8 +++++--- 6 files changed, 28 insertions(+), 27 deletions(-) diff --git a/include/profiler/profiler.h b/include/profiler/profiler.h index 416e613..d3a6eab 100644 --- a/include/profiler/profiler.h +++ b/include/profiler/profiler.h @@ -280,6 +280,7 @@ namespace profiler { public: + BaseBlockData(const BaseBlockData&) = default; BaseBlockData(timestamp_t _begin_time, block_id_t _id); inline timestamp_t begin() const { return m_begin; } @@ -288,6 +289,10 @@ namespace profiler { inline timestamp_t duration() const { return m_end - m_begin; } inline void setId(block_id_t _id) { m_id = _id; } + + private: + + BaseBlockData() = delete; }; #pragma pack(pop) diff --git a/profiler_gui/blocks_graphics_view.cpp b/profiler_gui/blocks_graphics_view.cpp index 0f31c47..f781eeb 100644 --- a/profiler_gui/blocks_graphics_view.cpp +++ b/profiler_gui/blocks_graphics_view.cpp @@ -515,7 +515,7 @@ void EasyGraphicsItem::paint(QPainter* _painter, const QStyleOptionGraphicsItem* if (!m_pRoot->sync.empty()) { _painter->setBrush(Qt::NoBrush); - QPen pen(QColor::fromRgba(0x40f08040)); + QPen pen(QColor::fromRgba(0xe0f08040)); pen.setWidth(3); _painter->setPen(pen); @@ -528,10 +528,10 @@ void EasyGraphicsItem::paint(QPainter* _painter, const QStyleOptionGraphicsItem* if (begin > sceneRight) break; // This is first totally invisible item. No need to check other items. - decltype(begin) width = item.node->duration(); + decltype(begin) width = sceneView->time2position(item.node->end()) - begin; auto r = begin + width; -// if (r < sceneLeft) // This item is not visible -// continue; + if (r < sceneLeft) // This item is not visible + continue; begin *= currentScale; begin -= dx; @@ -1424,7 +1424,13 @@ void EasyGraphicsView::setTree(const ::profiler::thread_blocks_tree_t& _blocksTr for (const auto& threadTree : _blocksTree) { const auto& tree = threadTree.second.children; - const auto timestart = blocksTree(tree.front()).node->begin(); + auto timestart = blocksTree(tree.front()).node->begin(); + +#ifdef EASY_STORE_CSWITCH_SEPARATELY + if (!threadTree.second.sync.empty()) + timestart = ::std::min(timestart, blocksTree(threadTree.second.sync.front()).node->begin()); +#endif + const auto timefinish = blocksTree(tree.back()).node->end(); if (m_beginTime > timestart) diff --git a/sample/main.cpp b/sample/main.cpp index 7ef3014..32de060 100644 --- a/sample/main.cpp +++ b/sample/main.cpp @@ -262,6 +262,11 @@ int main(int argc, char* argv[]) } cv.notify_all(); + for (int i = 0; i < RENDER_SPEPS; ++i) { + modellingStep(); + localSleep(1200000); + } + render.join(); modelling.join(); for(auto& t : threads){ diff --git a/src/event_trace_win.cpp b/src/event_trace_win.cpp index ad40b97..78c436a 100644 --- a/src/event_trace_win.cpp +++ b/src/event_trace_win.cpp @@ -3,7 +3,6 @@ #ifdef _WIN32 #include #include -#include #include "event_trace_win.h" #include "profiler/profiler.h" #include "profile_manager.h" @@ -35,8 +34,6 @@ namespace profiler { void WINAPI processTraceEvent(PEVENT_RECORD _traceEvent) { - //static ::std::ofstream outputFile("csw.csv", ::std::fstream::app); - static const decltype(_traceEvent->EventHeader.EventDescriptor.Opcode) SWITCH_CONTEXT_OPCODE = 36; if (_traceEvent->EventHeader.EventDescriptor.Opcode != SWITCH_CONTEXT_OPCODE) return; @@ -47,11 +44,6 @@ namespace profiler { auto _contextSwitchEvent = reinterpret_cast(_traceEvent->UserData); auto timestampValue = _traceEvent->EventHeader.TimeStamp.QuadPart; - - //LARGE_INTEGER currtime; - //if (QueryPerformanceCounter(&currtime)) - // timestampValue = currtime.QuadPart; - //timestampValue *= 1000000000LL; //timestampValue /= CPU_FREQUENCY; const auto time = (::profiler::timestamp_t)timestampValue; @@ -59,14 +51,10 @@ namespace profiler { static const ::profiler::StaticBlockDescriptor desc("OS.ContextSwitch", __FILE__, __LINE__, ::profiler::BLOCK_TYPE_CONTEXT_SWITCH, ::profiler::colors::White); //if (_contextSwitchEvent->OldThreadId != 0) - MANAGER._cswitchBeginBlock(time, desc.id(), _contextSwitchEvent->OldThreadId); + MANAGER._cswitchBeginBlock(time, desc.id(), _contextSwitchEvent->OldThreadId); //if (_contextSwitchEvent->NewThreadId != 0) - MANAGER._cswitchEndBlock(_contextSwitchEvent->NewThreadId, time); - - //static const auto firstTime = time; - //outputFile << _contextSwitchEvent->OldThreadId << "\t" << _contextSwitchEvent->NewThreadId << "\t" << (((time - firstTime) * 1000000000LL) / CPU_FREQUENCY) << ::std::endl; - //outputFile << _contextSwitchEvent->OldThreadId << "\t" << _contextSwitchEvent->NewThreadId << "\t" << time << ::std::endl; + MANAGER._cswitchEndBlock(_contextSwitchEvent->NewThreadId, time); } ////////////////////////////////////////////////////////////////////////// diff --git a/src/profile_manager.cpp b/src/profile_manager.cpp index e4e0a46..bc4bd9e 100644 --- a/src/profile_manager.cpp +++ b/src/profile_manager.cpp @@ -271,14 +271,10 @@ uint32_t ProfileManager::dumpBlocksToFile(const char* filename) of.write(descriptor.file(), filename_size); } - //::std::ofstream outputFile("csw2.csv", ::std::fstream::app); - for (auto& thread_storage : m_threads) { auto& t = thread_storage.second; - //outputFile << thread_storage.first << std::endl; - of.write(thread_storage.first); #ifdef STORE_CSWITCHES_SEPARATELY of.write(static_cast(t.blocks.closedList.size())); @@ -318,7 +314,6 @@ uint32_t ProfileManager::dumpBlocksToFile(const char* filename) { auto b = t.sync.closedList[i]; #endif - //outputFile << b->begin() << "\t" << b->end() << std::endl; of.writeBlock(b); } diff --git a/src/profile_manager.h b/src/profile_manager.h index 311ef19..9622910 100644 --- a/src/profile_manager.h +++ b/src/profile_manager.h @@ -76,7 +76,7 @@ public: return data; } - m_size = 0; + m_size = n; m_chunks.emplace_back(); return m_chunks.back().data; } @@ -91,6 +91,8 @@ public: ////////////////////////////////////////////////////////////////////////// +const uint16_t SIZEOF_CSWITCH = sizeof(profiler::BaseBlockData) + 1; + class ThreadStorage final { typedef std::vector serialized_list_t; @@ -114,8 +116,8 @@ class ThreadStorage final public: - BlocksList, 1024> blocks; - BlocksList sync; + BlocksList, SIZEOF_CSWITCH * (uint16_t)1024U> blocks; + BlocksList sync; bool named = false; void storeBlock(const profiler::Block& _block);