0
0
mirror of https://github.com/yse/easy_profiler.git synced 2024-12-27 08:41:02 +08:00

Merge branch 'develop' of github.com:yse/easy_profiler into develop

This commit is contained in:
Sergey Yagovtsev 2016-12-02 00:09:31 +03:00
commit f4d4cbecfa
4 changed files with 75 additions and 30 deletions

View File

@ -556,7 +556,7 @@ namespace profiler {
*/
PROFILER_API const char* getContextSwitchLogFilename();
PROFILER_API void startListen(uint16_t _port = profiler::DEFAULT_PORT);
PROFILER_API void startListen(uint16_t _port = ::profiler::DEFAULT_PORT);
PROFILER_API void stopListen();
/** Returns current major version.
@ -604,7 +604,7 @@ namespace profiler {
inline void setLowPriorityEventTracing(bool) { }
inline void setContextSwitchLogFilename(const char*) { }
inline const char* getContextSwitchLogFilename() { return ""; }
inline void startListen(uint16_t _port = profiler::DEFAULT_PORT) { }
inline void startListen(uint16_t = ::profiler::DEFAULT_PORT) { }
inline void stopListen() { }
inline uint8_t versionMajor() { return 0; }
inline uint8_t versionMinor() { return 0; }

View File

@ -1317,36 +1317,81 @@ void EasyGraphicsView::onIdleTimeout()
auto name = *itemBlock.node->name() != 0 ? itemBlock.node->name() : itemDesc.name();
auto widget = new QWidget();
auto lay = new QFormLayout(widget);
lay->setLabelAlignment(Qt::AlignRight);
auto lay = new QGridLayout(widget);
if (itemDesc.type() == ::profiler::BLOCK_TYPE_BLOCK)
{
lay->addRow("Block:", new QLabel(name));
lay->addRow("Duration:", new QLabel(::profiler_gui::timeStringRealNs(EASY_GLOBALS.time_units, itemBlock.node->duration(), 3)));
lay->addWidget(new QLabel("Block:", widget), 0, 0, Qt::AlignRight);
lay->addWidget(new QLabel(name, widget), 0, 1, 1, 3, Qt::AlignLeft);
lay->addWidget(new QLabel("Duration:", widget), 1, 0, Qt::AlignRight);
lay->addWidget(new QLabel(::profiler_gui::timeStringRealNs(EASY_GLOBALS.time_units, itemBlock.node->duration(), 3), widget), 1, 1, 1, 3, Qt::AlignLeft);
}
else
{
lay->addRow("Event:", new QLabel(name));
lay->addWidget(new QLabel("Event:", widget), 0, 0, Qt::AlignRight);
lay->addWidget(new QLabel(name, widget), 0, 1, Qt::AlignLeft);
}
if (itemBlock.per_thread_stats)
{
lay->addRow("N/Thread:", new QLabel(QString::number(itemBlock.per_thread_stats->calls_number)));
if (itemDesc.type() == ::profiler::BLOCK_TYPE_BLOCK)
{
lay->addRow("%/Thread:", new QLabel(QString::number(::profiler_gui::percent(itemBlock.per_thread_stats->total_duration, item->root()->active_time))));
if (itemBlock.per_parent_stats->parent_block == item->threadId())
const auto duration = itemBlock.node->duration();
lay->addWidget(new QLabel("%", widget), 2, 1, Qt::AlignHCenter);
lay->addWidget(new QLabel("%/N", widget), 2, 2, Qt::AlignHCenter);
lay->addWidget(new QLabel("N", widget), 2, 3, Qt::AlignHCenter);
lay->addWidget(new QLabel("Thread:", widget), 3, 0, Qt::AlignRight);
auto percent = ::profiler_gui::percentReal(duration, item->root()->active_time);
lay->addWidget(new QLabel(0.005 < percent && percent < 0.5001 ? QString::number(percent, 'f', 2) : QString::number(static_cast<int>(0.5 + percent)), widget), 3, 1, Qt::AlignHCenter);
lay->addWidget(new QLabel(QString::number(::profiler_gui::percent(itemBlock.per_thread_stats->total_duration, item->root()->active_time)), widget), 3, 2, Qt::AlignHCenter);
lay->addWidget(new QLabel(QString::number(itemBlock.per_thread_stats->calls_number), widget), 3, 3, Qt::AlignHCenter);
int r = 3;
if (itemBlock.per_frame_stats->parent_block != i)
{
auto percent = ::profiler_gui::percentReal(itemBlock.node->duration(), item->root()->active_time);
lay->addRow("%:", new QLabel(percent < 0.5001 ? QString::number(percent, 'f', 2) : QString::number(static_cast<int>(0.5 + percent))));
++r;
auto frame_duration = blocksTree(itemBlock.per_frame_stats->parent_block).node->duration();
lay->addWidget(new QLabel("Frame:", widget), r, 0, Qt::AlignRight);
percent = ::profiler_gui::percentReal(duration, frame_duration);
lay->addWidget(new QLabel(0.005 < percent && percent < 0.5001 ? QString::number(percent, 'f', 2) : QString::number(static_cast<int>(0.5 + percent)), widget), r, 1, Qt::AlignHCenter);
percent = ::profiler_gui::percentReal(itemBlock.per_frame_stats->total_duration, frame_duration);
lay->addWidget(new QLabel(0.005 < percent && percent < 0.5001 ? QString::number(percent, 'f', 2) : QString::number(static_cast<int>(0.5 + percent)), widget), r, 2, Qt::AlignHCenter);
lay->addWidget(new QLabel(QString::number(itemBlock.per_frame_stats->calls_number), widget), r, 3, Qt::AlignHCenter);
}
else
if (itemBlock.per_parent_stats->parent_block != item->threadId())
{
auto percent = ::profiler_gui::percentReal(itemBlock.node->duration(), blocksTree(itemBlock.per_parent_stats->parent_block).node->duration());
lay->addRow("%:", new QLabel(percent < 0.5001 ? QString::number(percent, 'f', 2) : QString::number(static_cast<int>(0.5 + percent))));
++r;
auto parent_duration = blocksTree(itemBlock.per_parent_stats->parent_block).node->duration();
lay->addWidget(new QLabel("Parent:", widget), r, 0, Qt::AlignRight);
percent = ::profiler_gui::percentReal(duration, parent_duration);
lay->addWidget(new QLabel(0.005 < percent && percent < 0.5001 ? QString::number(percent, 'f', 2) : QString::number(static_cast<int>(0.5 + percent)), widget), r, 1, Qt::AlignHCenter);
percent = ::profiler_gui::percentReal(itemBlock.per_parent_stats->total_duration, parent_duration);
lay->addWidget(new QLabel(0.005 < percent && percent < 0.5001 ? QString::number(percent, 'f', 2) : QString::number(static_cast<int>(0.5 + percent)), widget), r, 2, Qt::AlignHCenter);
lay->addWidget(new QLabel(QString::number(itemBlock.per_parent_stats->calls_number), widget), r, 3, Qt::AlignHCenter);
++r;
}
}
else
{
lay->addWidget(new QLabel("N/Thread:", widget), 1, 0, Qt::AlignRight);
lay->addWidget(new QLabel(QString::number(itemBlock.per_thread_stats->calls_number), widget), 1, 1, Qt::AlignLeft);
}
}
m_csInfoWidget = new QGraphicsProxyWidget();
@ -1388,7 +1433,7 @@ void EasyGraphicsView::onIdleTimeout()
scenePos.setX(scenePos.x() - br.width());
m_csInfoWidget->setPos(scenePos);
m_csInfoWidget->setOpacity(0.85);
m_csInfoWidget->setOpacity(0.9);
}
}
else if (m_csInfoWidget != nullptr)

View File

@ -175,12 +175,12 @@ extern "C" {
PROFILER_API void startListen(uint16_t _port)
{
return MANAGER.startListenSignalToCapture(_port);
return MANAGER.startListen(_port);
}
PROFILER_API void stopListen()
{
return MANAGER.stopListenSignalToCapture();
return MANAGER.stopListen();
}
#else
PROFILER_API const BaseBlockDescriptor* registerDescription(EasyBlockStatus, const char*, const char*, const char*, int, block_type_t, color_t) { return reinterpret_cast<const BaseBlockDescriptor*>(0xbad); }
@ -195,8 +195,8 @@ extern "C" {
PROFILER_API void setLowPriorityEventTracing(bool) { }
PROFILER_API void setContextSwitchLogFilename(const char*) { }
PROFILER_API const char* getContextSwitchLogFilename() { return ""; }
PROFILER_API void startListenSignalToCapture() { }
PROFILER_API void stopListenSignalToCapture() { }
PROFILER_API void startListen(uint16_t) { }
PROFILER_API void stopListen() { }
#endif
PROFILER_API uint8_t versionMajor()
@ -396,13 +396,14 @@ ProfileManager::ProfileManager()
{
m_isEnabled = ATOMIC_VAR_INIT(false);
m_isEventTracingEnabled = ATOMIC_VAR_INIT(EASY_EVENT_TRACING_ENABLED);
m_isAlreadyListening = ATOMIC_VAR_INIT(false);
m_stopListen = ATOMIC_VAR_INIT(false);
}
ProfileManager::~ProfileManager()
{
#ifndef EASY_PROFILER_API_DISABLED
stopListenSignalToCapture();
stopListen();
#endif
for (auto desc : m_descriptors)
@ -909,22 +910,21 @@ void ProfileManager::setBlockStatus(block_id_t _id, EasyBlockStatus _status)
}
}
void ProfileManager::startListenSignalToCapture(uint16_t _port)
void ProfileManager::startListen(uint16_t _port)
{
if (!m_isAlreadyListened)
if (!m_isAlreadyListening.exchange(true, std::memory_order_release))
{
m_stopListen.store(false, std::memory_order_release);
m_listenThread = std::move(std::thread(&ProfileManager::listen, this, _port));
m_isAlreadyListened = true;
}
}
void ProfileManager::stopListenSignalToCapture()
void ProfileManager::stopListen()
{
m_stopListen.store(true, std::memory_order_release);
if (m_listenThread.joinable())
m_listenThread.join();
m_isAlreadyListened = false;
m_isAlreadyListening.store(false, std::memory_order_release);
}
//////////////////////////////////////////////////////////////////////////

View File

@ -360,6 +360,7 @@ class ProfileManager
profiler::spin_lock m_storedSpin;
std::atomic_bool m_isEnabled;
std::atomic_bool m_isEventTracingEnabled;
std::atomic_bool m_isAlreadyListening;
std::string m_csInfoFilename = "/tmp/cs_profiling_info.log";
@ -367,7 +368,6 @@ class ProfileManager
void setBlockStatus(profiler::block_id_t _id, profiler::EasyBlockStatus _status);
std::thread m_listenThread;
bool m_isAlreadyListened = false;
void listen(uint16_t _port);
int m_socket = 0;//TODO crossplatform
@ -409,8 +409,8 @@ public:
void beginContextSwitch(profiler::thread_id_t _thread_id, profiler::timestamp_t _time, profiler::thread_id_t _target_thread_id, const char* _target_process, bool _lockSpin = true);
void storeContextSwitch(profiler::thread_id_t _thread_id, profiler::timestamp_t _time, profiler::thread_id_t _target_thread_id, bool _lockSpin = true);
void endContextSwitch(profiler::thread_id_t _thread_id, profiler::timestamp_t _endtime, bool _lockSpin = true);
void startListenSignalToCapture(uint16_t _port);
void stopListenSignalToCapture();
void startListen(uint16_t _port);
void stopListen();
private: