Qnx: Fixing slog2info messages printing

Slog2InfoRunner class now more properly parses the slog2info output
including datetime, applicationid filtering, buffer-name, buffer-id.

Task-number: QTCREATORBUG-10646
Task-number: QTCREATORBUG-10712
Change-Id: I71aaf6b9b3ff1da16d3c46065a1dc5125dc1503e
Reviewed-by: Tobias Nätterlund <tobias.naetterlund@kdab.com>
Reviewed-by: Nicolas Arnaud-Cormos <nicolas@kdab.com>
Reviewed-by: David Kaspar <dkaspar@blackberry.com>
This commit is contained in:
David Kaspar
2013-11-14 09:11:25 +01:00
parent 267ffecb4b
commit efe2f64efe
2 changed files with 62 additions and 47 deletions

View File

@@ -43,6 +43,10 @@ Slog2InfoRunner::Slog2InfoRunner(const QString &applicationId, const RemoteLinux
, m_found(false) , m_found(false)
, m_currentLogs(false) , m_currentLogs(false)
{ {
// See QTCREATORBUG-10712 for details.
// We need to limit length of ApplicationId to 63 otherwise it would not match one in slog2info.
m_applicationId.truncate(63);
m_testProcess = new ProjectExplorer::SshDeviceProcess(device, this); m_testProcess = new ProjectExplorer::SshDeviceProcess(device, this);
connect(m_testProcess, SIGNAL(finished()), this, SLOT(handleTestProcessCompleted())); connect(m_testProcess, SIGNAL(finished()), this, SLOT(handleTestProcessCompleted()));
@@ -67,8 +71,10 @@ void Slog2InfoRunner::stop()
if (m_testProcess->state() == QProcess::Running) if (m_testProcess->state() == QProcess::Running)
m_testProcess->kill(); m_testProcess->kill();
if (m_logProcess->state() == QProcess::Running) if (m_logProcess->state() == QProcess::Running) {
m_logProcess->kill(); m_logProcess->kill();
processLog(true);
}
} }
bool Slog2InfoRunner::commandFound() const bool Slog2InfoRunner::commandFound() const
@@ -104,60 +110,66 @@ void Slog2InfoRunner::launchSlog2Info()
QString::fromLatin1("dd HH:mm:ss")); QString::fromLatin1("dd HH:mm:ss"));
QStringList arguments; QStringList arguments;
arguments << QLatin1String("-w") arguments << QLatin1String("-w");
<< QLatin1String("-b")
<< m_applicationId;
m_logProcess->start(QLatin1String("slog2info"), arguments); m_logProcess->start(QLatin1String("slog2info"), arguments);
} }
void Slog2InfoRunner::readLogStandardOutput() void Slog2InfoRunner::readLogStandardOutput()
{ {
const QString message = QString::fromLatin1(m_logProcess->readAllStandardOutput()); processLog(false);
const QStringList multiLine = message.split(QLatin1Char('\n'));
Q_FOREACH (const QString &line, multiLine) {
// Note: This is useless if/once slog2info -b displays only logs from recent launches
if (!m_launchDateTime.isNull())
{
// Check if logs are from the recent launch
if (!m_currentLogs) {
QDateTime dateTime = QDateTime::fromString(line.split(m_applicationId).first().mid(4).trimmed(),
QString::fromLatin1("dd HH:mm:ss.zzz"));
m_currentLogs = dateTime >= m_launchDateTime;
if (!m_currentLogs)
continue;
}
}
// The line could be a part of a previous log message that contains a '\n'
// In that case only the message body is displayed
if (!line.contains(m_applicationId) && !line.isEmpty()) {
emit output(line + QLatin1Char('\n'), Utils::StdOutFormat);
continue;
}
QStringList validLineBeginnings;
validLineBeginnings << QLatin1String("qt-msg 0 ")
<< QLatin1String("qt-msg* 0 ")
<< QLatin1String("default* 9000 ")
<< QLatin1String("default 9000 ")
<< QLatin1String(" 0 ");
Q_FOREACH (const QString &beginning, validLineBeginnings) {
if (showQtMessage(beginning, line))
break;
}
}
} }
bool Slog2InfoRunner::showQtMessage(const QString &pattern, const QString &line) void Slog2InfoRunner::processLog(bool force)
{ {
const int index = line.indexOf(pattern); QString input = QString::fromLatin1(m_logProcess->readAllStandardOutput());
if (index != -1) { QStringList lines = input.split(QLatin1Char('\n'));
const QString str = line.right(line.length()-index-pattern.length()) + QLatin1Char('\n'); if (lines.isEmpty())
emit output(str, Utils::StdOutFormat); return;
return true; lines.first().prepend(m_remainingData);
if (force)
m_remainingData.clear();
else
m_remainingData = lines.takeLast();
foreach (const QString &line, lines)
processLogLine(line);
}
void Slog2InfoRunner::processLogLine(const QString &line)
{
// The "(\\s+\\S+)?" represents a named buffer. If message has noname (aka empty) buffer
// then the message might get cut for the first number in the message.
// The "\\s+(\\b.*)?$" represents a space followed by a message. We are unable to determinate
// how many spaces represent separators and how many are a part of the messages, so resulting
// messages has all whitespaces at the beginning of the message trimmed.
static QRegExp regexp(QLatin1String(
"^[a-zA-Z]+\\s+([0-9]+ [0-9]+:[0-9]+:[0-9]+.[0-9]+)\\s+(\\S+)(\\s+(\\S+))?\\s+([0-9]+)\\s+(\\b.*)?$"));
if (!regexp.exactMatch(line) || regexp.captureCount() != 6)
return;
// Note: This is useless if/once slog2info -b displays only logs from recent launches
if (!m_launchDateTime.isNull()) {
// Check if logs are from the recent launch
if (!m_currentLogs) {
QDateTime dateTime = QDateTime::fromString(regexp.cap(1),
QLatin1String("dd HH:mm:ss.zzz"));
m_currentLogs = dateTime >= m_launchDateTime;
if (!m_currentLogs)
return;
} }
return false; }
QString applicationId = regexp.cap(2);
if (!applicationId.startsWith(m_applicationId))
return;
QString bufferName = regexp.cap(4);
int bufferId = regexp.cap(5).toInt();
// filtering out standard BB10 messages
if (bufferName == QLatin1String("default") && bufferId == 8900)
return;
emit output(regexp.cap(6) + QLatin1Char('\n'), Utils::StdOutFormat);
} }
void Slog2InfoRunner::readLogStandardError() void Slog2InfoRunner::readLogStandardError()

View File

@@ -38,6 +38,7 @@
#include <utils/outputformat.h> #include <utils/outputformat.h>
#include <QDateTime> #include <QDateTime>
#include <QByteArray>
namespace ProjectExplorer { namespace ProjectExplorer {
class SshDeviceProcess; class SshDeviceProcess;
@@ -75,7 +76,8 @@ private slots:
private: private:
void readLaunchTime(); void readLaunchTime();
bool showQtMessage(const QString &pattern, const QString &line); void processLog(bool force);
void processLogLine(const QString &line);
QString m_applicationId; QString m_applicationId;
@@ -83,6 +85,7 @@ private:
QDateTime m_launchDateTime; QDateTime m_launchDateTime;
bool m_currentLogs; bool m_currentLogs;
QString m_remainingData;
ProjectExplorer::SshDeviceProcess *m_launchDateTimeProcess; ProjectExplorer::SshDeviceProcess *m_launchDateTimeProcess;
ProjectExplorer::SshDeviceProcess *m_testProcess; ProjectExplorer::SshDeviceProcess *m_testProcess;