Commit 356c39a7 authored by David Edmundson's avatar David Edmundson Committed by David Redondo
Browse files

Use faster file system searcing for iterating process groups

This was showing in hotspot as 14ms per update.

It turns out QDir creates a full QFileSystem entry on every file, even
using QDirIterator and with all features turned off.

This isn't really useful when iterating through /sys which has simpler
requirements.

Using a lower level API brings that down to 2ms.


(cherry picked from commit ae21f67c)
parent 7b29131a
......@@ -33,6 +33,7 @@
#include <QDir>
#include <algorithm>
#include <filesystem>
using namespace KSysGuard;
......@@ -409,11 +410,8 @@ bool CGroupDataModel::filterAcceptsCGroup(const QString &id)
void CGroupDataModel::update(CGroup *node)
{
namespace fs = std::filesystem;
const QString path = CGroup::cgroupSysBasePath() + node->id();
QDir dir(path);
if (!dir.exists()) {
return;
}
// Update our own stat info
// This may trigger some dataChanged
......@@ -422,9 +420,12 @@ void CGroupDataModel::update(CGroup *node)
Q_EMIT dataChanged(index(row, 0, QModelIndex()), index(row, columnCount()-1, QModelIndex()));
});
const auto entries = dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
for (auto subDir : entries) {
const QString childId = node->id() % QLatin1Char('/') % subDir;
for (const auto& entry : fs::directory_iterator(path.toUtf8().data())) {
if (!entry.is_directory()) {
continue;
}
const QString childId = node->id() % QLatin1Char('/') % QString::fromUtf8(entry.path().filename().c_str());
CGroup *childNode = d->m_cgroupMap[childId];
if (!childNode) {
childNode = new CGroup(childId);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment