Browse Source

Set waiting time after signal with flag --signal-timeout

tempestpy_adaptions
Matthias Volk 5 years ago
parent
commit
0dd1c70e12
  1. 7
      src/storm/settings/modules/ResourceSettings.cpp
  2. 10
      src/storm/settings/modules/ResourceSettings.h
  3. 8
      src/storm/utility/SignalHandler.cpp

7
src/storm/settings/modules/ResourceSettings.cpp

@ -15,11 +15,14 @@ namespace storm {
const std::string ResourceSettings::timeoutOptionShortName = "t";
const std::string ResourceSettings::printTimeAndMemoryOptionName = "timemem";
const std::string ResourceSettings::printTimeAndMemoryOptionShortName = "tm";
const std::string ResourceSettings::signalWaitingTimeOptionName = "signal-timeout";
ResourceSettings::ResourceSettings() : ModuleSettings(moduleName) {
this->addOption(storm::settings::OptionBuilder(moduleName, timeoutOptionName, false, "If given, computation will abort after the timeout has been reached.").setIsAdvanced().setShortName(timeoutOptionShortName)
.addArgument(storm::settings::ArgumentBuilder::createUnsignedIntegerArgument("time", "Seconds after which to timeout.").setDefaultValueUnsignedInteger(0).build()).build());
this->addOption(storm::settings::OptionBuilder(moduleName, printTimeAndMemoryOptionName, false, "Prints CPU time and memory consumption at the end.").setShortName(printTimeAndMemoryOptionShortName).build());
this->addOption(storm::settings::OptionBuilder(moduleName, signalWaitingTimeOptionName, false, "If given, computation will abort after the timeout has been reached.").setIsAdvanced()
.addArgument(storm::settings::ArgumentBuilder::createUnsignedIntegerArgument("time", "Seconds after which to exit the program.").setDefaultValueUnsignedInteger(3).build()).build());
}
bool ResourceSettings::isTimeoutSet() const {
@ -34,6 +37,10 @@ namespace storm {
return this->getOption(printTimeAndMemoryOptionName).getHasOptionBeenSet();
}
uint_fast64_t ResourceSettings::getSignalWaitingTimeInSeconds() const {
return this->getOption(signalWaitingTimeOptionName).getArgumentByName("time").getValueAsUnsignedInteger();
}
}
}
}

10
src/storm/settings/modules/ResourceSettings.h

@ -39,6 +39,15 @@ namespace storm {
*/
uint_fast64_t getTimeoutInSeconds() const;
/*!
* Retrieves the waiting time of the program after a signal.
* If a signal to abort is handled, the program should terminate.
* However, it waits the given number of seconds before it is killed to allow for printing preliminary results.
*
* @return The number of seconds after which to exit the program.
*/
uint_fast64_t getSignalWaitingTimeInSeconds() const;
// The name of the module.
static const std::string moduleName;
@ -48,6 +57,7 @@ namespace storm {
static const std::string timeoutOptionShortName;
static const std::string printTimeAndMemoryOptionName;
static const std::string printTimeAndMemoryOptionShortName;
static const std::string signalWaitingTimeOptionName;
};
}
}

8
src/storm/utility/SignalHandler.cpp

@ -3,12 +3,15 @@
#include <csignal>
#include <iostream>
#include "storm/settings/SettingsManager.h"
#include "storm/settings/modules/ResourceSettings.h"
namespace storm {
namespace utility {
namespace resources {
// Maximal waiting time after abort signal before terminating
const int maxWaitTime = 3;
int maxWaitTime = 0;
SignalInformation::SignalInformation() : terminate(false), lastSignal(0) {
}
@ -57,6 +60,9 @@ namespace storm {
}
void installSignalHandler() {
// Set the waiting time
maxWaitTime = storm::settings::getModule<storm::settings::modules::ResourceSettings>().getSignalWaitingTimeInSeconds();
// We use the newer sigaction instead of signal
struct sigaction sa;
sa.sa_handler = signalHandler;
Loading…
Cancel
Save