| 29 | } |
| 30 | |
| 31 | void Kernel::sampleProcessStats() |
| 32 | { |
| 33 | int procs = 0, threads = 0; |
| 34 | const QDir procDir("/proc"); |
| 35 | for (const QString &entry : procDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) |
| 36 | { |
| 37 | bool ok; |
| 38 | entry.toInt(&ok); |
| 39 | if (!ok) |
| 40 | continue; |
| 41 | ++procs; |
| 42 | // Each thread appears as a subdirectory entry under /proc/<pid>/task/ |
| 43 | const QDir taskDir(QString("/proc/%1/task").arg(entry)); |
| 44 | // count() includes "." and ".." so subtract 2 |
| 45 | threads += static_cast<int>(taskDir.count()) - 2; |
| 46 | } |
| 47 | this->m_processCount = procs; |
| 48 | this->m_threadCount = qMax(0, threads); |
| 49 | } |
| 50 | |