From 60997a1f9a73b3db236f6443c3126f522538cc29 Mon Sep 17 00:00:00 2001 From: Nodir Temirkhodjaev Date: Thu, 4 May 2023 14:43:30 +0300 Subject: [PATCH] UI: StatManager: Fix stats for Traffic Graph when "Collect Traffic Statistics" is turned off --- src/ui/stat/statmanager.cpp | 16 +++++++--------- src/ui/stat/statmanager.h | 2 +- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/ui/stat/statmanager.cpp b/src/ui/stat/statmanager.cpp index 02fe3def..f907b094 100644 --- a/src/ui/stat/statmanager.cpp +++ b/src/ui/stat/statmanager.cpp @@ -242,11 +242,11 @@ bool StatManager::logProcNew(const LogEntryProcNew &entry, qint64 unixTime) bool StatManager::logStatTraf(const LogEntryStatTraf &entry, qint64 unixTime) { - const bool logStat = conf() && conf()->logStat(); - // Active period updateActivePeriod(); + const bool logStat = conf() && conf()->logStat() && m_isActivePeriod; + const bool isNewDay = updateTrafDay(unixTime); sqliteDb()->beginTransaction(); @@ -284,10 +284,8 @@ bool StatManager::logStatTraf(const LogEntryStatTraf &entry, qint64 unixTime) const bool inactive = (pidFlag & 1) != 0; const quint32 pid = pidFlag & ~quint32(1); - if (logStat) { - logTrafBytes(insertTrafAppStmts, updateTrafAppStmts, sumInBytes, sumOutBytes, pid, - inBytes, outBytes, unixTime); - } + logTrafBytes(insertTrafAppStmts, updateTrafAppStmts, sumInBytes, sumOutBytes, pid, + inBytes, outBytes, unixTime, logStat); if (inactive) { logClearApp(pid); @@ -295,7 +293,7 @@ bool StatManager::logStatTraf(const LogEntryStatTraf &entry, qint64 unixTime) } } - if (m_isActivePeriod && logStat) { + if (logStat) { const SqliteStmtList insertTrafStmts = SqliteStmtList() << getTrafficStmt(StatSql::sqlInsertTrafHour, m_trafHour) << getTrafficStmt(StatSql::sqlInsertTrafDay, m_trafDay) @@ -474,7 +472,7 @@ void StatManager::getStatAppList(QStringList &list, QVector &appIds) void StatManager::logTrafBytes(const SqliteStmtList &insertStmtList, const SqliteStmtList &updateStmtList, quint32 &sumInBytes, quint32 &sumOutBytes, - quint32 pid, quint32 inBytes, quint32 outBytes, qint64 unixTime) + quint32 pid, quint32 inBytes, quint32 outBytes, qint64 unixTime, bool logStat) { const QString appPath = m_appPidPathMap.value(pid); @@ -490,7 +488,7 @@ void StatManager::logTrafBytes(const SqliteStmtList &insertStmtList, const qint64 appId = getOrCreateAppId(appPath, unixTime); Q_ASSERT(appId != INVALID_APP_ID); - if (m_isActivePeriod) { + if (logStat) { if (!hasAppTraf(appId)) { emit appCreated(appId, appPath); } diff --git a/src/ui/stat/statmanager.h b/src/ui/stat/statmanager.h index 6e98828b..4cfb1397 100644 --- a/src/ui/stat/statmanager.h +++ b/src/ui/stat/statmanager.h @@ -92,7 +92,7 @@ private: void logTrafBytes(const SqliteStmtList &insertStmtList, const SqliteStmtList &updateStmtList, quint32 &sumInBytes, quint32 &sumOutBytes, quint32 pid, quint32 inBytes, - quint32 outBytes, qint64 unixTime); + quint32 outBytes, qint64 unixTime, bool logStat); void updateTrafficList(const SqliteStmtList &insertStmtList, const SqliteStmtList &updateStmtList, quint32 inBytes, quint32 outBytes,