mirror of
https://codeberg.org/vyn/mirai.git
synced 2025-07-03 01:33:19 +00:00
Add simple debug timer
This commit is contained in:
parent
723345b21a
commit
d90bfbc483
2 changed files with 59 additions and 0 deletions
44
libs/cpp-utils/debug.h
Normal file
44
libs/cpp-utils/debug.h
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
/*
|
||||||
|
* Mirai. Copyright (C) 2024 Vyn
|
||||||
|
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
||||||
|
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef CPP_UTILS_DEBUG_H
|
||||||
|
#define CPP_UTILS_DEBUG_H
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <chrono>
|
||||||
|
#include <iostream>
|
||||||
|
#include <ostream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace cpputils::debug
|
||||||
|
{
|
||||||
|
|
||||||
|
class Timer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Timer() : startTime(std::chrono::high_resolution_clock::now())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void start()
|
||||||
|
{
|
||||||
|
startTime = std::chrono::high_resolution_clock::now();
|
||||||
|
}
|
||||||
|
|
||||||
|
void printTimeElapsed(const std::string &message) const
|
||||||
|
{
|
||||||
|
const auto now = std::chrono::high_resolution_clock::now();
|
||||||
|
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(now - startTime);
|
||||||
|
std::cout << "[Debug - Timer] " << message << ": " << ((double)duration.count() / 1000000)
|
||||||
|
<< " seconds" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::chrono::time_point<std::chrono::system_clock> startTime;
|
||||||
|
};
|
||||||
|
} // namespace cpputils::debug
|
||||||
|
|
||||||
|
#endif
|
|
@ -9,6 +9,7 @@
|
||||||
#include "core/TaskItem.h"
|
#include "core/TaskItem.h"
|
||||||
#include "core/TasksView.h"
|
#include "core/TasksView.h"
|
||||||
#include "core/TodoMd.h"
|
#include "core/TodoMd.h"
|
||||||
|
#include "cpp-utils/debug.h"
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
|
@ -19,9 +20,13 @@
|
||||||
|
|
||||||
Backend::Backend() : view(&mirai)
|
Backend::Backend() : view(&mirai)
|
||||||
{
|
{
|
||||||
|
cpputils::debug::Timer startDuration;
|
||||||
std::cout << "Backend created" << std::endl;
|
std::cout << "Backend created" << std::endl;
|
||||||
|
|
||||||
|
cpputils::debug::Timer readConfigDuration;
|
||||||
QDir().mkdir(QDir::homePath() + "/.config/mirai");
|
QDir().mkdir(QDir::homePath() + "/.config/mirai");
|
||||||
QFile loadFile(QDir::homePath() + "/.config/mirai/config.json");
|
QFile loadFile(QDir::homePath() + "/.config/mirai/config.json");
|
||||||
|
readConfigDuration.printTimeElapsed("Read config duration");
|
||||||
|
|
||||||
if (!loadFile.open(QIODevice::ReadOnly)) {
|
if (!loadFile.open(QIODevice::ReadOnly)) {
|
||||||
qWarning() << "Couldn't find existing config file";
|
qWarning() << "Couldn't find existing config file";
|
||||||
|
@ -43,7 +48,11 @@ Backend::Backend() : view(&mirai)
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
for (const QJsonValueRef &filePath : jsonFilesPath.toArray()) {
|
for (const QJsonValueRef &filePath : jsonFilesPath.toArray()) {
|
||||||
|
cpputils::debug::Timer loadingFileDuration;
|
||||||
mirai.loadFile(filePath.toString().toStdString());
|
mirai.loadFile(filePath.toString().toStdString());
|
||||||
|
loadingFileDuration.printTimeElapsed(
|
||||||
|
"Loading file duration of " + filePath.toString().toStdString()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto jsonTagsConfig = json["tags"];
|
auto jsonTagsConfig = json["tags"];
|
||||||
|
@ -53,8 +62,14 @@ Backend::Backend() : view(&mirai)
|
||||||
jsonTagsConfig.toObject()[jsonTagConfigKey].toObject()["color"].toString();
|
jsonTagsConfig.toObject()[jsonTagConfigKey].toObject()["color"].toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cpputils::debug::Timer updatingViewDuration;
|
||||||
view.update();
|
view.update();
|
||||||
|
updatingViewDuration.printTimeElapsed("Updating view duration");
|
||||||
|
cpputils::debug::Timer rebuildQMLTasksListDuration;
|
||||||
rebuildQMLTasksList();
|
rebuildQMLTasksList();
|
||||||
|
rebuildQMLTasksListDuration.printTimeElapsed("Rebuilding QML duration");
|
||||||
|
startDuration.printTimeElapsed("Start duration");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Backend::addTodo(QString newTodo, QString date)
|
void Backend::addTodo(QString newTodo, QString date)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue