refact: optimize regular expression initialization
add profiling test. Signed-off-by: ComixHe <heyuming@deepin.org>
This commit is contained in:
parent
06ee5e5899
commit
2bdb9e99ee
@ -15,6 +15,7 @@ set(THREADS_PREFER_PTHREAD_FLAG ON)
|
|||||||
|
|
||||||
set(BUILD_EXAMPLES ON CACHE BOOL "Whether to build examples or not.")
|
set(BUILD_EXAMPLES ON CACHE BOOL "Whether to build examples or not.")
|
||||||
set(DEBUG_MODE ON CACHE BOOL "start a dde-applicatiom-manager service for debug")
|
set(DEBUG_MODE ON CACHE BOOL "start a dde-applicatiom-manager service for debug")
|
||||||
|
set(PROFILING_MODE OFF CACHE BOOL "run a valgrind performance profiling.")
|
||||||
|
|
||||||
find_package(Qt6 REQUIRED COMPONENTS Core DBus Concurrent)
|
find_package(Qt6 REQUIRED COMPONENTS Core DBus Concurrent)
|
||||||
find_package(Threads REQUIRED)
|
find_package(Threads REQUIRED)
|
||||||
@ -25,6 +26,10 @@ if(DEBUG_MODE)
|
|||||||
add_compile_definitions(-DDEBUG_MODE)
|
add_compile_definitions(-DDEBUG_MODE)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(PROFILING_MODE)
|
||||||
|
add_compile_definitions(-DDPROFILING_MODE)
|
||||||
|
endif()
|
||||||
|
|
||||||
add_subdirectory(src)
|
add_subdirectory(src)
|
||||||
add_subdirectory(plugins)
|
add_subdirectory(plugins)
|
||||||
add_subdirectory(apps)
|
add_subdirectory(apps)
|
||||||
|
@ -8,6 +8,10 @@
|
|||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include "dbus/applicationmanager1service.h"
|
#include "dbus/applicationmanager1service.h"
|
||||||
#include "cgroupsidentifier.h"
|
#include "cgroupsidentifier.h"
|
||||||
|
#include <chrono>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
Q_LOGGING_CATEGORY(DDEAMProf, "dde.am.prof", QtInfoMsg)
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
void registerComplexDbusType()
|
void registerComplexDbusType()
|
||||||
@ -21,6 +25,7 @@ void registerComplexDbusType()
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
auto start = std::chrono::high_resolution_clock::now();
|
||||||
QCoreApplication app{argc, argv};
|
QCoreApplication app{argc, argv};
|
||||||
|
|
||||||
auto &bus = ApplicationManager1DBus::instance();
|
auto &bus = ApplicationManager1DBus::instance();
|
||||||
@ -43,6 +48,12 @@ int main(int argc, char *argv[])
|
|||||||
AMService.addApplication(std::move(ret).value());
|
AMService.addApplication(std::move(ret).value());
|
||||||
return false; // means to apply this function to the rest of the files
|
return false; // means to apply this function to the rest of the files
|
||||||
});
|
});
|
||||||
|
auto end = std::chrono::high_resolution_clock::now();
|
||||||
return QCoreApplication::exec();
|
qCInfo(DDEAMProf) << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << "ms";
|
||||||
|
return
|
||||||
|
#ifdef PROFILING_MODE
|
||||||
|
QCoreApplication::exec();
|
||||||
|
#else
|
||||||
|
0;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -59,8 +59,12 @@ DesktopErrorCode DesktopEntry::parseEntry(const QString &str, decltype(m_entryMa
|
|||||||
const static auto validKey =
|
const static auto validKey =
|
||||||
QString("^%1(?:\\[(?<LOCALE>%2%3?%4?%5?)\\])?$").arg(MainKey).arg(Language).arg(Country).arg(Encoding).arg(Modifier);
|
QString("^%1(?:\\[(?<LOCALE>%2%3?%4?%5?)\\])?$").arg(MainKey).arg(Language).arg(Country).arg(Encoding).arg(Modifier);
|
||||||
// example: https://regex101.com/r/hylOay/1
|
// example: https://regex101.com/r/hylOay/1
|
||||||
QRegularExpression re{validKey};
|
static QRegularExpression re = []() -> QRegularExpression {
|
||||||
re.optimize();
|
QRegularExpression tmp{validKey};
|
||||||
|
tmp.optimize();
|
||||||
|
return tmp;
|
||||||
|
}();
|
||||||
|
|
||||||
auto matcher = re.match(keyStr);
|
auto matcher = re.match(keyStr);
|
||||||
if (!matcher.hasMatch()) {
|
if (!matcher.hasMatch()) {
|
||||||
#ifdef DEBUG_MODE
|
#ifdef DEBUG_MODE
|
||||||
@ -216,8 +220,8 @@ DesktopErrorCode DesktopEntry::parse(QTextStream &stream) noexcept
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line.startsWith("[")) {
|
if (line[0] == '[') {
|
||||||
if (!line.endsWith("]")) {
|
if (!(line[line.size() - 1] == ']')) {
|
||||||
return DesktopErrorCode::GroupHeaderInvalid;
|
return DesktopErrorCode::GroupHeaderInvalid;
|
||||||
}
|
}
|
||||||
currentGroup = parserGroupHeader(line);
|
currentGroup = parserGroupHeader(line);
|
||||||
|
@ -19,10 +19,13 @@
|
|||||||
#include <QDBusObjectPath>
|
#include <QDBusObjectPath>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <QUuid>
|
#include <QUuid>
|
||||||
|
#include <QLoggingCategory>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include "constant.h"
|
#include "constant.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
Q_DECLARE_LOGGING_CATEGORY(DDEAMProf)
|
||||||
|
|
||||||
using IconMap = QMap<QString, QMap<uint, QMap<QString, QDBusUnixFileDescriptor>>>;
|
using IconMap = QMap<QString, QMap<uint, QMap<QString, QDBusUnixFileDescriptor>>>;
|
||||||
using ObjectMap = QMap<QDBusObjectPath, QStringList>;
|
using ObjectMap = QMap<QDBusObjectPath, QStringList>;
|
||||||
|
|
||||||
|
20
tools/profiling.sh
Executable file
20
tools/profiling.sh
Executable file
@ -0,0 +1,20 @@
|
|||||||
|
#!/bin/env bash
|
||||||
|
|
||||||
|
# SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: LGPL-3.0-or-later
|
||||||
|
|
||||||
|
cd "$(git rev-parse --show-toplevel)" || exit 255
|
||||||
|
|
||||||
|
BUILD_DIR=${BUILD_DIR:="build-prof"}
|
||||||
|
|
||||||
|
cmake -B "$BUILD_DIR" \
|
||||||
|
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
|
||||||
|
-DDEBUG_MODE=OFF \
|
||||||
|
-DPROFILING_MODE=ON
|
||||||
|
|
||||||
|
cmake --build "$BUILD_DIR" -j$(nproc)
|
||||||
|
|
||||||
|
QT_LOGGING_RULES="*.debug=false;*.info=false;*.warning=false" valgrind --tool=cachegrind --cachegrind-out-file="$BUILD_DIR/profiling.out" "$BUILD_DIR/apps/dde-application-manager/src/dde-application-manager"
|
||||||
|
|
||||||
|
echo "you can use Kcachegrind to check this profiling result."
|
@ -21,4 +21,4 @@ cmake --build "$BUILD_DIR" -j$(nproc)
|
|||||||
|
|
||||||
cmake --build "$BUILD_DIR" -j$(nproc) -t test
|
cmake --build "$BUILD_DIR" -j$(nproc) -t test
|
||||||
|
|
||||||
gcovr -f "src/*" --html-details "$BUILD_DIR"/coverage.html
|
gcovr -f "src/*" --html-details "$HTML_DIR"/coverage.html
|
||||||
|
Loading…
Reference in New Issue
Block a user