Name worker threads.

This commit is contained in:
Bartosz Taudul 2023-03-25 22:14:34 +01:00
parent 5eebc5d7cf
commit 33a640f848
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3
4 changed files with 14 additions and 5 deletions

View File

@ -1,12 +1,13 @@
#include <assert.h> #include <assert.h>
#include <stdio.h> #include <stdio.h>
#include "../public/common/TracySystem.hpp"
#include "TracyTaskDispatch.hpp" #include "TracyTaskDispatch.hpp"
namespace tracy namespace tracy
{ {
TaskDispatch::TaskDispatch( size_t workers ) TaskDispatch::TaskDispatch( size_t workers, const char* name )
: m_exit( false ) : m_exit( false )
, m_jobs( 0 ) , m_jobs( 0 )
{ {
@ -15,7 +16,7 @@ TaskDispatch::TaskDispatch( size_t workers )
m_workers.reserve( workers ); m_workers.reserve( workers );
for( size_t i=0; i<workers; i++ ) for( size_t i=0; i<workers; i++ )
{ {
m_workers.emplace_back( std::thread( [this]{ Worker(); } ) ); m_workers.emplace_back( std::thread( [this, name, i]{ SetName( name, i ); Worker(); } ) );
} }
} }
@ -79,4 +80,11 @@ void TaskDispatch::Worker()
} }
} }
void TaskDispatch::SetName( const char* name, size_t num )
{
char tmp[128];
snprintf( tmp, sizeof( tmp ), "%s #%zu", name, num );
SetThreadName( tmp );
}
} }

View File

@ -14,7 +14,7 @@ namespace tracy
class TaskDispatch class TaskDispatch
{ {
public: public:
TaskDispatch( size_t workers ); TaskDispatch( size_t workers, const char* name );
~TaskDispatch(); ~TaskDispatch();
void Queue( const std::function<void(void)>& f ); void Queue( const std::function<void(void)>& f );
@ -24,6 +24,7 @@ public:
private: private:
void Worker(); void Worker();
void SetName( const char* name, size_t num );
std::vector<std::function<void(void)>> m_queue; std::vector<std::function<void(void)>> m_queue;
std::mutex m_queueLock; std::mutex m_queueLock;

View File

@ -20,7 +20,7 @@ TimelineController::TimelineController( View& view, Worker& worker )
#ifdef __EMSCRIPTEN__ #ifdef __EMSCRIPTEN__
, m_td( 1 ) , m_td( 1 )
#else #else
, m_td( std::max( 1u, std::thread::hardware_concurrency() - 2 ) ) , m_td( std::max( 1u, std::thread::hardware_concurrency() - 2 ), "Render" )
#endif #endif
{ {
} }

View File

@ -1287,7 +1287,7 @@ Worker::Worker( FileRead& f, EventType::Type eventMask, bool bgTasks )
// Minimum 2 threads to have at least two buffers (one in use, second one filling up) // Minimum 2 threads to have at least two buffers (one in use, second one filling up)
const auto jobs = std::max<int>( std::thread::hardware_concurrency() - 2, 2 ); const auto jobs = std::max<int>( std::thread::hardware_concurrency() - 2, 2 );
#endif #endif
auto td = std::make_unique<TaskDispatch>( jobs ); auto td = std::make_unique<TaskDispatch>( jobs, "FrImg Zstd" );
auto data = std::make_unique<JobData[]>( jobs ); auto data = std::make_unique<JobData[]>( jobs );
for( uint64_t i=0; i<sz; i++ ) for( uint64_t i=0; i<sz; i++ )