From 1268c450f8579467970fe63754471e12dcef6d6e Mon Sep 17 00:00:00 2001 From: Padraig Gleeson Date: Thu, 13 Jun 2019 13:59:42 +0100 Subject: [PATCH] More details in report file saved --- src/main/java/org/lemsml/jlems/core/sim/Sim.java | 4 +++- src/main/java/org/lemsml/jlems/io/IOUtil.java | 12 +++++++++--- src/main/java/org/lemsml/jlems/io/Main.java | 2 +- src/main/java/org/lemsml/jlems/viz/VizMain.java | 2 +- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/lemsml/jlems/core/sim/Sim.java b/src/main/java/org/lemsml/jlems/core/sim/Sim.java index b1a8f748..83430843 100644 --- a/src/main/java/org/lemsml/jlems/core/sim/Sim.java +++ b/src/main/java/org/lemsml/jlems/core/sim/Sim.java @@ -50,6 +50,7 @@ public class Sim extends LemsProcess { EventManager eventManager; + public long initTime = -1; public long simulationStartTime = -1; public long simulationEndTime = -1; public long simulationSaveTime = -1; @@ -59,6 +60,7 @@ public class Sim extends LemsProcess { public Sim(String srcStr) { super(srcStr); + initTime = System.currentTimeMillis(); } public Map getDvHM() { @@ -267,7 +269,6 @@ public void run(RunConfig rc, boolean flatten) throws ConnectionError, ContentEr int nstep = (int) Math.round(rc.getRuntime() / dt); - simulationStartTime = System.currentTimeMillis(); double t = 0; times = new double[nstep+1]; @@ -278,6 +279,7 @@ public void run(RunConfig rc, boolean flatten) throws ConnectionError, ContentEr long realTimeStart = System.currentTimeMillis(); int nsDone = 0; + simulationStartTime = System.currentTimeMillis(); try{ for (int istep = 0; istep <= nstep; istep++) { diff --git a/src/main/java/org/lemsml/jlems/io/IOUtil.java b/src/main/java/org/lemsml/jlems/io/IOUtil.java index 48e2bc2e..fa2f56fc 100644 --- a/src/main/java/org/lemsml/jlems/io/IOUtil.java +++ b/src/main/java/org/lemsml/jlems/io/IOUtil.java @@ -3,6 +3,7 @@ import java.io.File; import java.io.IOException; import java.net.URL; +import java.text.SimpleDateFormat; import org.lemsml.jlems.core.logging.E; import org.lemsml.jlems.core.run.RuntimeError; @@ -17,7 +18,7 @@ public class IOUtil { - public static void saveReportAndTimesFile(Sim sim) throws ContentError, RuntimeError + public static void saveReportAndTimesFile(Sim sim, File lemsFile) throws ContentError, RuntimeError { File reportFile = null; @@ -46,12 +47,17 @@ public static void saveReportAndTimesFile(Sim sim) throws ContentError, RuntimeE for(double time: sim.times) { times.append((float)time+"\n"); } - + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try { + info.append("Simulator=jLEMS\n"); + info.append("SimulatorVersion=" + org.lemsml.jlems.io.Main.VERSION + "\n"); + info.append("SimulationFile=" + lemsFile.getAbsolutePath() + "\n"); + + info.append("StartTime=" + format.format(sim.initTime) + "\n"); + info.append("SetupTime=" + ((sim.simulationStartTime - sim.initTime) / 1000.0) + "\n"); info.append("RealSimulationTime=" + ((sim.simulationEndTime - sim.simulationStartTime) / 1000.0) + "\n"); info.append("SimulationSaveTime=" + ((sim.simulationSaveTime - sim.simulationEndTime) / 1000.0) + "\n"); - info.append("SimulatorVersion=" + org.lemsml.jlems.io.Main.VERSION + "\n"); if (reportFile != null) { FileUtil.writeStringToFile(info.toString(), reportFile); diff --git a/src/main/java/org/lemsml/jlems/io/Main.java b/src/main/java/org/lemsml/jlems/io/Main.java index ac2756e1..308623d9 100644 --- a/src/main/java/org/lemsml/jlems/io/Main.java +++ b/src/main/java/org/lemsml/jlems/io/Main.java @@ -111,7 +111,7 @@ public static void main(String[] argv) throws ConnectionError, ContentError, Run E.info("Finished reading, building, running and displaying the LEMS model"); } - IOUtil.saveReportAndTimesFile(sim); + IOUtil.saveReportAndTimesFile(sim, simFile); } diff --git a/src/main/java/org/lemsml/jlems/viz/VizMain.java b/src/main/java/org/lemsml/jlems/viz/VizMain.java index af644cac..f814d3dd 100644 --- a/src/main/java/org/lemsml/jlems/viz/VizMain.java +++ b/src/main/java/org/lemsml/jlems/viz/VizMain.java @@ -124,6 +124,6 @@ public Sim importFile(File simFile) throws LEMSException { E.info("Finished reading, building, running and displaying the LEMS model"); } - IOUtil.saveReportAndTimesFile(sim); + IOUtil.saveReportAndTimesFile(sim, simFile); } }