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 <stdio.h>
#include "../public/common/TracySystem.hpp"
#include "TracyTaskDispatch.hpp"
namespace tracy
{
TaskDispatch::TaskDispatch( size_t workers )
TaskDispatch::TaskDispatch( size_t workers, const char* name )
: m_exit( false )
, m_jobs( 0 )
{
@ -15,7 +16,7 @@ TaskDispatch::TaskDispatch( size_t workers )
m_workers.reserve( workers );
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
{
public:
TaskDispatch( size_t workers );
TaskDispatch( size_t workers, const char* name );
~TaskDispatch();
void Queue( const std::function<void(void)>& f );
@ -24,6 +24,7 @@ public:
private:
void Worker();
void SetName( const char* name, size_t num );
std::vector<std::function<void(void)>> m_queue;
std::mutex m_queueLock;

View File

@ -20,7 +20,7 @@ TimelineController::TimelineController( View& view, Worker& worker )
#ifdef __EMSCRIPTEN__
, m_td( 1 )
#else
, m_td( std::max( 1u, std::thread::hardware_concurrency() - 2 ) )
, m_td( std::max( 1u, std::thread::hardware_concurrency() - 2 ), "Render" )
#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)
const auto jobs = std::max<int>( std::thread::hardware_concurrency() - 2, 2 );
#endif
auto td = std::make_unique<TaskDispatch>( jobs );
auto td = std::make_unique<TaskDispatch>( jobs, "FrImg Zstd" );
auto data = std::make_unique<JobData[]>( jobs );
for( uint64_t i=0; i<sz; i++ )