diff --git a/VectoConsole/Program.cs b/VectoConsole/Program.cs index 34074149a9e75fb787c72126424ffeae8360b85e..556a810ff171d6034c70e646d7e31857fa091c03 100644 --- a/VectoConsole/Program.cs +++ b/VectoConsole/Program.cs @@ -28,6 +28,8 @@ Synopsis: Description: FILE1.vecto [FILE2.vecto ...]: A list of vecto-job files (with the extension: .vecto). At least one file must be given. Delimited by whitespace. + -t: output information about execution times + -mod: write mod-data in addition to sum-data -v: Shows verbose information (errors and warnings will be displayed) -vv: Shows more verbose information (infos will be displayed) -vvv: Shows debug messages (slow!) @@ -89,6 +91,8 @@ Examples: Console.Write(USAGE); return 1; } + var stopWatch = new Stopwatch(); + var timings = new Dictionary<string, double>(); // process the file list and start simulation var fileList = args; @@ -98,12 +102,18 @@ Examples: var jobContainer = new JobContainer(sumWriter); Console.WriteLine("Reading Job Files"); + stopWatch.Start(); foreach (var file in fileList.Where(f => Path.GetExtension(f) == Constants.FileExtensions.VectoJobFile)) { var runsFactory = new SimulatorFactory(SimulatorFactory.FactoryMode.DeclarationMode, file); jobContainer.AddRuns(runsFactory); } + stopWatch.Stop(); + timings.Add("Reading input files", stopWatch.Elapsed.TotalMilliseconds); + stopWatch.Reset(); Console.WriteLine("Starting simulation runs"); + + stopWatch.Start(); jobContainer.Execute(!debugEnabled); Console.CancelKeyPress += (object sender, ConsoleCancelEventArgs e) => { @@ -120,6 +130,13 @@ Examples: PrintProgress(jobContainer.GetProgress()); Thread.Sleep(250); } + stopWatch.Stop(); + timings.Add("Simulation runs", stopWatch.Elapsed.TotalMilliseconds); + + PrintProgress(jobContainer.GetProgress(), args.Contains("-t")); + if (args.Contains("-t")) { + PrintTimings(timings); + } } catch (Exception e) { Console.Error.WriteLine(e.Message); Trace.TraceError(e.ToString()); @@ -128,21 +145,40 @@ Examples: return Environment.ExitCode; } - private static void PrintProgress(Dictionary<string, double> progessData) + private static void PrintProgress(Dictionary<string, JobContainer.ProgressEntry> progessData, bool showTiming = true) { Console.SetCursorPosition(0, Console.CursorTop - NumLines); NumLines = 0; var sumProgress = 0.0; - foreach (var progress in progessData) { - Console.WriteLine(string.Format("{0,-60} {1,8:P}", progress.Key, progress.Value)); - sumProgress += progress.Value; + foreach (var progressEntry in progessData) { + if (progressEntry.Value.Success) { + Console.ForegroundColor = ConsoleColor.Green; + } else if (progressEntry.Value.Error != null) { + Console.ForegroundColor = ConsoleColor.Red; + } + var timingString = ""; + if (showTiming && progressEntry.Value.ExecTime > 0) { + timingString = string.Format("{0,9:F2}s", progressEntry.Value.ExecTime / 1000.0); + } + Console.WriteLine("{0,-60} {1,8:P}{2}", progressEntry.Key, progressEntry.Value.Progress, timingString); + Console.ResetColor(); + sumProgress += progressEntry.Value.Progress; NumLines++; } sumProgress /= NumLines; var spinner = "/-\\|"[ProgessCounter++ % 4]; var bar = new string('#', (int)(sumProgress * 100.0 / 2)); - Console.WriteLine(string.Format(" {2} [{1,-50}] [{0,6:P}]", sumProgress, bar, spinner)); + Console.WriteLine(string.Format(" {2} [{1,-50}] [{0,7:P}]", sumProgress, bar, spinner)); NumLines++; } + + private static void PrintTimings(Dictionary<string, double> timings) + { + Console.WriteLine(); + Console.WriteLine("---- timing information ----"); + foreach (var timing in timings) { + Console.Write("{0,-20}: {1:F2}s", timing.Key, timing.Value / 1000); + } + } } } \ No newline at end of file diff --git a/VectoCore/Models/Simulation/Impl/JobContainer.cs b/VectoCore/Models/Simulation/Impl/JobContainer.cs index 6edded3df13b23addbd9e0bde1a9542e8d3f8e3b..532c9f459d3b60416ae7194ad3209e9c848af505 100644 --- a/VectoCore/Models/Simulation/Impl/JobContainer.cs +++ b/VectoCore/Models/Simulation/Impl/JobContainer.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.ComponentModel; +using System.Diagnostics; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -119,9 +120,16 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl } } - public Dictionary<string, double> GetProgress() + public Dictionary<string, ProgressEntry> GetProgress() { - return Runs.ToDictionary(jobEntry => jobEntry.Run.Name, jobEntry => jobEntry.Progress); + return Runs.ToDictionary(jobEntry => jobEntry.Run.Name, entry => new ProgressEntry() { + Progress = entry.Progress, + Done = entry.Done, + ExecTime = entry.ExecTime, + Success = entry.Success, + Canceled = entry.Canceled, + Error = entry.ExecException + }); } public bool AllCompleted @@ -129,7 +137,17 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl get { return (Runs.Count(x => x.Done == true) == Runs.Count()); } } - internal class JobEntry + public class ProgressEntry + { + public double Progress; + public double ExecTime; + public Exception Error; + public bool Canceled; + public bool Success; + public bool Done; + } + + internal class JobEntry : LoggingObject { public IVectoRun Run; public JobContainer Container; @@ -138,19 +156,30 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl public bool Started; public bool Success; public bool Canceled; + public double ExecTime; + public Exception ExecException; public BackgroundWorker Worker; public void DoWork(object sender, DoWorkEventArgs e) { + var stopWatch = new Stopwatch(); + stopWatch.Start(); var worker = sender as BackgroundWorker; - Run.Run(worker); + try { + Run.Run(worker); + } catch (Exception ex) { + Log.Error(ex, "Error during simulation run!"); + ExecException = ex; + } if (worker != null && worker.CancellationPending) { e.Cancel = true; Canceled = true; } + stopWatch.Stop(); Success = Run.FinishedWithoutErrors; Done = true; + ExecTime = stopWatch.Elapsed.TotalMilliseconds; Container.JobCompleted(this); } diff --git a/VectoCore/Utils/SI.cs b/VectoCore/Utils/SI.cs index 40035c76940b770ed6542f39f848a66b019115e8..e17a8fb4c99f5df99f876e6c3da8be09a898f1b1 100644 --- a/VectoCore/Utils/SI.cs +++ b/VectoCore/Utils/SI.cs @@ -1656,11 +1656,8 @@ namespace TUGraz.VectoCore.Utils if (Numerator.SequenceEqual(si.Numerator) && Denominator.SequenceEqual(si.Denominator)) { return true; } - return ToBasicUnits() - .Denominator.OrderBy(x => x) - .SequenceEqual(si.ToBasicUnits().Denominator.OrderBy(x => x)) - && - ToBasicUnits().Numerator.OrderBy(x => x).SequenceEqual(si.ToBasicUnits().Numerator.OrderBy(x => x)); + return ToBasicUnits().Denominator.OrderBy(x => x).SequenceEqual(si.ToBasicUnits().Denominator.OrderBy(x => x)) + && ToBasicUnits().Numerator.OrderBy(x => x).SequenceEqual(si.ToBasicUnits().Numerator.OrderBy(x => x)); } /// <summary>