Commit 5a648c56 authored by Harald Sitter's avatar Harald Sitter 🏳🌈
Browse files

disabe ksycoca rebuilding on runner threads

this frees the internal per-thread inotify instance used to watch
database changes meaning runner applications no longer claim N inotify
instances (N=size of threadweaver pool).
the database is still reloaded by ksyscoca internally if it finds the
backing file has changed.

CCBUG: 423818
parent 459f5162
# SPDX-License-Identifier: BSD-3-Clause
# SPDX-FileCopyrightText: 2016-2020 Harald Sitter <sitter@kde.org>
remove_definitions(-DQT_NO_CAST_FROM_ASCII)
find_package(Threads REQUIRED)
include(ECMAddTests)
ecm_add_test(servicerunnertest.cpp TEST_NAME servicerunnertest
LINK_LIBRARIES Qt5::Test krunner_services_static)
LINK_LIBRARIES Qt5::Test krunner_services_static Threads::Threads)
set_target_properties(servicerunnertest PROPERTIES CXX_STANDARD 17) # std::optional
/*
* Copyright (C) 2016 Harald Sitter <sitter@kde.org>
* Copyright (C) 2016-2020 Harald Sitter <sitter@kde.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -24,6 +24,7 @@
#include <QObject>
#include <QStandardPaths>
#include <QTest>
#include <QThread>
#include <KSycoca>
......@@ -31,6 +32,8 @@
#include <clocale>
#include <optional>
#include <sys/types.h>
#include <unistd.h>
class ServiceRunnerTest : public QObject
{
......@@ -43,6 +46,7 @@ private Q_SLOTS:
void testKonsoleVsYakuakeComment();
void testSystemSettings();
void testForeignAppsOutscoreKCMs();
void testINotifyUsage();
};
void ServiceRunnerTest::initTestCase()
......@@ -204,6 +208,41 @@ void ServiceRunnerTest::testForeignAppsOutscoreKCMs()
qPrintable(QStringLiteral("%1 > %2").arg(virtManRelevance.value()).arg(kcmRelevance.value())));
}
void ServiceRunnerTest::testINotifyUsage()
{
auto inotifyCount = []() -> uint {
uint count = 0;
const QDir procDir(QStringLiteral("/proc/%1/fd").arg(getpid()));
for (const auto &fileInfo : procDir.entryInfoList()) {
if (fileInfo.symLinkTarget().endsWith(QStringLiteral("anon_inode:inotify"))) {
++count;
}
}
return count;
};
const uint originalCount = inotifyCount();
// We'll run this in a new thread so KDirWatch would be led to create a new thread-local watch instance.
// The expectation here is that this KDW instance is not persistently claiming an inotify instance.
bool inotifyCountCool = false;
auto thread = QThread::create([&] {
ServiceRunner runner(nullptr, QVariantList());
Plasma::RunnerContext context;
context.setQuery(QStringLiteral("settings"));
runner.match(context);
QCOMPARE(inotifyCount(), originalCount);
inotifyCountCool = true;
});
thread->start();
thread->wait();
thread->deleteLater();
QVERIFY(inotifyCountCool);
}
QTEST_MAIN(ServiceRunnerTest)
#include "servicerunnertest.moc"
/*
* Copyright (C) 2006 Aaron Seigo <aseigo@kde.org>
* Copyright (C) 2014 Vishesh Handa <vhanda@kde.org>
* Copyright (C) 2016 Harald Sitter <sitter@kde.org>
* Copyright (C) 2016-2020 Harald Sitter <sitter@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License version 2 as
......@@ -37,6 +37,7 @@
#include <KServiceAction>
#include <KServiceTypeTrader>
#include <KStringHandler>
#include <KSycoca>
#include <KIO/ApplicationLauncherJob>
......@@ -67,6 +68,8 @@ public:
return;
}
KSycoca::disableAutoRebuild();
term = context.query();
weightedTermLength = weightedLength(term);
......@@ -465,7 +468,7 @@ void ServiceRunner::run(const Plasma::RunnerContext &context, const Plasma::Quer
if (actionName.isEmpty()) {
// We want to load kcms directly with systemsettings,
// but we can't completely replace kcmshell with systemsettings
// as we need to be able to load kcms without plasma and we can't
// as we need to be able to load kcms without plasma and we can't
// implement all kcmshell features into systemsettings
if (service->serviceTypes().contains(QLatin1String("KCModule"))) {
if (service->parentApp() == QStringLiteral("kinfocenter")) {
......
Markdown is supported
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