Commit ae21f67c authored by David Edmundson's avatar David Edmundson
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.
parent bebacdd6
......@@ -102,7 +102,7 @@ add_definitions(-DQT_NO_NARROWING_CONVERSIONS_IN_CONNECT)
add_definitions(-DKF_DISABLE_DEPRECATED_BEFORE_AND_AT=0x054200)
add_definitions(-DKF_DEPRECATED_WARNINGS_SINCE=0x060000)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
add_subdirectory( formatter )
......
......@@ -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, 0, 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