Skip to content

Commit

Permalink
simulation: add function that checks for overruns
Browse files Browse the repository at this point in the history
Signed-off-by: Niklas Eiling <niklas.eiling@eonerc.rwth-aachen.de>
  • Loading branch information
n-eiling committed Jul 29, 2024
1 parent bb6b799 commit 2aae38b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions dpsim/include/dpsim/Simulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ class Simulation : public CPS::AttributeList {
void addLogger(DataLogger::Ptr logger) { mLoggers.push_back(logger); }
/// Write step time measurements to log file
void logStepTimes(String logName);
/// Check for overruns
void checkForOverruns(String logName);

/// Write LU decomposition times measurements to log file
void logLUTimes();
Expand Down
17 changes: 16 additions & 1 deletion dpsim/src/Simulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ void Simulation::prepSchedule() {
mTasks.push_back(logger->getTask());
}
if (!mScheduler) {
mScheduler = std::make_shared<SequentialScheduler>();
mScheduler = std::make_shared<SequentialScheduler>("taskTimes");
}
mScheduler->resolveDeps(mTasks, mTaskInEdges, mTaskOutEdges);
}
Expand Down Expand Up @@ -431,6 +431,21 @@ void Simulation::logStepTimes(String logName) {
stepTimeSum / mStepTimes.size());
}

void Simulation::checkForOverruns(String logName) {
auto stepTimeLog = Logger::get(logName, Logger::Level::info);
Logger::setLogPattern(stepTimeLog, "%v");
stepTimeLog->info("overruns");

int overruns = 0;
for (auto meas : mStepTimes) {
if (meas > **mTimeStep) {
overruns++;
SPDLOG_LOGGER_INFO(mLog, "overrun detected {}: {:.9f}", overruns, meas);
}
}
SPDLOG_LOGGER_INFO(mLog, "Detected {} overruns.", overruns);
}

void Simulation::logLUTimes() {
for (auto solver : mSolvers) {
solver->logLUTimes();
Expand Down

0 comments on commit 2aae38b

Please sign in to comment.