Skip to content

Commit

Permalink
test for catching statistics peaks + shader window bug fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
chrxh committed Nov 1, 2024
1 parent e5d81a9 commit b704e9a
Show file tree
Hide file tree
Showing 20 changed files with 141 additions and 73 deletions.
31 changes: 21 additions & 10 deletions source/Gui/AutosaveWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ void AutosaveWindow::initIntern(SimulationFacade simulationFacade, PersisterFaca
_catchPeak = _origCatchPeak;

_lastAutosaveTimepoint = std::chrono::steady_clock::now();
_lastPeakTimepoint = std::chrono::steady_clock::now();

_catchPeakProcessor = _TaskProcessor::createTaskProcessor(_persisterFacade);
_peakProcessor = _TaskProcessor::createTaskProcessor(_persisterFacade);
_peakDeserializedSimulation = std::make_shared<_SharedDeserializedSimulation>();
updateSavepointTableFromFile();
}

Expand Down Expand Up @@ -98,21 +100,22 @@ void AutosaveWindow::processBackground()
processDeleteNonPersistentSavepoint();
processCleanup();
processAutomaticSavepoints();
_peakProcessor->process();
}

void AutosaveWindow::processToolbar()
{
ImGui::SameLine();
ImGui::BeginDisabled(!_savepointTable.has_value());
if (AlienImGui::ToolbarButton(ICON_FA_SAVE)) {
if (AlienImGui::ToolbarButton(ICON_FA_PLUS)) {
onCreateSavepoint();
}
ImGui::EndDisabled();
AlienImGui::Tooltip("Create save point");

ImGui::SameLine();
ImGui::BeginDisabled(!static_cast<bool>(_selectedEntry) || _selectedEntry->state != SavepointState_Persisted);
if (AlienImGui::ToolbarButton(ICON_FA_TRASH)) {
if (AlienImGui::ToolbarButton(ICON_FA_MINUS)) {
onDeleteSavepoint(_selectedEntry);
}
AlienImGui::Tooltip("Delete save point");
Expand Down Expand Up @@ -286,7 +289,7 @@ void AutosaveWindow::onCreateSavepoint()
.zoom = Viewport::get().getZoomFactor(),
.center = Viewport::get().getCenterInWorldPos(),
.generateNameFromTimestep = true};
auto requestId = _persisterFacade->scheduleSaveSimulationToFile(senderInfo, saveData);
auto requestId = _persisterFacade->scheduleSaveSimulation(senderInfo, saveData);

auto entry = std::make_shared<_SavepointEntry>(
_SavepointEntry{.filename = "", .state = SavepointState_InQueue, .timestamp = "", .name = "", .timestep = 0, .requestId = requestId.value});
Expand Down Expand Up @@ -328,12 +331,20 @@ void AutosaveWindow::processAutomaticSavepoints()
_lastAutosaveTimepoint = std::chrono::steady_clock::now();
}

if (!_lastCatchPeakTimepoint.has_value()) {
_lastCatchPeakTimepoint = std::chrono::steady_clock::now();
}
auto minSinceLastCatchPeak = std::chrono::duration_cast<std::chrono::minutes>(std::chrono::steady_clock::now() - _lastCatchPeakTimepoint.value()).count();
if (minSinceLastCatchPeak >= 1) {
//_persisterFacade->
auto minSinceLastCatchPeak = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::steady_clock::now() - _lastPeakTimepoint).count();
if (minSinceLastCatchPeak >= 10) {
_peakProcessor->executeTask(
[&](auto const& senderId) {
return _persisterFacade->scheduleGetPeakSimulation(
SenderInfo{.senderId = senderId, .wishResultData = false, .wishErrorInfo = true},
GetPeakSimulationRequestData{
.peakDeserializedSimulation = _peakDeserializedSimulation,
.zoom = Viewport::get().getZoomFactor(),
.center = Viewport::get().getCenterInWorldPos()});
},
[&](auto const& requestId) {},
[](auto const& errors) { GenericMessageDialog::get().information("Error", errors); });
_lastPeakTimepoint = std::chrono::steady_clock::now();
}
}

Expand Down
5 changes: 3 additions & 2 deletions source/Gui/AutosaveWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class AutosaveWindow : public AlienWindow<SimulationFacade, PersisterFacade>
};
CatchPeak _origCatchPeak = CatchPeak_None;
CatchPeak _catchPeak = _origCatchPeak;
std::optional<std::chrono::steady_clock::time_point> _lastCatchPeakTimepoint;
TaskProcessor _catchPeakProcessor;
std::chrono::steady_clock::time_point _lastPeakTimepoint;
TaskProcessor _peakProcessor;
SharedDeserializedSimulation _peakDeserializedSimulation;
};
4 changes: 2 additions & 2 deletions source/Gui/FileTransferController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void FileTransferController::onOpenSimulation()
[&](auto const& senderId) {
auto senderInfo = SenderInfo{.senderId = senderId, .wishResultData = true, .wishErrorInfo = true};
auto readData = ReadSimulationRequestData{firstFilename.string()};
return _persisterFacade->scheduleReadSimulationFromFile(senderInfo, readData);
return _persisterFacade->scheduleReadSimulation(senderInfo, readData);
},
[&](auto const& requestId) {
auto const& data = _persisterFacade->fetchReadSimulationData(requestId);
Expand Down Expand Up @@ -91,7 +91,7 @@ void FileTransferController::onSaveSimulation()
[&, firstFilename = firstFilename](auto const& senderId) {
auto senderInfo = SenderInfo{.senderId = senderId, .wishResultData = false, .wishErrorInfo = true};
auto readData = SaveSimulationRequestData{firstFilename.string(), Viewport::get().getZoomFactor(), Viewport::get().getCenterInWorldPos()};
return _persisterFacade->scheduleSaveSimulationToFile(senderInfo, readData);
return _persisterFacade->scheduleSaveSimulation(senderInfo, readData);
},
[](auto const&) { },
[](auto const& criticalErrors) { GenericMessageDialog::get().information("Error", criticalErrors); });
Expand Down
4 changes: 2 additions & 2 deletions source/Gui/MainLoopController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ void MainLoopController::processFirstTick()

auto senderInfo = SenderInfo{.senderId = SenderId{StartupSenderId}, .wishResultData = true, .wishErrorInfo = true};
auto readData = ReadSimulationRequestData{Const::AutosaveFile};
_loadSimRequestId = _persisterFacade->scheduleReadSimulationFromFile(senderInfo, readData);
_loadSimRequestId = _persisterFacade->scheduleReadSimulation(senderInfo, readData);
_programState = ProgramState::LoadingScreen;

OverlayController::get().process();
Expand Down Expand Up @@ -245,7 +245,7 @@ void MainLoopController::processScheduleExit()

auto senderInfo = SenderInfo{.senderId = SenderId{StartupSenderId}, .wishResultData = true, .wishErrorInfo = false};
auto saveData = SaveSimulationRequestData{Const::AutosaveFile, Viewport::get().getZoomFactor(), Viewport::get().getCenterInWorldPos()};
_saveSimRequestId = _persisterFacade->scheduleSaveSimulationToFile(senderInfo, saveData);
_saveSimRequestId = _persisterFacade->scheduleSaveSimulation(senderInfo, saveData);
_programState = ProgramState::Exiting;
} else {
_programState = ProgramState::Finished;
Expand Down
2 changes: 2 additions & 0 deletions source/Gui/SimulationView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ float SimulationView::getBrightness() const

void SimulationView::setBrightness(float value)
{
_brightness = value;
_shader->setFloat("brightness", value);
}

Expand All @@ -263,6 +264,7 @@ float SimulationView::getContrast() const

void SimulationView::setContrast(float value)
{
_contrast = value;
_shader->setFloat("contrast", value);
}

Expand Down
12 changes: 6 additions & 6 deletions source/PersisterImpl/PersisterFacadeImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ PersisterErrorInfo _PersisterFacadeImpl::fetchError(PersisterRequestId const& id
return _worker->fetchJobError(id)->getErrorInfo();
}

PersisterRequestId _PersisterFacadeImpl::scheduleSaveSimulationToFile(SenderInfo const& senderInfo, SaveSimulationRequestData const& data)
PersisterRequestId _PersisterFacadeImpl::scheduleSaveSimulation(SenderInfo const& senderInfo, SaveSimulationRequestData const& data)
{
return scheduleRequest<_SaveSimulationRequest>(senderInfo, data);
}
Expand All @@ -66,7 +66,7 @@ SaveSimulationResultData _PersisterFacadeImpl::fetchSaveSimulationData(Persister
return fetchData<_SaveSimulationRequestResult, SaveSimulationResultData>(id);
}

PersisterRequestId _PersisterFacadeImpl::scheduleReadSimulationFromFile(SenderInfo const& senderInfo, ReadSimulationRequestData const& data)
PersisterRequestId _PersisterFacadeImpl::scheduleReadSimulation(SenderInfo const& senderInfo, ReadSimulationRequestData const& data)
{
return scheduleRequest<_ReadSimulationRequest>(senderInfo, data);
}
Expand Down Expand Up @@ -176,14 +176,14 @@ ToggleReactionNetworkResourceResultData _PersisterFacadeImpl::fetchToggleReactio
return fetchData<_ToggleReactionNetworkResourceRequestResult, ToggleReactionNetworkResourceResultData>(id);
}

PersisterRequestId _PersisterFacadeImpl::scheduleGetSimulationFromFile(SenderInfo const& senderInfo, GetSimulationRequestData const& data)
PersisterRequestId _PersisterFacadeImpl::scheduleGetPeakSimulation(SenderInfo const& senderInfo, GetPeakSimulationRequestData const& data)
{
return scheduleRequest<_GetSimulationRequest>(senderInfo, data);
return scheduleRequest<_GetPeakSimulationRequest>(senderInfo, data);
}

GetSimulationResultData _PersisterFacadeImpl::fetchGetSimulationData(PersisterRequestId const& id)
GetPeakSimulationResultData _PersisterFacadeImpl::fetchGetPeakSimulationData(PersisterRequestId const& id)
{
return fetchData<_GetSimulationRequestResult, GetSimulationResultData>(id);
return fetchData<_GetPeakSimulationRequestResult, GetPeakSimulationResultData>(id);
}

PersisterRequestId _PersisterFacadeImpl::generateNewRequestId()
Expand Down
8 changes: 4 additions & 4 deletions source/PersisterImpl/PersisterFacadeImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ class _PersisterFacadeImpl : public _PersisterFacade
std::vector<PersisterErrorInfo> fetchAllErrorInfos(SenderId const& senderId) override;
PersisterErrorInfo fetchError(PersisterRequestId const& id) override;

PersisterRequestId scheduleSaveSimulationToFile(SenderInfo const& senderInfo, SaveSimulationRequestData const& data) override;
PersisterRequestId scheduleSaveSimulation(SenderInfo const& senderInfo, SaveSimulationRequestData const& data) override;
SaveSimulationResultData fetchSaveSimulationData(PersisterRequestId const& id) override;

PersisterRequestId scheduleReadSimulationFromFile(SenderInfo const& senderInfo, ReadSimulationRequestData const& data) override;
PersisterRequestId scheduleReadSimulation(SenderInfo const& senderInfo, ReadSimulationRequestData const& data) override;
ReadSimulationResultData fetchReadSimulationData(PersisterRequestId const& id) override;

PersisterRequestId scheduleLogin(SenderInfo const& senderInfo, LoginRequestData const& data) override;
Expand Down Expand Up @@ -58,8 +58,8 @@ class _PersisterFacadeImpl : public _PersisterFacade
PersisterRequestId scheduleToggleReactionNetworkResource(SenderInfo const& senderInfo, ToggleReactionNetworkResourceRequestData const& data) override;
ToggleReactionNetworkResourceResultData fetchToggleReactionNetworkResourcesData(PersisterRequestId const& id) override;

PersisterRequestId scheduleGetSimulationFromFile(SenderInfo const& senderInfo, GetSimulationRequestData const& data) override;
GetSimulationResultData fetchGetSimulationData(PersisterRequestId const& id) override;
PersisterRequestId scheduleGetPeakSimulation(SenderInfo const& senderInfo, GetPeakSimulationRequestData const& data) override;
GetPeakSimulationResultData fetchGetPeakSimulationData(PersisterRequestId const& id) override;

private:
static auto constexpr MaxWorkerThreads = 4;
Expand Down
6 changes: 3 additions & 3 deletions source/PersisterImpl/PersisterRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "PersisterInterface/DownloadNetworkResourceRequestData.h"
#include "PersisterInterface/EditNetworkResourceRequestData.h"
#include "PersisterInterface/GetNetworkResourcesRequestData.h"
#include "PersisterInterface/GetSimulationRequestData.h"
#include "PersisterInterface/GetPeakSimulationRequestData.h"
#include "PersisterInterface/GetUserNamesForReactionRequestData.h"
#include "PersisterInterface/LoginRequestData.h"
#include "PersisterInterface/MoveNetworkResourceRequestData.h"
Expand Down Expand Up @@ -93,5 +93,5 @@ using MoveNetworkResourceRequest = std::shared_ptr<_MoveNetworkResourceRequest>;
using _ToggleReactionNetworkResourceRequest = _ConcreteRequest<ToggleReactionNetworkResourceRequestData>;
using ToggleReactionNetworkResourceRequest = std::shared_ptr<_ToggleReactionNetworkResourceRequest>;

using _GetSimulationRequest = _ConcreteRequest<GetSimulationRequestData>;
using GetSimulationRequest = std::shared_ptr<_GetSimulationRequest>;
using _GetPeakSimulationRequest = _ConcreteRequest<GetPeakSimulationRequestData>;
using GetPeakSimulationRequest = std::shared_ptr<_GetPeakSimulationRequest>;
4 changes: 2 additions & 2 deletions source/PersisterImpl/PersisterRequestResult.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "PersisterInterface/ReadSimulationResultData.h"
#include "PersisterInterface/PersisterRequestId.h"
#include "PersisterInterface/SaveSimulationResultData.h"
#include "PersisterInterface/GetSimulationResultData.h"
#include "PersisterInterface/GetPeakSimulationResultData.h"

class _PersisterRequestResult
{
Expand Down Expand Up @@ -51,4 +51,4 @@ using _DeleteNetworkResourceRequestResult = _ConcreteRequestResult<DeleteNetwork
using _EditNetworkResourceRequestResult = _ConcreteRequestResult<EditNetworkResourceResultData>;
using _MoveNetworkResourceRequestResult = _ConcreteRequestResult<MoveNetworkResourceResultData>;
using _ToggleReactionNetworkResourceRequestResult = _ConcreteRequestResult<ToggleReactionNetworkResourceResultData>;
using _GetSimulationRequestResult = _ConcreteRequestResult<GetSimulationResultData>;
using _GetPeakSimulationRequestResult = _ConcreteRequestResult<GetPeakSimulationResultData>;
41 changes: 23 additions & 18 deletions source/PersisterImpl/PersisterWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ void _PersisterWorker::processRequests(std::unique_lock<std::mutex>& lock)
processingResult = processRequest(lock, concreteRequest);
} else if (auto const& concreteRequest = std::dynamic_pointer_cast<_ToggleReactionNetworkResourceRequest>(request)) {
processingResult = processRequest(lock, concreteRequest);
} else if (auto const& concreteRequest = std::dynamic_pointer_cast<_GetSimulationRequest>(request)) {
} else if (auto const& concreteRequest = std::dynamic_pointer_cast<_GetPeakSimulationRequest>(request)) {
processingResult = processRequest(lock, concreteRequest);
}
auto inProgressJobsIter = std::ranges::find_if(
Expand Down Expand Up @@ -619,27 +619,32 @@ _PersisterWorker::PersisterRequestResultOrError _PersisterWorker::processRequest
return std::make_shared<_ToggleReactionNetworkResourceRequestResult>(request->getRequestId(), ToggleReactionNetworkResourceResultData{});
}

_PersisterWorker::PersisterRequestResultOrError _PersisterWorker::processRequest(std::unique_lock<std::mutex>& lock, GetSimulationRequest const& request)
_PersisterWorker::PersisterRequestResultOrError _PersisterWorker::processRequest(std::unique_lock<std::mutex>& lock, GetPeakSimulationRequest const& request)
{
UnlockGuard unlockGuard(lock);
try {
UnlockGuard unlockGuard(lock);

auto const& requestData = request->getData();
auto const& requestData = request->getData();

GetSimulationResultData resultData;
try {
resultData.deserializedSimulation.statistics = _simulationFacade->getStatisticsHistory().getCopiedData();
resultData.deserializedSimulation.auxiliaryData.realTime = _simulationFacade->getRealTime();
resultData.deserializedSimulation.auxiliaryData.zoom = requestData.zoom;
resultData.deserializedSimulation.auxiliaryData.center = requestData.center;
resultData.deserializedSimulation.auxiliaryData.generalSettings = _simulationFacade->getGeneralSettings();
resultData.deserializedSimulation.auxiliaryData.simulationParameters = _simulationFacade->getSimulationParameters();
resultData.deserializedSimulation.auxiliaryData.timestep = static_cast<uint32_t>(_simulationFacade->getCurrentTimestep());
resultData.deserializedSimulation.mainData = _simulationFacade->getClusteredSimulationData();
return std::make_shared<_GetSimulationRequestResult>(request->getRequestId(), resultData);
auto peakStatistics = requestData.peakDeserializedSimulation->getLastStatisticsData();

DeserializedSimulation deserializedSimulation;
deserializedSimulation.statistics = _simulationFacade->getStatisticsHistory().getCopiedData();
if (!deserializedSimulation.statistics.empty() && deserializedSimulation.statistics.back().varianceGenomeComplexity.summedValues
>= peakStatistics.varianceGenomeComplexity.summedValues) {

deserializedSimulation.auxiliaryData.realTime = _simulationFacade->getRealTime();
deserializedSimulation.auxiliaryData.zoom = requestData.zoom;
deserializedSimulation.auxiliaryData.center = requestData.center;
deserializedSimulation.auxiliaryData.generalSettings = _simulationFacade->getGeneralSettings();
deserializedSimulation.auxiliaryData.simulationParameters = _simulationFacade->getSimulationParameters();
deserializedSimulation.auxiliaryData.timestep = static_cast<uint32_t>(_simulationFacade->getCurrentTimestep());
deserializedSimulation.mainData = _simulationFacade->getClusteredSimulationData();
requestData.peakDeserializedSimulation->setDeserializedSimulation(std::move(deserializedSimulation));
}
return std::make_shared<_GetPeakSimulationRequestResult>(request->getRequestId(), GetPeakSimulationResultData());
} catch (...) {
return std::make_shared<_PersisterRequestError>(
request->getRequestId(),
request->getSenderInfo().senderId,
PersisterErrorInfo{"No valid data could be obtained from the GPU."});
request->getRequestId(), request->getSenderInfo().senderId, PersisterErrorInfo{"No valid data could be obtained from the GPU."});
}
}
2 changes: 1 addition & 1 deletion source/PersisterImpl/PersisterWorker.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class _PersisterWorker
PersisterRequestResultOrError processRequest(std::unique_lock<std::mutex>& lock, EditNetworkResourceRequest const& request);
PersisterRequestResultOrError processRequest(std::unique_lock<std::mutex>& lock, MoveNetworkResourceRequest const& request);
PersisterRequestResultOrError processRequest(std::unique_lock<std::mutex>& lock, ToggleReactionNetworkResourceRequest const& request);
PersisterRequestResultOrError processRequest(std::unique_lock<std::mutex>& lock, GetSimulationRequest const& request);
PersisterRequestResultOrError processRequest(std::unique_lock<std::mutex>& lock, GetPeakSimulationRequest const& request);

SimulationFacade _simulationFacade;

Expand Down
7 changes: 5 additions & 2 deletions source/PersisterInterface/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ add_library(PersisterInterface
EditNetworkResourceResultData.h
GetNetworkResourcesRequestData.h
GetNetworkResourcesResultData.h
GetSimulationRequestData.h
GetSimulationResultData.h
GetPeakSimulationRequestData.h
GetPeakSimulationResultData.h
GetUserNamesForReactionRequestData.h
GetUserNamesForReactionResultData.h
LegacyAuxiliaryDataParserService.cpp
Expand All @@ -36,13 +36,16 @@ add_library(PersisterInterface
SavepointTable.h
SavepointTableService.cpp
SavepointTableService.h
SaveDeserializedSimulationRequestData.h
SaveDeserializedSimulationResultData.h
SaveSimulationRequestData.h
SaveSimulationResultData.h
SenderId.h
SenderInfo.h
SerializerService.cpp
SerializerService.h
SerializedSimulation.h
SharedDeserializedSimulation.h
TaskProcessor.cpp
TaskProcessor.h
ToggleReactionNetworkResourceRequestData.h
Expand Down
10 changes: 10 additions & 0 deletions source/PersisterInterface/GetPeakSimulationRequestData.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once

#include "SharedDeserializedSimulation.h"

struct GetPeakSimulationRequestData
{
SharedDeserializedSimulation peakDeserializedSimulation;
float zoom = 1.0f;
RealVector2D center;
};
5 changes: 5 additions & 0 deletions source/PersisterInterface/GetPeakSimulationResultData.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

struct GetPeakSimulationResultData
{
};
7 changes: 0 additions & 7 deletions source/PersisterInterface/GetSimulationRequestData.h

This file was deleted.

8 changes: 0 additions & 8 deletions source/PersisterInterface/GetSimulationResultData.h

This file was deleted.

Loading

0 comments on commit b704e9a

Please sign in to comment.