diff --git a/matsim/src/main/java/org/matsim/core/config/groups/ControllerConfigGroup.java b/matsim/src/main/java/org/matsim/core/config/groups/ControllerConfigGroup.java index 9cbde96f1e3..c84d9eee16c 100644 --- a/matsim/src/main/java/org/matsim/core/config/groups/ControllerConfigGroup.java +++ b/matsim/src/main/java/org/matsim/core/config/groups/ControllerConfigGroup.java @@ -79,6 +79,8 @@ public enum CleanIterations { private static final String COMPRESSION_TYPE = "compressionType"; private static final String EVENT_TYPE_TO_CREATE_SCORING_FUNCTIONS = "createScoringFunctionType"; + private static final String MEMORY_OBSERVER_INTERVAL = "memoryObserverInterval"; + /*package*/ static final String MOBSIM = "mobsim"; public enum MobsimType {qsim, JDEQSim, hermes} @@ -109,6 +111,8 @@ public enum MobsimType {qsim, JDEQSim, hermes} private CleanIterations cleanItersAtEnd = CleanIterations.keep; + private int memoryObserverInterval = 60; + public ControllerConfigGroup() { super(GROUP_NAME); } @@ -151,6 +155,7 @@ public final Map getComments() { "to a file. `0' disables snapshots writing completely"); map.put(DUMP_DATA_AT_END, "true if at the end of a run, plans, network, config etc should be dumped to a file"); map.put(CLEAN_ITERS_AT_END, "Defines what should be done with the ITERS directory when a simulation finished successfully"); + map.put(MEMORY_OBSERVER_INTERVAL, "Defines the interval for printing memory usage to the log in [seconds]. Must be positive. Defaults to 60."); return map; } @@ -427,6 +432,17 @@ public EventTypeToCreateScoringFunctions getEventTypeToCreateScoringFunctions() public void setEventTypeToCreateScoringFunctions(EventTypeToCreateScoringFunctions eventTypeToCreateScoringFunctions) { this.eventTypeToCreateScoringFunctions = eventTypeToCreateScoringFunctions; } + + @StringGetter(MEMORY_OBSERVER_INTERVAL) + public int getMemoryObserverInterval() { + return memoryObserverInterval; + } + + @StringSetter(MEMORY_OBSERVER_INTERVAL) + public void setMemoryObserverInterval(int memoryObserverInterval) { + this.memoryObserverInterval = memoryObserverInterval; + } + // --- int writePlansUntilIteration = 1 ; public int getWritePlansUntilIteration() { @@ -450,5 +466,8 @@ protected void checkConsistency(Config config) { log.warn( "this is not recommended, as it might result in a directory containing output from several model runs" ); log.warn( "prefer the options "+OverwriteFileSetting.deleteDirectoryIfExists+" or "+OverwriteFileSetting.failIfDirectoryExists ); } + if(config.controller().getMemoryObserverInterval() < 0) { + log.warn("Memory observer interval is negative. Simulation will most likely crash."); + } } } diff --git a/matsim/src/main/java/org/matsim/core/controler/AbstractController.java b/matsim/src/main/java/org/matsim/core/controler/AbstractController.java index 93c1680a231..a1c008e31ba 100644 --- a/matsim/src/main/java/org/matsim/core/controler/AbstractController.java +++ b/matsim/src/main/java/org/matsim/core/controler/AbstractController.java @@ -73,7 +73,7 @@ final void setupOutputDirectory(OutputDirectoryHierarchy controlerIO) { } protected final void run(final Config config) { - MemoryObserver.start(60); + MemoryObserver.start(config.controller().getMemoryObserverInterval()); MatsimRuntimeModifications.MyRunnable runnable = new MatsimRuntimeModifications.MyRunnable() { @Override public void run() throws MatsimRuntimeModifications.UnexpectedShutdownException {