Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/2.1' into 2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
esbrandt committed Feb 21, 2018
2 parents 3ce7e68 + 0ff67c5 commit cc7d8ae
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 25 deletions.
37 changes: 23 additions & 14 deletions src/dialog/dlgdevelopertools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "control/control.h"
#include "util/cmdlineargs.h"
#include "util/statsmanager.h"
#include "util/logging.h"

DlgDeveloperTools::DlgDeveloperTools(QWidget* pParent,
UserSettingsPointer pConfig)
Expand Down Expand Up @@ -81,24 +82,32 @@ DlgDeveloperTools::DlgDeveloperTools(QWidget* pParent,

void DlgDeveloperTools::timerEvent(QTimerEvent* pEvent) {
Q_UNUSED(pEvent);
if (m_logFile.isOpen()) {
QStringList newLines;
if (!isVisible()) {
// nothing to do if we are not visible
return;
}

while (true) {
QByteArray line = m_logFile.readLine();
if (line.isEmpty()) {
break;
// To save on CPU, only update the models when they are visible.
if (toolTabWidget->currentWidget() == logTab) {
if (m_logFile.isOpen()) {
// ensure, everything is in Buffer.
mixxx::Logging::flushLogFile();

QStringList newLines;

while (true) {
QByteArray line = m_logFile.readLine();
if (line.isEmpty()) {
break;
}
newLines.append(QString::fromLocal8Bit(line));
}
newLines.append(QString::fromLocal8Bit(line));
}

if (!newLines.isEmpty()) {
logTextView->append(newLines.join(""));
if (!newLines.isEmpty()) {
logTextView->append(newLines.join(""));
}
}
}

// To save on CPU, only update the models when they are visible.
if (toolTabWidget->currentWidget() == controlsTab) {
} else if (toolTabWidget->currentWidget() == controlsTab) {
//m_controlModel.updateDirtyRows();
controlsTable->update();
} else if (toolTabWidget->currentWidget() == statsTab) {
Expand Down
2 changes: 1 addition & 1 deletion src/engine/enginebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1228,7 +1228,7 @@ void EngineBuffer::updateIndicators(double speed, int iBufferSize) {
// Update indicators that are only updated after every
// sampleRate/kiUpdateRate samples processed. (e.g. playposSlider)
if (m_iSamplesCalculated > (m_pSampleRate->get() / kiPlaypositionUpdateRate)) {
const double samplePositionToSeconds = 1.0 / m_iSampleRate
const double samplePositionToSeconds = 1.0 / m_trackSampleRateOld
/ kSamplesPerFrame / m_tempo_ratio_old;
m_timeElapsed->set(m_filepos_play * samplePositionToSeconds);
m_timeRemaining->set(std::max(m_trackSamplesOld - m_filepos_play, 0.0) *
Expand Down
4 changes: 3 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ int main(int argc, char * argv[]) {
QThread::currentThread()->setObjectName("Main");

mixxx::Logging::initialize(args.getSettingsPath(),
args.getLogLevel(), args.getDebugAssertBreak());
args.getLogLevel(),
args.getLogFlushLevel(),
args.getDebugAssertBreak());

MixxxApplication app(argc, argv);

Expand Down
24 changes: 23 additions & 1 deletion src/util/cmdlineargs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ CmdlineArgs::CmdlineArgs()
m_safeMode(false),
m_debugAssertBreak(false),
m_settingsPathSet(false),
m_logLevel(mixxx::LogLevel::Default),
m_logLevel(mixxx::kLogLevelDefault),
m_logFlushLevel(mixxx::kLogFlushLevelDefault),
// We are not ready to switch to XDG folders under Linux, so keeping $HOME/.mixxx as preferences folder. see lp:1463273
#ifdef __LINUX__
m_settingsPath(QDir::homePath().append("/").append(SETTINGS_PATH)) {
Expand Down Expand Up @@ -73,6 +74,23 @@ bool CmdlineArgs::Parse(int &argc, char **argv) {
warnings and errors to the console unless this is set properly.\n", stdout);
}
i++;
} else if (argv[i] == QString("--logFlushLevel") && i+1 < argc) {
auto level = QLatin1String(argv[i+1]);
if (level == "trace") {
m_logFlushLevel = mixxx::LogLevel::Trace;
} else if (level == "debug") {
m_logFlushLevel = mixxx::LogLevel::Debug;
} else if (level == "info") {
m_logFlushLevel = mixxx::LogLevel::Info;
} else if (level == "warning") {
m_logFlushLevel = mixxx::LogLevel::Warning;
} else if (level == "critical") {
m_logFlushLevel = mixxx::LogLevel::Critical;
} else {
fputs("\nlogFushLevel argument wasn't 'trace', 'debug', 'info', 'warning', or 'critical'! Mixxx will only flush messages to mixxx.log\n\
when a critical error occours unless this is set properly.\n", stdout);
}
i++;
} else if (QString::fromLocal8Bit(argv[i]).contains("--midiDebug", Qt::CaseInsensitive) ||
QString::fromLocal8Bit(argv[i]).contains("--controllerDebug", Qt::CaseInsensitive)) {
m_midiDebug = true;
Expand Down Expand Up @@ -142,6 +160,10 @@ void CmdlineArgs::printUsage() {
info - Above + Informational messages\n\
debug - Above + Debug/Developer messages\n\
trace - Above + Profiling messages\n\
\n\
--logFlushLevel LEVEL Sets the the logging level at which the log buffer\n\
is flushed to mixxx.log. LEVEL is one of the values\n\
defined at --logLevel above.\n\
\n"
#ifdef MIXXX_BUILD_DEBUG
"\
Expand Down
4 changes: 3 additions & 1 deletion src/util/cmdlineargs.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class CmdlineArgs final {
bool getDebugAssertBreak() const { return m_debugAssertBreak; }
bool getSettingsPathSet() const { return m_settingsPathSet; }
mixxx::LogLevel getLogLevel() const { return m_logLevel; }
mixxx::LogLevel getLogFlushLevel() const { return m_logFlushLevel; }
bool getTimelineEnabled() const { return !m_timelinePath.isEmpty(); }
const QString& getLocale() const { return m_locale; }
const QString& getSettingsPath() const { return m_settingsPath; }
Expand All @@ -47,7 +48,8 @@ class CmdlineArgs final {
bool m_safeMode;
bool m_debugAssertBreak;
bool m_settingsPathSet; // has --settingsPath been set on command line ?
mixxx::LogLevel m_logLevel; // Level of logging message verbosity
mixxx::LogLevel m_logLevel; // Level of stderr logging message verbosity
mixxx::LogLevel m_logFlushLevel; // Level of mixx.log file flushing
QString m_locale;
QString m_settingsPath;
QString m_resourcePath;
Expand Down
19 changes: 17 additions & 2 deletions src/util/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
namespace mixxx {

// Initialize the log level with the default value
LogLevel Logging::s_logLevel = LogLevel::Default;
LogLevel Logging::s_logLevel = kLogLevelDefault;
LogLevel Logging::s_logFlushLevel = kLogFlushLevelDefault;

namespace {

Expand Down Expand Up @@ -79,18 +80,21 @@ void MessageHandler(QtMsgType type,
#endif
shouldPrint = Logging::enabled(LogLevel::Debug) ||
isControllerDebug;
shouldFlush = Logging::flushing(LogLevel::Debug);
break;
#if QT_VERSION >= QT_VERSION_CHECK(5, 5, 0)
case QtInfoMsg:
tag = "Info [";
baSize += strlen(tag);
shouldPrint = Logging::enabled(LogLevel::Info);
shouldFlush = Logging::flushing(LogLevel::Info);
break;
#endif
case QtWarningMsg:
tag = "Warning [";
baSize += strlen(tag);
shouldPrint = Logging::enabled(LogLevel::Warning);
shouldFlush = Logging::flushing(LogLevel::Warning);
break;
case QtCriticalMsg:
tag = "Critical [";
Expand Down Expand Up @@ -176,14 +180,17 @@ void MessageHandler(QtMsgType type,
} // namespace

// static
void Logging::initialize(const QDir& settingsDir, LogLevel logLevel,
void Logging::initialize(const QDir& settingsDir,
LogLevel logLevel,
LogLevel logFlushLevel,
bool debugAssertBreak) {
VERIFY_OR_DEBUG_ASSERT(!g_logfile.isOpen()) {
// Somebody already called Logging::initialize.
return;
}

s_logLevel = logLevel;
s_logFlushLevel = logFlushLevel;

QString logFileName;

Expand Down Expand Up @@ -240,4 +247,12 @@ void Logging::shutdown() {
}
}

// static
void Logging::flushLogFile() {
QMutexLocker locker(&g_mutexLogfile);
if (g_logfile.isOpen()) {
g_logfile.flush();
}
}

} // namespace mixxx
15 changes: 10 additions & 5 deletions src/util/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,28 @@ enum class LogLevel {
Info = 2,
Debug = 3,
Trace = 4, // for profiling etc.
Default = Warning,
};

constexpr LogLevel kLogLevelDefault = LogLevel::Warning;
constexpr LogLevel kLogFlushLevelDefault = LogLevel::Critical;

class Logging {
public:
// These are not thread safe. Only call them on Mixxx startup and shutdown.
static void initialize(const QDir& settingsDir,
LogLevel logLevel,
LogLevel logFlushLevel,
bool debugAssertBreak);
static void shutdown();

// Query the current log level
static LogLevel logLevel() {
return s_logLevel;
}
static void flushLogFile();

static bool enabled(LogLevel logLevel) {
return s_logLevel >= logLevel;
}
static bool flushing(LogLevel logFlushLevel) {
return s_logFlushLevel >= logFlushLevel;
}
static bool traceEnabled() {
return enabled(LogLevel::Trace);
}
Expand All @@ -44,6 +48,7 @@ class Logging {
Logging() = delete;

static LogLevel s_logLevel;
static LogLevel s_logFlushLevel;
};

} // namespace mixxx
Expand Down

0 comments on commit cc7d8ae

Please sign in to comment.