File indexing completed on 2024-05-12 05:48:39
0001 /* 0002 SPDX-FileCopyrightText: 2007 Nicolas Ternisien <nicolas.ternisien@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "kernelAnalyzer.h" 0008 #include <QFile> 0009 #include <QRegExp> 0010 0011 KernelAnalyzer::KernelAnalyzer(LogMode *logMode) 0012 : FileAnalyzer(logMode) 0013 { 0014 startupTime(); 0015 } 0016 0017 LogViewColumns KernelAnalyzer::initColumns() 0018 { 0019 LogViewColumns columns; 0020 columns.addColumn(LogViewColumn(i18n("Date"), true, false)); 0021 columns.addColumn(LogViewColumn(i18n("Component"), true, false)); 0022 columns.addColumn(LogViewColumn(i18n("Message"), true, false)); 0023 0024 return columns; 0025 } 0026 0027 LogFileReader *KernelAnalyzer::createLogFileReader(const LogFile &logFile) 0028 { 0029 return new ProcessOutputLogFileReader(logFile); 0030 } 0031 0032 void KernelAnalyzer::startupTime() 0033 { 0034 QFile file(QStringLiteral(UPTIME_FILE)); 0035 0036 file.open(QIODevice::ReadOnly | QIODevice::Text); 0037 0038 QTextStream in(&file); 0039 const QString line = in.readLine(); 0040 0041 // Format : 1618.72 1382.98 (uptime / something) 0042 const QStringList times = line.split(QLatin1Char(' ')); 0043 0044 const QString secondsString = times.at(0); 0045 const QString pureSecondsString = secondsString.left(secondsString.indexOf(QLatin1Char('.'))); 0046 const long updateSeconds = pureSecondsString.toLong(); 0047 0048 mStartupDateTime = QDateTime::currentDateTime().addSecs(-updateSeconds); 0049 qCDebug(KSYSTEMLOG) << "Startup time : " << mStartupDateTime; 0050 } 0051 0052 LogLine *KernelAnalyzer::parseMessage(const QString &logLine, const LogFile &originalLogFile) 0053 { 0054 const QRegExp timeRegex(QStringLiteral("\\[\\ *(\\d*)\\.(\\d*)\\]\\s+(.*)")); 0055 0056 // QRegExp componentRegexp(timeRegex + "([^\\s:]{,20})[:\\s\\t]+(.*)"); 0057 // QRegExp messageRegexp(timeRegex + "(.*)"); 0058 0059 QDateTime dateTime(mStartupDateTime); 0060 QStringList messages; 0061 0062 int const timeExists = timeRegex.indexIn(logLine); 0063 0064 // If we have the date, we are able to update the start date 0065 if (timeExists != -1) { 0066 // qCDebug(KSYSTEMLOG) << componentRegexp.cap(1).toInt() << "and" << componentRegexp.cap(2).toInt(); 0067 dateTime = dateTime.addSecs(timeRegex.cap(1).toInt()); 0068 dateTime = dateTime.addMSecs(timeRegex.cap(2).toInt() / 1000); 0069 0070 parseComponentMessage(timeRegex.cap(3), messages); 0071 } 0072 // Else, the date will never change 0073 else { 0074 parseComponentMessage(logLine, messages); 0075 } 0076 0077 /* 0078 qCDebug(KSYSTEMLOG) << "--------------------------------"; 0079 qCDebug(KSYSTEMLOG) << logLine; 0080 qCDebug(KSYSTEMLOG) << "Secs : " << dateTime.time().second(); 0081 qCDebug(KSYSTEMLOG) << "MSec : " << dateTime.time().msec(); 0082 qCDebug(KSYSTEMLOG) << "Comp : " << messages.at(0); 0083 qCDebug(KSYSTEMLOG) << "Msg : " << messages.at(1); 0084 qCDebug(KSYSTEMLOG) << "--------------------------------"; 0085 */ 0086 0087 auto line = new LogLine(mLogLineInternalIdGenerator++, 0088 dateTime, 0089 messages, 0090 originalLogFile.url().toLocalFile(), 0091 Globals::instance().informationLogLevel(), 0092 mLogMode); 0093 0094 return line; 0095 } 0096 0097 #include "moc_kernelAnalyzer.cpp"