0
0
mirror of https://github.com/yse/easy_profiler.git synced 2024-12-26 08:01:51 +08:00

Event tracing fixes! Now working :)

This commit is contained in:
Victor Zarubkin 2016-09-04 19:35:58 +03:00
parent 05b56dcec0
commit f5ed51e13a
6 changed files with 28 additions and 27 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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){

View File

@ -3,7 +3,6 @@
#ifdef _WIN32
#include <memory.h>
#include <chrono>
#include <fstream>
#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<CSwitch*>(_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);
}
//////////////////////////////////////////////////////////////////////////

View File

@ -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<uint32_t>(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);
}

View File

@ -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<profiler::SerializedBlock*> serialized_list_t;
@ -114,8 +116,8 @@ class ThreadStorage final
public:
BlocksList<std::reference_wrapper<profiler::Block>, 1024> blocks;
BlocksList<profiler::Block, 1024> sync;
BlocksList<std::reference_wrapper<profiler::Block>, SIZEOF_CSWITCH * (uint16_t)1024U> blocks;
BlocksList<profiler::Block, SIZEOF_CSWITCH * (uint16_t)128U> sync;
bool named = false;
void storeBlock(const profiler::Block& _block);