mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
Merge pull request #8847 from sethalves/fix-audio-mixer-data-race-1
fix some data-races in logging system
This commit is contained in:
commit
bdcb58bf8b
4 changed files with 40 additions and 12 deletions
|
@ -638,6 +638,10 @@ QString AudioMixer::percentageForMixStats(int counter) {
|
|||
void AudioMixer::sendStatsPacket() {
|
||||
QJsonObject statsObject;
|
||||
|
||||
if (_numStatFrames == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
statsObject["useDynamicJitterBuffers"] = _numStaticJitterFrames == -1;
|
||||
statsObject["trailing_sleep_percentage"] = _trailingSleepRatio * 100.0f;
|
||||
statsObject["performance_throttling_ratio"] = _performanceThrottlingRatio;
|
||||
|
|
|
@ -300,7 +300,7 @@ bool LimitedNodeList::packetSourceAndHashMatchAndTrackBandwidth(const udt::Packe
|
|||
= LogHandler::getInstance().addRepeatedMessageRegex(UNKNOWN_REGEX);
|
||||
|
||||
qCDebug(networking) << "Packet of type" << headerType
|
||||
<< "received from unknown node with UUID" << qPrintable(uuidStringWithoutCurlyBraces(sourceID));
|
||||
<< "received from unknown node with UUID" << uuidStringWithoutCurlyBraces(sourceID);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
|
||||
#include "LogHandler.h"
|
||||
|
||||
QMutex LogHandler::_mutex;
|
||||
|
||||
LogHandler& LogHandler::getInstance() {
|
||||
static LogHandler staticInstance;
|
||||
return staticInstance;
|
||||
|
@ -63,8 +65,29 @@ const QString DATE_STRING_FORMAT = "MM/dd hh:mm:ss";
|
|||
// the following will produce 11/18 13:55:36.999
|
||||
const QString DATE_STRING_FORMAT_WITH_MILLISECONDS = "MM/dd hh:mm:ss.zzz";
|
||||
|
||||
void LogHandler::setTargetName(const QString& targetName) {
|
||||
QMutexLocker lock(&_mutex);
|
||||
_targetName = targetName;
|
||||
}
|
||||
|
||||
void LogHandler::setShouldOutputProcessID(bool shouldOutputProcessID) {
|
||||
QMutexLocker lock(&_mutex);
|
||||
_shouldOutputProcessID = shouldOutputProcessID;
|
||||
}
|
||||
|
||||
void LogHandler::setShouldOutputThreadID(bool shouldOutputThreadID) {
|
||||
QMutexLocker lock(&_mutex);
|
||||
_shouldOutputThreadID = shouldOutputThreadID;
|
||||
}
|
||||
|
||||
void LogHandler::setShouldDisplayMilliseconds(bool shouldDisplayMilliseconds) {
|
||||
QMutexLocker lock(&_mutex);
|
||||
_shouldDisplayMilliseconds = shouldDisplayMilliseconds;
|
||||
}
|
||||
|
||||
|
||||
void LogHandler::flushRepeatedMessages() {
|
||||
QMutexLocker locker(&_repeatedMessageLock);
|
||||
QMutexLocker lock(&_mutex);
|
||||
QHash<QString, int>::iterator message = _repeatMessageCountHash.begin();
|
||||
while (message != _repeatMessageCountHash.end()) {
|
||||
|
||||
|
@ -73,7 +96,9 @@ void LogHandler::flushRepeatedMessages() {
|
|||
.arg(message.value()).arg(message.key()).arg(_lastRepeatedMessage.value(message.key()));
|
||||
|
||||
QMessageLogContext emptyContext;
|
||||
lock.unlock();
|
||||
printMessage(LogSuppressed, emptyContext, repeatMessage);
|
||||
lock.relock();
|
||||
}
|
||||
|
||||
_lastRepeatedMessage.remove(message.key());
|
||||
|
@ -82,13 +107,13 @@ void LogHandler::flushRepeatedMessages() {
|
|||
}
|
||||
|
||||
QString LogHandler::printMessage(LogMsgType type, const QMessageLogContext& context, const QString& message) {
|
||||
QMutexLocker lock(&_mutex);
|
||||
if (message.isEmpty()) {
|
||||
return QString();
|
||||
}
|
||||
|
||||
if (type == LogDebug) {
|
||||
// for debug messages, check if this matches any of our regexes for repeated log messages
|
||||
QMutexLocker locker(&_repeatedMessageLock);
|
||||
foreach(const QString& regexString, getInstance()._repeatedMessageRegexes) {
|
||||
QRegExp repeatRegex(regexString);
|
||||
if (repeatRegex.indexIn(message) != -1) {
|
||||
|
@ -111,7 +136,6 @@ QString LogHandler::printMessage(LogMsgType type, const QMessageLogContext& cont
|
|||
}
|
||||
}
|
||||
if (type == LogDebug) {
|
||||
QMutexLocker locker(&_onlyOnceMessageLock);
|
||||
// see if this message is one we should only print once
|
||||
foreach(const QString& regexString, getInstance()._onlyOnceMessageRegexes) {
|
||||
QRegExp onlyOnceRegex(regexString);
|
||||
|
@ -163,11 +187,11 @@ void LogHandler::verboseMessageHandler(QtMsgType type, const QMessageLogContext&
|
|||
}
|
||||
|
||||
const QString& LogHandler::addRepeatedMessageRegex(const QString& regexString) {
|
||||
QMutexLocker locker(&_repeatedMessageLock);
|
||||
QMutexLocker lock(&_mutex);
|
||||
return *_repeatedMessageRegexes.insert(regexString);
|
||||
}
|
||||
|
||||
const QString& LogHandler::addOnlyOnceMessageRegex(const QString& regexString) {
|
||||
QMutexLocker locker(&_onlyOnceMessageLock);
|
||||
QMutexLocker lock(&_mutex);
|
||||
return *_onlyOnceMessageRegexes.insert(regexString);
|
||||
}
|
||||
|
|
|
@ -38,11 +38,11 @@ public:
|
|||
|
||||
/// sets the target name to output via the verboseMessageHandler, called once before logging begins
|
||||
/// \param targetName the desired target name to output in logs
|
||||
void setTargetName(const QString& targetName) { _targetName = targetName; }
|
||||
void setTargetName(const QString& targetName);
|
||||
|
||||
void setShouldOutputProcessID(bool shouldOutputProcessID) { _shouldOutputProcessID = shouldOutputProcessID; }
|
||||
void setShouldOutputThreadID(bool shouldOutputThreadID) { _shouldOutputThreadID = shouldOutputThreadID; }
|
||||
void setShouldDisplayMilliseconds(bool shouldDisplayMilliseconds) { _shouldDisplayMilliseconds = shouldDisplayMilliseconds; }
|
||||
void setShouldOutputProcessID(bool shouldOutputProcessID);
|
||||
void setShouldOutputThreadID(bool shouldOutputThreadID);
|
||||
void setShouldDisplayMilliseconds(bool shouldDisplayMilliseconds);
|
||||
|
||||
QString printMessage(LogMsgType type, const QMessageLogContext& context, const QString &message);
|
||||
|
||||
|
@ -64,11 +64,11 @@ private:
|
|||
QSet<QString> _repeatedMessageRegexes;
|
||||
QHash<QString, int> _repeatMessageCountHash;
|
||||
QHash<QString, QString> _lastRepeatedMessage;
|
||||
QMutex _repeatedMessageLock;
|
||||
|
||||
QSet<QString> _onlyOnceMessageRegexes;
|
||||
QHash<QString, int> _onlyOnceMessageCountHash;
|
||||
QMutex _onlyOnceMessageLock;
|
||||
|
||||
static QMutex _mutex;
|
||||
};
|
||||
|
||||
#endif // hifi_LogHandler_h
|
||||
|
|
Loading…
Reference in a new issue