UI: StatManager: Fix stats for Traffic Graph when "Collect Traffic Statistics" is turned off

This commit is contained in:
Nodir Temirkhodjaev 2023-05-04 14:43:30 +03:00
parent 27c7935ed4
commit 60997a1f9a
2 changed files with 8 additions and 10 deletions

View File

@ -242,11 +242,11 @@ bool StatManager::logProcNew(const LogEntryProcNew &entry, qint64 unixTime)
bool StatManager::logStatTraf(const LogEntryStatTraf &entry, qint64 unixTime) bool StatManager::logStatTraf(const LogEntryStatTraf &entry, qint64 unixTime)
{ {
const bool logStat = conf() && conf()->logStat();
// Active period // Active period
updateActivePeriod(); updateActivePeriod();
const bool logStat = conf() && conf()->logStat() && m_isActivePeriod;
const bool isNewDay = updateTrafDay(unixTime); const bool isNewDay = updateTrafDay(unixTime);
sqliteDb()->beginTransaction(); sqliteDb()->beginTransaction();
@ -284,10 +284,8 @@ bool StatManager::logStatTraf(const LogEntryStatTraf &entry, qint64 unixTime)
const bool inactive = (pidFlag & 1) != 0; const bool inactive = (pidFlag & 1) != 0;
const quint32 pid = pidFlag & ~quint32(1); const quint32 pid = pidFlag & ~quint32(1);
if (logStat) {
logTrafBytes(insertTrafAppStmts, updateTrafAppStmts, sumInBytes, sumOutBytes, pid, logTrafBytes(insertTrafAppStmts, updateTrafAppStmts, sumInBytes, sumOutBytes, pid,
inBytes, outBytes, unixTime); inBytes, outBytes, unixTime, logStat);
}
if (inactive) { if (inactive) {
logClearApp(pid); logClearApp(pid);
@ -295,7 +293,7 @@ bool StatManager::logStatTraf(const LogEntryStatTraf &entry, qint64 unixTime)
} }
} }
if (m_isActivePeriod && logStat) { if (logStat) {
const SqliteStmtList insertTrafStmts = SqliteStmtList() const SqliteStmtList insertTrafStmts = SqliteStmtList()
<< getTrafficStmt(StatSql::sqlInsertTrafHour, m_trafHour) << getTrafficStmt(StatSql::sqlInsertTrafHour, m_trafHour)
<< getTrafficStmt(StatSql::sqlInsertTrafDay, m_trafDay) << getTrafficStmt(StatSql::sqlInsertTrafDay, m_trafDay)
@ -474,7 +472,7 @@ void StatManager::getStatAppList(QStringList &list, QVector<qint64> &appIds)
void StatManager::logTrafBytes(const SqliteStmtList &insertStmtList, void StatManager::logTrafBytes(const SqliteStmtList &insertStmtList,
const SqliteStmtList &updateStmtList, quint32 &sumInBytes, quint32 &sumOutBytes, 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); const QString appPath = m_appPidPathMap.value(pid);
@ -490,7 +488,7 @@ void StatManager::logTrafBytes(const SqliteStmtList &insertStmtList,
const qint64 appId = getOrCreateAppId(appPath, unixTime); const qint64 appId = getOrCreateAppId(appPath, unixTime);
Q_ASSERT(appId != INVALID_APP_ID); Q_ASSERT(appId != INVALID_APP_ID);
if (m_isActivePeriod) { if (logStat) {
if (!hasAppTraf(appId)) { if (!hasAppTraf(appId)) {
emit appCreated(appId, appPath); emit appCreated(appId, appPath);
} }

View File

@ -92,7 +92,7 @@ private:
void logTrafBytes(const SqliteStmtList &insertStmtList, const SqliteStmtList &updateStmtList, void logTrafBytes(const SqliteStmtList &insertStmtList, const SqliteStmtList &updateStmtList,
quint32 &sumInBytes, quint32 &sumOutBytes, quint32 pid, quint32 inBytes, quint32 &sumInBytes, quint32 &sumOutBytes, quint32 pid, quint32 inBytes,
quint32 outBytes, qint64 unixTime); quint32 outBytes, qint64 unixTime, bool logStat);
void updateTrafficList(const SqliteStmtList &insertStmtList, void updateTrafficList(const SqliteStmtList &insertStmtList,
const SqliteStmtList &updateStmtList, quint32 inBytes, quint32 outBytes, const SqliteStmtList &updateStmtList, quint32 inBytes, quint32 outBytes,