paramerized show time and debug in global config

Also some additional time measurements in the qt app.
This commit is contained in:
jorenchik
2024-10-27 12:12:00 +02:00
parent 09a25d9216
commit 6359d97ba5
13 changed files with 97 additions and 44 deletions

View File

@@ -1,6 +1,5 @@
#include <cstdio>
#include <ctime>
#include <format>
#include <fstream>
#include <iostream>
#include <map>
@@ -64,6 +63,7 @@
#include <QShortcut>
#include <QWidget>
#include "config.h"
#include "settings.h"
#include "mdemList.h"
#include "trainWindow.h"
@@ -573,6 +573,7 @@ void reloadMdem(std::string path) {
return;
}
start = std::chrono::high_resolution_clock::now();
auto file = std::ifstream(path);
std::string content;
@@ -589,7 +590,13 @@ void reloadMdem(std::string path) {
std::stringstream buffer;
buffer << file.rdbuf();
content = buffer.str();
auto res = transpile(content, true);
end = std::chrono::high_resolution_clock::now();
showTimes = settings->value(SETTING_SHOW_TIMES).toBool();
if (showTimes) {
std::cout << showTime("I/O time") << std::endl;
}
debug = settings->value(SETTING_DEBUG).toBool();
auto res = transpile(content);
currentMdemBuffer->error = res.error.length() > 0;
if (res.error == "") {
@@ -599,7 +606,11 @@ void reloadMdem(std::string path) {
auto timezoneOffset = settings->value("timezone").toInt();
currentMdemBuffer->trainedAt = res.value.lastTrainedAt - 3600 * timezoneOffset;
}
std::cout << std::format("Last trained at: {}", currentMdemBuffer->trainedAt) << std::endl;
if (settings->value(SETTING_DEBUG).toBool()) {
std::cout << std::format("Last trained at: {}", currentMdemBuffer->trainedAt)
<< std::endl;
}
currentMdemBuffer->questions = res.value.questions;
errorView->box.hide();
@@ -676,7 +687,9 @@ void pickDirectory(QString directory) {
}
void setupEditorSave() {
auto res = transpile(editor->text().toStdString(), true);
debug = settings->value(SETTING_DEBUG).toBool();
showTimes = settings->value(SETTING_SHOW_TIMES).toBool();
auto res = transpile(editor->text().toStdString());
if (res.error.length() > 0) {
currentMdemBuffer->trainedAt = 0;
for (auto question: res.value.questions) {
@@ -740,12 +753,19 @@ void setupEditorSave() {
};
void saveMdem() {
start = std::chrono::high_resolution_clock::now();
auto filename = getFilename(currentMdem);
std::ofstream out(currentMdem);
out << outputMdem(currentMdemBuffer->questions, currentMdemBuffer->trainedAt);
updateMdemInfo(getFilename(currentMdem), false);
}
end = std::chrono::high_resolution_clock::now();
showTimes = settings->value(SETTING_SHOW_TIMES).toBool();
if (showTimes) {
std::cout << showTime("Saving time") << std::endl;
}
}
QMainWindow *initMdemListWindow() {
QMainWindow* window = new QMainWindow;