From b58509172d51d66154f356d8618b9aa393f575ce Mon Sep 17 00:00:00 2001 From: Scott Bilas Date: Wed, 10 Apr 2024 06:36:57 +0200 Subject: [PATCH] Add timing info --- src/Stale.Cli/StaleCli.cs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/Stale.Cli/StaleCli.cs b/src/Stale.Cli/StaleCli.cs index b06426f..3d095d2 100644 --- a/src/Stale.Cli/StaleCli.cs +++ b/src/Stale.Cli/StaleCli.cs @@ -10,6 +10,7 @@ const string programVersion = "0.1"; const int jsonVersion = 1; +var programStart = DateTime.Now; using var ctx = new Context(); // ReSharper disable AccessToDisposedClosure @@ -77,7 +78,7 @@ ctx.VerboseDump(ctx.Options); if (ctx.Options.CmdRecord) - return (int)await Record(ctx.Options.ArgRecorded, ctx.Options.ArgCommand!, ctx.Options.ArgArg.ToArray()); + return Return(Record(ctx.Options.ArgRecorded, ctx.Options.ArgCommand!, [..ctx.Options.ArgArg])); if (ctx.Options.CmdPlay) { @@ -130,12 +131,14 @@ ctx.VerboseLine($"Playing back '{ctx.Options.ArgRecorded}' at original speed"); } - return (int)await Play(ctx.Options.ArgRecorded!, ratio, delay, ctx.CancelToken); + return Return(Play(ctx.Options.ArgRecorded!, ratio, delay, ctx.CancelToken)); } // $$$ DO THE REAL PROGRAM HERE throw new UnreachableCodeException(); + + //Return(...); } catch (CliErrorException x) { @@ -148,13 +151,26 @@ return (int)CliExitCode.ErrorSoftware; } +int Return(Task task) +{ + var result = task.Result; + + if (ctx.IsVerbose) + { + var elapsed = DateTime.Now - programStart; + ctx.VerboseLine($"Finished in {elapsed.TotalSeconds:F3}s with exit code {result} ({(int)result})"); + } + + return (int)result; +} + async Task Record(string? recordedPath, string command, IReadOnlyList args) { var (cmd, captures) = Exec(command, args); if (ctx.IsVerbose) { - ctx.VerboseLine($">{cmd.Id} $ {command} {args}"); + ctx.VerboseLine($">{cmd.Id} $ {command} {CliUtility.CommandLineArgsToString(args)}"); ctx.VerboseLine($" (Recording to ${ctx.Options.ArgRecorded ?? "stdout"})"); }