UI: StatManager: Fix processes tracking when "Collect Traffic Statistics" is turned off

This commit is contained in:
Nodir Temirkhodjaev 2023-05-04 14:37:40 +03:00
parent 3f5a15db49
commit 27c7935ed4
2 changed files with 18 additions and 16 deletions

View File

@ -99,7 +99,7 @@ void StatManager::setupTrafDate()
void StatManager::setupByConf()
{
if (!conf() || !conf()->logStat()) {
if (!conf()) {
logClear();
}
@ -114,6 +114,7 @@ void StatManager::setupActivePeriod()
{
DateUtil::parseTime(
conf()->activePeriodFrom(), m_activePeriodFromHour, m_activePeriodFromMinute);
DateUtil::parseTime(conf()->activePeriodTo(), m_activePeriodToHour, m_activePeriodToMinute);
}
@ -241,8 +242,7 @@ bool StatManager::logProcNew(const LogEntryProcNew &entry, qint64 unixTime)
bool StatManager::logStatTraf(const LogEntryStatTraf &entry, qint64 unixTime)
{
if (!conf() || !conf()->logStat())
return false;
const bool logStat = conf() && conf()->logStat();
// Active period
updateActivePeriod();
@ -281,12 +281,21 @@ bool StatManager::logStatTraf(const LogEntryStatTraf &entry, qint64 unixTime)
const quint32 inBytes = *procTrafBytes++;
const quint32 outBytes = *procTrafBytes++;
logTrafBytes(insertTrafAppStmts, updateTrafAppStmts, sumInBytes, sumOutBytes, pidFlag,
const bool inactive = (pidFlag & 1) != 0;
const quint32 pid = pidFlag & ~quint32(1);
if (logStat) {
logTrafBytes(insertTrafAppStmts, updateTrafAppStmts, sumInBytes, sumOutBytes, pid,
inBytes, outBytes, unixTime);
}
if (inactive) {
logClearApp(pid);
}
}
}
if (m_isActivePeriod) {
if (m_isActivePeriod && logStat) {
const SqliteStmtList insertTrafStmts = SqliteStmtList()
<< getTrafficStmt(StatSql::sqlInsertTrafHour, m_trafHour)
<< getTrafficStmt(StatSql::sqlInsertTrafDay, m_trafDay)
@ -465,23 +474,16 @@ void StatManager::getStatAppList(QStringList &list, QVector<qint64> &appIds)
void StatManager::logTrafBytes(const SqliteStmtList &insertStmtList,
const SqliteStmtList &updateStmtList, quint32 &sumInBytes, quint32 &sumOutBytes,
quint32 pidFlag, quint32 inBytes, quint32 outBytes, qint64 unixTime)
quint32 pid, quint32 inBytes, quint32 outBytes, qint64 unixTime)
{
const bool inactive = (pidFlag & 1) != 0;
const quint32 pid = pidFlag & ~quint32(1);
const QString appPath = m_appPidPathMap.value(pid);
if (Q_UNLIKELY(appPath.isEmpty())) {
qCCritical(LC) << "UI & Driver's states mismatch! Expected processes:"
<< m_appPidPathMap.keys() << "Got:" << pid << inactive;
<< m_appPidPathMap.keys() << "Got:" << pid;
return;
}
if (inactive) {
logClearApp(pid);
}
if (inBytes == 0 && outBytes == 0)
return;

View File

@ -91,7 +91,7 @@ private:
void deleteOldTraffic(qint32 trafHour);
void logTrafBytes(const SqliteStmtList &insertStmtList, const SqliteStmtList &updateStmtList,
quint32 &sumInBytes, quint32 &sumOutBytes, quint32 pidFlag, quint32 inBytes,
quint32 &sumInBytes, quint32 &sumOutBytes, quint32 pid, quint32 inBytes,
quint32 outBytes, qint64 unixTime);
void updateTrafficList(const SqliteStmtList &insertStmtList,