Added thread names

This commit is contained in:
ezratl 2020-01-09 15:24:09 -05:00
parent f840961418
commit a1131f7b02
12 changed files with 125 additions and 12 deletions

View File

@ -12,10 +12,13 @@
#include "ScannerSM.h"
#include "ListGenerator.h"
#include "loguru.hpp"
#include "threadname.h"
#define DELAY_TIMEOUT 2.0
#define SCANNER_THREAD_NAME "Scanner"
using namespace piscan;
ScannerSM::ScannerSM(MessageReceiver& central, SystemList& dataSource) :
@ -81,7 +84,7 @@ void ScannerSM::manualEntry(uint32_t* freq){
}
void ScannerSM::ST_Load(EventData* data){
loguru::set_thread_name("Scanner");
setThreadName(SCANNER_THREAD_NAME);
DLOG_F(9, "ST_Load");
_systems.populateFromFile();
LOG_F(INFO, "Loaded %u systems", _systems.size());

76
src/core/threadname.h Normal file
View File

@ -0,0 +1,76 @@
/* cross platform thread naming, copied from this stackoverflow thread:
https://stackoverflow.com/questions/10121560/stdthread-naming-your-thread
*/
#pragma once
#include <thread>
#include <loguru.hpp>
#ifdef _WIN32
#include <windows.h>
const DWORD MS_VC_EXCEPTION=0x406D1388;
#pragma pack(push,8)
typedef struct tagTHREADNAME_INFO
{
DWORD dwType; // Must be 0x1000.
LPCSTR szName; // Pointer to name (in user addr space).
DWORD dwThreadID; // Thread ID (-1=caller thread).
DWORD dwFlags; // Reserved for future use, must be zero.
} THREADNAME_INFO;
#pragma pack(pop)
inline void _SetThreadName(uint32_t dwThreadID, const char* threadName)
{
// DWORD dwThreadID = ::GetThreadId( static_cast<HANDLE>( t.native_handle() ) );
THREADNAME_INFO info;
info.dwType = 0x1000;
info.szName = threadName;
info.dwThreadID = dwThreadID;
info.dwFlags = 0;
__try
{
RaiseException( MS_VC_EXCEPTION, 0, sizeof(info)/sizeof(ULONG_PTR), (ULONG_PTR*)&info );
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
}
}
inline void _SetThreadName( const char* threadName)
{
_SetThreadName(GetCurrentThreadId(),threadName);
}
inline void _SetThreadName( std::thread* thread, const char* threadName)
{
DWORD threadId = ::GetThreadId( static_cast<HANDLE>( thread->native_handle() ) );
_SetThreadName(threadId,threadName);
}
#else
inline void _SetThreadName(std::thread* thread, const char* threadName)
{
auto handle = thread->native_handle();
pthread_setname_np(handle,threadName);
}
#include <sys/prctl.h>
inline void _SetThreadName( const char* threadName)
{
prctl(PR_SET_NAME,threadName,0,0,0);
}
#endif
/* convenience func to integrate with loguru */
inline void setThreadName(const char* name){
loguru::set_thread_name(name);
_SetThreadName(name);
}

View File

@ -12,6 +12,9 @@
#include <mutex>
#include "loguru.hpp"
#include "threadname.h"
#define AUDIO_THREAD_NAME "Audio"
//50 ms
#define HEARTBEAT_CHECK_PERIOD_MICROS (50 * 1000)
@ -499,7 +502,7 @@ void AudioThread::run() {
#endif
// std::cout << "Audio thread initializing.." << std::endl;
loguru::set_thread_name("Audio Thread");
setThreadName(AUDIO_THREAD_NAME);
LOG_F(INFO, "Audio thread initializing");
if (dac.getDeviceCount() < 1) {

View File

@ -13,6 +13,9 @@
#include "DemodulatorInstance.h"
#include "loguru.hpp"
#include "threadname.h"
#define DMDPRE_THREAD_NAME "Demod Pre Proc"
//50 ms
#define HEARTBEAT_CHECK_PERIOD_MICROS (50 * 1000)
@ -64,7 +67,7 @@ void DemodulatorPreThread::run() {
#endif
//std::cout << "Demodulator preprocessor thread started.." << std::endl;
loguru::set_thread_name("Demod Pre");
setThreadName(DMDPRE_THREAD_NAME);
LOG_F(INFO, "Demodulator prepocessing thread started");
ReBuffer<DemodulatorThreadPostIQData> buffers("DemodulatorPreThreadBuffers");

View File

@ -20,6 +20,9 @@
#endif
#include "loguru.hpp"
#include "threadname.h"
#define DEMOD_THREAD_NAME (std::string("Demod - " + demodInstance->getLabel()).c_str())
DemodulatorInstance* DemodulatorThread::squelchLock(nullptr);
std::mutex DemodulatorThread::squelchLockMutex;
@ -82,7 +85,7 @@ void DemodulatorThread::run() {
#endif
// std::cout << "Demodulator thread started.." << std::endl;
loguru::set_thread_name(std::string("Demod - " + demodInstance->getLabel()).c_str());
setThreadName(DEMOD_THREAD_NAME);
LOG_F(INFO, "Demodulator thread started");
iqInputQueue = std::static_pointer_cast<DemodulatorThreadPostInputQueue>(getInputQueue("IQDataInput"));

View File

@ -7,6 +7,9 @@
#include <vector>
#include "loguru.hpp"
#include "threadname.h"
#define DMDWORK_THREAD_NAME "Demod Worker"
//50 ms
#define HEARTBEAT_CHECK_PERIOD_MICROS (50 * 1000)
@ -21,7 +24,7 @@ DemodulatorWorkerThread::~DemodulatorWorkerThread() {
void DemodulatorWorkerThread::run() {
// std::cout << "Demodulator worker thread started.." << std::endl;
loguru::set_thread_name("Demod WorkerThread");
setThreadName(DMDWORK_THREAD_NAME);
LOG_F(INFO, "Demodulator worker thread started");
commandQueue = std::static_pointer_cast<DemodulatorThreadWorkerCommandQueue>(getInputQueue("WorkerCommandQueue"));

View File

@ -12,6 +12,9 @@
#endif
#include "loguru.hpp"
#include "threadname.h"
#define SDRENUM_THREAD_NAME "SDR Enumerator"
std::vector<std::string> SDREnumerator::factories;
@ -322,7 +325,7 @@ std::vector<SDRDeviceInfo *> *SDREnumerator::enumerate_devices(std::string remot
void SDREnumerator::run() {
//std::cout << "SDR enumerator starting." << std::endl;
loguru::set_thread_name("SDR Enumerator");
setThreadName(SDRENUM_THREAD_NAME);
LOG_F(1, "SDR enumerator starting");

View File

@ -10,6 +10,9 @@
#include <memory>
#include "loguru.hpp"
#include "threadname.h"
#define SDRPOST_THREAD_NAME "SDR Post Proc"
//50 ms
#define HEARTBEAT_CHECK_PERIOD_MICROS (50 * 1000)
@ -163,7 +166,7 @@ void SDRPostThread::run() {
#endif
//std::cout << "SDR post-processing thread started.." << std::endl;
loguru::set_thread_name("SDR Post Thread");
setThreadName(SDRPOST_THREAD_NAME);
LOG_F(INFO, "SDR Post-processing thread started");
iqDataInQueue = std::static_pointer_cast<SDRThreadIQDataQueue>(getInputQueue("IQDataInput"));
@ -415,6 +418,7 @@ void SDRPostThread::runDemodChannels(int channelBandwidth) {
void SDRPostThread::initPFBCH() {
// std::cout << "Initializing post-process FIR polyphase filterbank channelizer with " << numChannels << " channels." << std::endl;
LOG_F(1, "Initializing post-process FIR polyphase filterbank channelizer with %i channels.", numChannels);
if (channelizer) {
firpfbch_crcf_destroy(channelizer);
}
@ -426,6 +430,7 @@ void SDRPostThread::initPFBCH() {
demodChannelActive.resize(numChannels+1);
// std::cout << "Channel bandwidth spacing: " << (chanBw) << std::endl;
LOG_F(1, "Channel bandwidth spacing: %lli", chanBw);
}
void SDRPostThread::runPFBCH(SDRThreadIQData *data_in) {
@ -472,6 +477,7 @@ void SDRPostThread::runPFBCH(SDRThreadIQData *data_in) {
void SDRPostThread::initPFBCH2() {
// std::cout << "Initializing post-process FIR polyphase filterbank channelizer with " << numChannels << " channels." << std::endl;
LOG_F(1, "Initializing post-process FIR polyphase filterbank channelizer 2 with %i channels.", numChannels);
if (channelizer2) {
firpfbch2_crcf_destroy(channelizer2);
}
@ -482,6 +488,7 @@ void SDRPostThread::initPFBCH2() {
chanCenters.resize(numChannels+1);
demodChannelActive.resize(numChannels+1);
// std::cout << "Channel bandwidth spacing: " << (chanBw) << std::endl;
LOG_F(1, "Channel bandwidth spacing: %lli", chanBw);
}
void SDRPostThread::runPFBCH2(SDRThreadIQData *data_in) {

View File

@ -11,6 +11,9 @@
#include <chrono>
#include "loguru.hpp"
#include "threadname.h"
#define SDR_THREAD_NAME "SDR Interface"
#define TARGET_DISPLAY_FPS 60
@ -592,7 +595,7 @@ void SDRThread::run() {
//#endif
//std::cout << "SDR thread starting." << std::endl;
loguru::set_thread_name("SDR Thread");
setThreadName(SDR_THREAD_NAME);
LOG_F(INFO, "SDR Thread starting");
SDRDeviceInfo *activeDev = deviceInfo.load();

View File

@ -16,6 +16,7 @@
#include "ServerManager.h"
#include "ScannerSM.h"
#include "SystemList.h"
#include "threadname.h"
//enum {
// SYSTEM_CONTROL,
@ -26,6 +27,8 @@
// CLIENT,
//};
#define IO_THREAD_NAME "IO Service"
#define SCANNER_FLAG 0x01
#define CONNMGR_FLAG 0x02
#define DEMOD_FLAG 0x04
@ -79,7 +82,7 @@ private:
MessageReceiver* _receivers[MESSAGE_RECEIVERS];
void _handlerThreadFunc(void){
loguru::set_thread_name("MessageManager");
setThreadName("MessageManager");
LOG_F(2, "MessageManager started");
while(_run){
@ -314,7 +317,7 @@ void setDemodulator(DemodInterface* demod) {
}
void runIO(){
loguru::set_thread_name("IO Service");
setThreadName(IO_THREAD_NAME);
DLOG_F(2, "Starting IO service");
io_service.run();
}

View File

@ -13,6 +13,9 @@
#include "constants.h"
#include "DebugServer.h"
#include "loguru.hpp"
#include "threadname.h"
#define DS_THREAD_NAME "DebugConsole"
using namespace piscan;
@ -36,7 +39,7 @@ void DebugConsole::giveMessage(std::shared_ptr<Message> message){
}
void DebugConsole::_consoleInputFunc() {
loguru::set_thread_name("DebugConsole");
setThreadName(DS_THREAD_NAME);
std::string input = "";
std::vector<std::string> tokens(5);

View File

@ -13,10 +13,13 @@
#include "loguru.hpp"
#include "DebugServer.h"
#include "SocketServer.h"
#include "threadname.h"
#define QUEUE_SIZE 64
#define SM_THREAD_NAME "ServerManager"
using namespace piscan;
static ConnectionLevel const permissionMap[] = {
@ -87,7 +90,7 @@ void ServerManager::disconnectClients(){
}
void ServerManager::_queueThreadFunc(void){
loguru::set_thread_name("ServerManager");
setThreadName(SM_THREAD_NAME);
while(_run){
std::unique_lock<std::mutex> lock(_msgMutex);