Added printThreadId option in ULogger

This commit is contained in:
matlabbe
2016-01-05 13:55:21 -05:00
parent bf2bd3fe50
commit 97dd9bb7d5
8 changed files with 73 additions and 15 deletions
@@ -132,6 +132,7 @@ public:
int getGeneralLoggerPauseLevel() const; int getGeneralLoggerPauseLevel() const;
int getGeneralLoggerType() const; int getGeneralLoggerType() const;
bool getGeneralLoggerPrintTime() const; bool getGeneralLoggerPrintTime() const;
bool getGeneralLoggerPrintThreadId() const;
bool isVerticalLayoutUsed() const; bool isVerticalLayoutUsed() const;
bool imageRejectedShown() const; bool imageRejectedShown() const;
bool imageHighestHypShown() const; bool imageHighestHypShown() const;
+1
View File
@@ -2418,6 +2418,7 @@ void MainWindow::applyPrefSettings(PreferencesDialog::PANEL_FLAGS flags)
ULogger::setType((ULogger::Type)_preferencesDialog->getGeneralLoggerType(), ULogger::setType((ULogger::Type)_preferencesDialog->getGeneralLoggerType(),
(_preferencesDialog->getWorkingDirectory()+QDir::separator()+LOG_FILE_NAME).toStdString(), true); (_preferencesDialog->getWorkingDirectory()+QDir::separator()+LOG_FILE_NAME).toStdString(), true);
ULogger::setPrintTime(_preferencesDialog->getGeneralLoggerPrintTime()); ULogger::setPrintTime(_preferencesDialog->getGeneralLoggerPrintTime());
ULogger::setPrintThreadId(_preferencesDialog->getGeneralLoggerPrintThreadId());
} }
} }
+8
View File
@@ -329,6 +329,7 @@ PreferencesDialog::PreferencesDialog(QWidget * parent) :
connect(_ui->comboBox_loggerEventLevel, SIGNAL(currentIndexChanged(int)), this, SLOT(makeObsoleteLoggingPanel())); connect(_ui->comboBox_loggerEventLevel, SIGNAL(currentIndexChanged(int)), this, SLOT(makeObsoleteLoggingPanel()));
connect(_ui->comboBox_loggerPauseLevel, SIGNAL(currentIndexChanged(int)), this, SLOT(makeObsoleteLoggingPanel())); connect(_ui->comboBox_loggerPauseLevel, SIGNAL(currentIndexChanged(int)), this, SLOT(makeObsoleteLoggingPanel()));
connect(_ui->checkBox_logger_printTime, SIGNAL(stateChanged(int)), this, SLOT(makeObsoleteLoggingPanel())); connect(_ui->checkBox_logger_printTime, SIGNAL(stateChanged(int)), this, SLOT(makeObsoleteLoggingPanel()));
connect(_ui->checkBox_logger_printThreadId, SIGNAL(stateChanged(int)), this, SLOT(makeObsoleteLoggingPanel()));
connect(_ui->comboBox_loggerType, SIGNAL(currentIndexChanged(int)), this, SLOT(makeObsoleteLoggingPanel())); connect(_ui->comboBox_loggerType, SIGNAL(currentIndexChanged(int)), this, SLOT(makeObsoleteLoggingPanel()));
//Source panel //Source panel
@@ -1121,6 +1122,7 @@ void PreferencesDialog::resetSettings(QGroupBox * groupBox)
_ui->comboBox_loggerEventLevel->setCurrentIndex(3); _ui->comboBox_loggerEventLevel->setCurrentIndex(3);
_ui->comboBox_loggerPauseLevel->setCurrentIndex(3); _ui->comboBox_loggerPauseLevel->setCurrentIndex(3);
_ui->checkBox_logger_printTime->setChecked(true); _ui->checkBox_logger_printTime->setChecked(true);
_ui->checkBox_logger_printThreadId->setChecked(false);
_ui->comboBox_loggerType->setCurrentIndex(1); _ui->comboBox_loggerType->setCurrentIndex(1);
} }
else if(groupBox->objectName() == _ui->groupBox_source0->objectName()) else if(groupBox->objectName() == _ui->groupBox_source0->objectName())
@@ -1381,6 +1383,7 @@ void PreferencesDialog::readGuiSettings(const QString & filePath)
_ui->comboBox_loggerPauseLevel->setCurrentIndex(settings.value("loggerPauseLevel", _ui->comboBox_loggerPauseLevel->currentIndex()).toInt()); _ui->comboBox_loggerPauseLevel->setCurrentIndex(settings.value("loggerPauseLevel", _ui->comboBox_loggerPauseLevel->currentIndex()).toInt());
_ui->comboBox_loggerType->setCurrentIndex(settings.value("loggerType", _ui->comboBox_loggerType->currentIndex()).toInt()); _ui->comboBox_loggerType->setCurrentIndex(settings.value("loggerType", _ui->comboBox_loggerType->currentIndex()).toInt());
_ui->checkBox_logger_printTime->setChecked(settings.value("loggerPrintTime", _ui->checkBox_logger_printTime->isChecked()).toBool()); _ui->checkBox_logger_printTime->setChecked(settings.value("loggerPrintTime", _ui->checkBox_logger_printTime->isChecked()).toBool());
_ui->checkBox_logger_printThreadId->setChecked(settings.value("loggerPrintThreadId", _ui->checkBox_logger_printThreadId->isChecked()).toBool());
_ui->checkBox_verticalLayoutUsed->setChecked(settings.value("verticalLayoutUsed", _ui->checkBox_verticalLayoutUsed->isChecked()).toBool()); _ui->checkBox_verticalLayoutUsed->setChecked(settings.value("verticalLayoutUsed", _ui->checkBox_verticalLayoutUsed->isChecked()).toBool());
_ui->checkBox_imageRejectedShown->setChecked(settings.value("imageRejectedShown", _ui->checkBox_imageRejectedShown->isChecked()).toBool()); _ui->checkBox_imageRejectedShown->setChecked(settings.value("imageRejectedShown", _ui->checkBox_imageRejectedShown->isChecked()).toBool());
_ui->checkBox_imageHighestHypShown->setChecked(settings.value("imageHighestHypShown", _ui->checkBox_imageHighestHypShown->isChecked()).toBool()); _ui->checkBox_imageHighestHypShown->setChecked(settings.value("imageHighestHypShown", _ui->checkBox_imageHighestHypShown->isChecked()).toBool());
@@ -1730,6 +1733,7 @@ void PreferencesDialog::writeGuiSettings(const QString & filePath) const
settings.setValue("loggerPauseLevel", _ui->comboBox_loggerPauseLevel->currentIndex()); settings.setValue("loggerPauseLevel", _ui->comboBox_loggerPauseLevel->currentIndex());
settings.setValue("loggerType", _ui->comboBox_loggerType->currentIndex()); settings.setValue("loggerType", _ui->comboBox_loggerType->currentIndex());
settings.setValue("loggerPrintTime", _ui->checkBox_logger_printTime->isChecked()); settings.setValue("loggerPrintTime", _ui->checkBox_logger_printTime->isChecked());
settings.setValue("loggerPrintThreadId", _ui->checkBox_logger_printThreadId->isChecked());
settings.setValue("verticalLayoutUsed", _ui->checkBox_verticalLayoutUsed->isChecked()); settings.setValue("verticalLayoutUsed", _ui->checkBox_verticalLayoutUsed->isChecked());
settings.setValue("imageRejectedShown", _ui->checkBox_imageRejectedShown->isChecked()); settings.setValue("imageRejectedShown", _ui->checkBox_imageRejectedShown->isChecked());
settings.setValue("imageHighestHypShown", _ui->checkBox_imageHighestHypShown->isChecked()); settings.setValue("imageHighestHypShown", _ui->checkBox_imageHighestHypShown->isChecked());
@@ -3443,6 +3447,10 @@ bool PreferencesDialog::getGeneralLoggerPrintTime() const
{ {
return _ui->checkBox_logger_printTime->isChecked(); return _ui->checkBox_logger_printTime->isChecked();
} }
bool PreferencesDialog::getGeneralLoggerPrintThreadId() const
{
return _ui->checkBox_logger_printThreadId->isChecked();
}
bool PreferencesDialog::isVerticalLayoutUsed() const bool PreferencesDialog::isVerticalLayoutUsed() const
{ {
return _ui->checkBox_verticalLayoutUsed->isChecked(); return _ui->checkBox_verticalLayoutUsed->isChecked();
+28 -5
View File
@@ -63,7 +63,7 @@
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>-366</y> <y>0</y>
<width>633</width> <width>633</width>
<height>2118</height> <height>2118</height>
</rect> </rect>
@@ -86,7 +86,7 @@
<enum>QFrame::Raised</enum> <enum>QFrame::Raised</enum>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>13</number> <number>2</number>
</property> </property>
<widget class="QWidget" name="page_22"> <widget class="QWidget" name="page_22">
<layout class="QVBoxLayout" name="verticalLayout_29" stretch="0,1"> <layout class="QVBoxLayout" name="verticalLayout_29" stretch="0,1">
@@ -1555,7 +1555,7 @@ Show a yellow background when the number of odometry inliers goes under this thr
</property> </property>
</widget> </widget>
</item> </item>
<item row="4" column="0"> <item row="5" column="0">
<widget class="QComboBox" name="comboBox_loggerType"> <widget class="QComboBox" name="comboBox_loggerType">
<property name="currentIndex"> <property name="currentIndex">
<number>1</number> <number>1</number>
@@ -1580,7 +1580,7 @@ Show a yellow background when the number of odometry inliers goes under this thr
</item> </item>
</widget> </widget>
</item> </item>
<item row="4" column="1"> <item row="5" column="1">
<widget class="QLabel" name="label_68"> <widget class="QLabel" name="label_68">
<property name="text"> <property name="text">
<string>Logger type: <string>Logger type:
@@ -1594,6 +1594,29 @@ when using the file type, logs are saved in LogRtabmap.txt (located in the worki
</property> </property>
</widget> </widget>
</item> </item>
<item row="4" column="1">
<widget class="QLabel" name="label_118">
<property name="text">
<string>Logger print thread ID.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QCheckBox" name="checkBox_logger_printThreadId">
<property name="text">
<string/>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>
@@ -10899,7 +10922,7 @@ Lower the ratio -&gt; higher the precision. 0 means disabled, matching the neare
<customwidget> <customwidget>
<class>UPlot</class> <class>UPlot</class>
<extends>QWidget</extends> <extends>QWidget</extends>
<header>rtabmap/utilite/UPlot.h</header> <header>../include/rtabmap/utilite/UPlot.h</header>
<container>1</container> <container>1</container>
</customwidget> </customwidget>
</customwidgets> </customwidgets>
+13
View File
@@ -298,6 +298,13 @@ public:
static void setPrintWhere(bool printWhere) {printWhere_ = printWhere;} static void setPrintWhere(bool printWhere) {printWhere_ = printWhere;}
static bool isPrintWhere() {return printWhere_;} static bool isPrintWhere() {return printWhere_;}
/**
* Print thread ID: default false.
* @param printThreadId true to print where, otherwise set to false.
*/
static void setPrintThreadId(bool printThreadId) {printThreadID_ = printThreadId;}
static bool isPrintThreadId() {return printThreadID_;}
/** /**
* Print the full path: default true. ULogger::setPrintWhere() must be true to have path printed. * Print the full path: default true. ULogger::setPrintWhere() must be true to have path printed.
* @param printWhereFullPath true to print the full path, otherwise set to false. * @param printWhereFullPath true to print the full path, otherwise set to false.
@@ -507,6 +514,12 @@ private:
*/ */
static bool printWhereFullPath_; static bool printWhereFullPath_;
/*
* If the logger prints the thread ID.
* Default is false.
*/
static bool printThreadID_;
/* /*
* If the logger limit the size of the "where" path to * If the logger limit the size of the "where" path to
* characters. If the path is over 8 characters, a "~" * characters. If the path is over 8 characters, a "~"
+6 -6
View File
@@ -91,6 +91,10 @@ public:
*/ */
enum Priority{kPLow, kPBelowNormal, kPNormal, kPAboveNormal, kPRealTime}; enum Priority{kPLow, kPBelowNormal, kPNormal, kPAboveNormal, kPRealTime};
public:
//return caller thread id
static unsigned long currentThreadId() {return (unsigned long)UThreadC<void>::Self();}
public: public:
/** /**
* The constructor. * The constructor.
@@ -165,7 +169,7 @@ public:
bool isKilled() const; bool isKilled() const;
Handle getThreadHandle() const {return handle_;} Handle getThreadHandle() const {return handle_;}
unsigned long getThreadId() const {return threadId_;}
protected: protected:
@@ -248,18 +252,14 @@ private:
private: private:
void operator=(UThread & t) {} void operator=(UThread & t) {}
UThread( const UThread & t ) {} UThread( const UThread & t ) : state_(kSIdle) {}
private: private:
enum State{kSIdle, kSCreating, kSRunning, kSKilled}; /* Enum of states. */ enum State{kSIdle, kSCreating, kSRunning, kSKilled}; /* Enum of states. */
State state_; /* The thread state. */ State state_; /* The thread state. */
Priority priority_; /* The thread priority. */ Priority priority_; /* The thread priority. */
Handle handle_; /* The thread handle. */ Handle handle_; /* The thread handle. */
#ifdef _WIN32
int threadId_; /* The thread id. */
#else
unsigned long threadId_; /* The thread id. */ unsigned long threadId_; /* The thread id. */
#endif
int cpuAffinity_; /* The cpu affinity. */ int cpuAffinity_; /* The cpu affinity. */
UMutex killSafelyMutex_; /* Mutex used to protect the kill() method. */ UMutex killSafelyMutex_; /* Mutex used to protect the kill() method. */
UMutex runningMutex_; /* Mutex used to notify the join method when the thread has finished. */ UMutex runningMutex_; /* Mutex used to notify the join method when the thread has finished. */
@@ -321,7 +321,7 @@ class UTILITE_EXP UThreadC<void>
} }
int Create( int Create(
int & ThreadId, unsigned long & ThreadId,
Handle * const & H = 0, Handle * const & H = 0,
const bool & CreateDetached = false, const bool & CreateDetached = false,
const unsigned int & StackSize = 0, const unsigned int & StackSize = 0,
@@ -330,7 +330,9 @@ class UTILITE_EXP UThreadC<void>
) const ) const
{ {
*H = InvalidHandle; *H = InvalidHandle;
*H = CREATE_THREAD2(StackSize,ThreadMainHandler,this, (LPDWORD)&ThreadId); int id;
*H = CREATE_THREAD2(StackSize,ThreadMainHandler,this, (LPDWORD)&id);
ThreadId = (unsigned long)id;
if ( *H == CREATE_THREAD_FAILED ) if ( *H == CREATE_THREAD_FAILED )
{ {
+12 -2
View File
@@ -50,6 +50,7 @@ bool ULogger::printEndline_ = true;
bool ULogger::printColored_ = true; bool ULogger::printColored_ = true;
bool ULogger::printWhere_ = true; bool ULogger::printWhere_ = true;
bool ULogger::printWhereFullPath_ = false; bool ULogger::printWhereFullPath_ = false;
bool ULogger::printThreadID_ = false;
bool ULogger::limitWhereLength_ = false; bool ULogger::limitWhereLength_ = false;
bool ULogger::buffered_ = false; bool ULogger::buffered_ = false;
bool ULogger::exitingState_ = false; bool ULogger::exitingState_ = false;
@@ -210,6 +211,7 @@ void ULogger::reset()
printColored_ = true; printColored_ = true;
printWhere_ = true; printWhere_ = true;
printWhereFullPath_ = false; printWhereFullPath_ = false;
printThreadID_ = false;
limitWhereLength_ = false; limitWhereLength_ = false;
level_ = kInfo; // By default, we show all info msgs + upper level (Warning, Error) level_ = kInfo; // By default, we show all info msgs + upper level (Warning, Error)
logFileName_ = ULogger::kDefaultLogFileName; logFileName_ = ULogger::kDefaultLogFileName;
@@ -383,6 +385,12 @@ void ULogger::write(ULogger::Level level,
levelStr.append(" "); levelStr.append(" ");
} }
std::string pidStr;
if(printThreadID_)
{
pidStr = uFormat("{%lu} ", UThread::currentThreadId());
}
std::string whereStr = ""; std::string whereStr = "";
if(printWhere_ || level == kFatal) if(printWhere_ || level == kFatal)
{ {
@@ -449,6 +457,7 @@ void ULogger::write(ULogger::Level level,
if(buffered_) if(buffered_)
{ {
bufferedMsgs_.append(levelStr.c_str()); bufferedMsgs_.append(levelStr.c_str());
bufferedMsgs_.append(pidStr.c_str());
bufferedMsgs_.append(time.c_str()); bufferedMsgs_.append(time.c_str());
bufferedMsgs_.append(whereStr.c_str()); bufferedMsgs_.append(whereStr.c_str());
bufferedMsgs_.append(uFormatv(msg, args)); bufferedMsgs_.append(uFormatv(msg, args));
@@ -456,6 +465,7 @@ void ULogger::write(ULogger::Level level,
else else
{ {
ULogger::getInstance()->_writeStr(levelStr.c_str()); ULogger::getInstance()->_writeStr(levelStr.c_str());
ULogger::getInstance()->_writeStr(pidStr.c_str());
ULogger::getInstance()->_writeStr(time.c_str()); ULogger::getInstance()->_writeStr(time.c_str());
ULogger::getInstance()->_writeStr(whereStr.c_str()); ULogger::getInstance()->_writeStr(whereStr.c_str());
ULogger::getInstance()->_write(msg, args); ULogger::getInstance()->_write(msg, args);
@@ -488,7 +498,7 @@ void ULogger::write(ULogger::Level level,
if(level >= eventLevel_) if(level >= eventLevel_)
{ {
std::string fullMsg = uFormat("%s%s%s", levelStr.c_str(), time.c_str(), whereStr.c_str()); std::string fullMsg = uFormat("%s%s%s%s", levelStr.c_str(), pidStr.c_str(), time.c_str(), whereStr.c_str());
va_start(args, msg); va_start(args, msg);
fullMsg.append(uFormatv(msg, args)); fullMsg.append(uFormatv(msg, args));
va_end(args); va_end(args);
@@ -510,7 +520,7 @@ void ULogger::write(ULogger::Level level,
printf("\n*******\n%s message occurred! Application will now exit.\n", levelName_[level]); printf("\n*******\n%s message occurred! Application will now exit.\n", levelName_[level]);
if(type_ != kTypeConsole) if(type_ != kTypeConsole)
{ {
printf(" %s%s%s", levelStr.c_str(), time.c_str(), whereStr.c_str()); printf(" %s%s%s%s", levelStr.c_str(), pidStr.c_str(), time.c_str(), whereStr.c_str());
va_start(args, msg); va_start(args, msg);
vprintf(msg, args); vprintf(msg, args);
va_end(args); va_end(args);