mirror of
https://github.com/yse/easy_profiler.git
synced 2024-12-28 01:04:41 +08:00
Merge branch 'develop' of github.com:yse/easy_profiler into develop
This commit is contained in:
commit
f4d4cbecfa
@ -556,7 +556,7 @@ namespace profiler {
|
|||||||
*/
|
*/
|
||||||
PROFILER_API const char* getContextSwitchLogFilename();
|
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();
|
PROFILER_API void stopListen();
|
||||||
|
|
||||||
/** Returns current major version.
|
/** Returns current major version.
|
||||||
@ -604,7 +604,7 @@ namespace profiler {
|
|||||||
inline void setLowPriorityEventTracing(bool) { }
|
inline void setLowPriorityEventTracing(bool) { }
|
||||||
inline void setContextSwitchLogFilename(const char*) { }
|
inline void setContextSwitchLogFilename(const char*) { }
|
||||||
inline const char* getContextSwitchLogFilename() { return ""; }
|
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 void stopListen() { }
|
||||||
inline uint8_t versionMajor() { return 0; }
|
inline uint8_t versionMajor() { return 0; }
|
||||||
inline uint8_t versionMinor() { return 0; }
|
inline uint8_t versionMinor() { return 0; }
|
||||||
|
@ -1317,36 +1317,81 @@ void EasyGraphicsView::onIdleTimeout()
|
|||||||
auto name = *itemBlock.node->name() != 0 ? itemBlock.node->name() : itemDesc.name();
|
auto name = *itemBlock.node->name() != 0 ? itemBlock.node->name() : itemDesc.name();
|
||||||
|
|
||||||
auto widget = new QWidget();
|
auto widget = new QWidget();
|
||||||
auto lay = new QFormLayout(widget);
|
auto lay = new QGridLayout(widget);
|
||||||
lay->setLabelAlignment(Qt::AlignRight);
|
|
||||||
if (itemDesc.type() == ::profiler::BLOCK_TYPE_BLOCK)
|
if (itemDesc.type() == ::profiler::BLOCK_TYPE_BLOCK)
|
||||||
{
|
{
|
||||||
lay->addRow("Block:", new QLabel(name));
|
lay->addWidget(new QLabel("Block:", widget), 0, 0, Qt::AlignRight);
|
||||||
lay->addRow("Duration:", new QLabel(::profiler_gui::timeStringRealNs(EASY_GLOBALS.time_units, itemBlock.node->duration(), 3)));
|
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
|
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)
|
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)
|
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))));
|
const auto duration = itemBlock.node->duration();
|
||||||
if (itemBlock.per_parent_stats->parent_block == item->threadId())
|
|
||||||
|
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);
|
++r;
|
||||||
lay->addRow("%:", new QLabel(percent < 0.5001 ? QString::number(percent, 'f', 2) : QString::number(static_cast<int>(0.5 + percent))));
|
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());
|
++r;
|
||||||
lay->addRow("%:", new QLabel(percent < 0.5001 ? QString::number(percent, 'f', 2) : QString::number(static_cast<int>(0.5 + percent))));
|
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();
|
m_csInfoWidget = new QGraphicsProxyWidget();
|
||||||
@ -1388,7 +1433,7 @@ void EasyGraphicsView::onIdleTimeout()
|
|||||||
scenePos.setX(scenePos.x() - br.width());
|
scenePos.setX(scenePos.x() - br.width());
|
||||||
|
|
||||||
m_csInfoWidget->setPos(scenePos);
|
m_csInfoWidget->setPos(scenePos);
|
||||||
m_csInfoWidget->setOpacity(0.85);
|
m_csInfoWidget->setOpacity(0.9);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (m_csInfoWidget != nullptr)
|
else if (m_csInfoWidget != nullptr)
|
||||||
|
@ -175,12 +175,12 @@ extern "C" {
|
|||||||
|
|
||||||
PROFILER_API void startListen(uint16_t _port)
|
PROFILER_API void startListen(uint16_t _port)
|
||||||
{
|
{
|
||||||
return MANAGER.startListenSignalToCapture(_port);
|
return MANAGER.startListen(_port);
|
||||||
}
|
}
|
||||||
|
|
||||||
PROFILER_API void stopListen()
|
PROFILER_API void stopListen()
|
||||||
{
|
{
|
||||||
return MANAGER.stopListenSignalToCapture();
|
return MANAGER.stopListen();
|
||||||
}
|
}
|
||||||
#else
|
#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); }
|
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 setLowPriorityEventTracing(bool) { }
|
||||||
PROFILER_API void setContextSwitchLogFilename(const char*) { }
|
PROFILER_API void setContextSwitchLogFilename(const char*) { }
|
||||||
PROFILER_API const char* getContextSwitchLogFilename() { return ""; }
|
PROFILER_API const char* getContextSwitchLogFilename() { return ""; }
|
||||||
PROFILER_API void startListenSignalToCapture() { }
|
PROFILER_API void startListen(uint16_t) { }
|
||||||
PROFILER_API void stopListenSignalToCapture() { }
|
PROFILER_API void stopListen() { }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
PROFILER_API uint8_t versionMajor()
|
PROFILER_API uint8_t versionMajor()
|
||||||
@ -396,13 +396,14 @@ ProfileManager::ProfileManager()
|
|||||||
{
|
{
|
||||||
m_isEnabled = ATOMIC_VAR_INIT(false);
|
m_isEnabled = ATOMIC_VAR_INIT(false);
|
||||||
m_isEventTracingEnabled = ATOMIC_VAR_INIT(EASY_EVENT_TRACING_ENABLED);
|
m_isEventTracingEnabled = ATOMIC_VAR_INIT(EASY_EVENT_TRACING_ENABLED);
|
||||||
|
m_isAlreadyListening = ATOMIC_VAR_INIT(false);
|
||||||
m_stopListen = ATOMIC_VAR_INIT(false);
|
m_stopListen = ATOMIC_VAR_INIT(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
ProfileManager::~ProfileManager()
|
ProfileManager::~ProfileManager()
|
||||||
{
|
{
|
||||||
#ifndef EASY_PROFILER_API_DISABLED
|
#ifndef EASY_PROFILER_API_DISABLED
|
||||||
stopListenSignalToCapture();
|
stopListen();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (auto desc : m_descriptors)
|
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_stopListen.store(false, std::memory_order_release);
|
||||||
m_listenThread = std::move(std::thread(&ProfileManager::listen, this, _port));
|
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);
|
m_stopListen.store(true, std::memory_order_release);
|
||||||
if (m_listenThread.joinable())
|
if (m_listenThread.joinable())
|
||||||
m_listenThread.join();
|
m_listenThread.join();
|
||||||
m_isAlreadyListened = false;
|
m_isAlreadyListening.store(false, std::memory_order_release);
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -360,6 +360,7 @@ class ProfileManager
|
|||||||
profiler::spin_lock m_storedSpin;
|
profiler::spin_lock m_storedSpin;
|
||||||
std::atomic_bool m_isEnabled;
|
std::atomic_bool m_isEnabled;
|
||||||
std::atomic_bool m_isEventTracingEnabled;
|
std::atomic_bool m_isEventTracingEnabled;
|
||||||
|
std::atomic_bool m_isAlreadyListening;
|
||||||
|
|
||||||
std::string m_csInfoFilename = "/tmp/cs_profiling_info.log";
|
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);
|
void setBlockStatus(profiler::block_id_t _id, profiler::EasyBlockStatus _status);
|
||||||
|
|
||||||
std::thread m_listenThread;
|
std::thread m_listenThread;
|
||||||
bool m_isAlreadyListened = false;
|
|
||||||
void listen(uint16_t _port);
|
void listen(uint16_t _port);
|
||||||
|
|
||||||
int m_socket = 0;//TODO crossplatform
|
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 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 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 endContextSwitch(profiler::thread_id_t _thread_id, profiler::timestamp_t _endtime, bool _lockSpin = true);
|
||||||
void startListenSignalToCapture(uint16_t _port);
|
void startListen(uint16_t _port);
|
||||||
void stopListenSignalToCapture();
|
void stopListen();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user