/// <summary> /// Submits a diagnostic message to the message queue /// </summary> /// <param name="msg">The source message</param> /// <param name="severity">The diagnostic severity level that, if specified, /// replaces the exising source message severity prior to queue submission</param> protected void Trace(AppMsg msg, SeverityLevel?severity = null) { if (TraceEnabled) { Enqueue(msg.WithLevel(severity ?? SeverityLevel.Babble)); } }
/// <summary> /// Submits a diagnostic message to the queue related to performance/benchmarking /// </summary> /// <param name="msg">The message to submit</param> protected void TracePerf(string msg) { if (TraceEnabled) { Enqueue(AppMsg.Define($"{msg}", SeverityLevel.Benchmark)); } }
protected void Trace(string msg, SeverityLevel?severity = null) { if (TraceEnabled) { Enqueue(AppMsg.Define($"{msg}", severity ?? SeverityLevel.Babble)); } }
public static void dispatch(string[] args) { try { var parts = ApiRuntimeLoader.parts(Index <PartId> .Empty); term.inform(AppMsg.status(text.prop("PartCount", parts.Components.Length))); var rng = Rng.@default(); using var wf = WfAppLoader.load(parts, args).WithSource(rng); if (args.Length == 0) { wf.Status("usage: run <command> [options]"); var settings = wf.Settings; wf.Row(settings.Format()); } else { wf.Status("Dispatching"); Reactor.create(wf).Dispatch(args); } } catch (Exception e) { term.error(e); } }
/// <summary> /// Submits a diagnostic message to the queue related to performance/benchmarking /// </summary> /// <param name="msg">The message to emit</param> protected void TracePerf(AppMsg msg) { if (TraceEnabled) { Enqueue(msg.WithLevel(SeverityLevel.Benchmark)); } }
/// <summary> /// Executes the tests defined by a host type /// </summary> /// <param name="host">The host type</param> /// <param name="filters">Filters the host's test if nonempty</param> void Run(Type host, string[] filters) { if (!HasAny(host, filters)) { return; } try { var execTime = Duration.Zero; var runtimer = stopwatch(); Trace(AppMsg.Define($"Creating unit {host.Name}", SeverityLevel.Babble)); var instance = host.CreateInstance <IUnitTest>(); instance.Configure(Config); var hostpath = host.DisplayName(); if (instance.Enabled) { iter(Tests(host), t => execTime += Run(instance, hostpath, t)); } Enqueue(instance.Benchmarks); print(AppMsg.Define($"{host.Name} exectime {execTime.Ms} ms, runtime = {snapshot(runtimer).Ms} ms", SeverityLevel.Info)); } catch (Exception e) { error($"Host execution failed: {e}", this); } }
public string ReadLine(AppMsg msg = null) { if (msg != null) { WriteMessage(msg, false); } return(Console.ReadLine()); }
public AppException(string msg, string caller, string file, int?line) : base(msg.ToString()) { this.Message = AppMsg.Define($"{caller} line {line} {file}: {msg}", SeverityLevel.Error, caller, file, line); this.Caller = Message.Caller; this.File = Message.CallerFile; this.Line = Message.FileLine; }
public AppException(AppMsg msg) : base(msg.ToString()) { this.Message = msg; this.Caller = Message.Caller; this.File = Message.CallerFile; this.Line = Message.FileLine; }
protected void Trace(string title, string msg, int?tpad = null, SeverityLevel?severity = null) { var titleFmt = tpad.Map(pad => title.PadRight(pad), () => title.PadRight(20)); if (TraceEnabled) { Enqueue(AppMsg.Define($"{titleFmt}: {msg}", severity ?? SeverityLevel.Babble)); } }
public char ReadKey(AppMsg msg = null) { if (msg != null) { WriteMessage(msg, false); } return(Console.ReadKey().KeyChar); }
public void WriteError(AppMsg msg) { lock (locker) { var fg = Console.ForegroundColor; Console.ForegroundColor = ForeColor(msg.Level); Console.Error.Write(msg); Console.Error.Write(zfunc.eol()); Console.ForegroundColor = fg; } }
/// <summary> /// Submits a diagnostic message to the queue related to performance/benchmarking /// </summary> /// <param name="msg">The message to emit</param> protected void TracePerf(string label, Duration time, int?cycles = null, int?samples = null, int?pad = null) { if (TraceEnabled) { var cyclesFmt = cycles != null ? (cycles.ToString() + " cycles").PadRight(16) : string.Empty; var samplesFmt = samples != null ? (samples.ToString() + " samples").PadRight(16) : string.Empty; var content = concat( $"{label}".PadRight(pad ?? 30), cyclesFmt, samplesFmt, $"{time.Ms} ms" ); Enqueue(AppMsg.Define(content, SeverityLevel.Benchmark)); } }
static AppMsg Describe(IMetricComparison comparison) { var title = $"{comparison.LeftTitle} / {comparison.RightTitle}"; var delta = comparison.LeftMetrics.WorkTime - comparison.RightMetrics.WorkTime; var leftDuration = comparison.LeftMetrics.WorkTime; var rightDuration = comparison.RightMetrics.WorkTime; var ratio = Math.Round((double)leftDuration.TimerTicks / (double)rightDuration.TimerTicks, 4); var description = concat( $"{title}", $" | Left Time = {leftDuration}", $" | Right Time = {rightDuration}", $" | Difference = {delta}", $" | Performance Ratio = {ratio}" ); return(AppMsg.Define(description, SeverityLevel.Benchmark)); }
public void WriteMessage(AppMsg msg, bool cr = true) { if (msg.Level == SeverityLevel.Error) { WriteError(msg, ForeColor(msg.Level)); } else { if (cr) { WriteLine(msg, ForeColor(msg.Level)); } else { Write(msg, ForeColor(msg.Level)); } } }
Duration Run(IUnitTest unit, string hostpath, MethodInfo test) { var exectime = Duration.Zero; var messages = new List <AppMsg>(); var testName = $"{hostpath}/{test.DisplayName()}"; try { messages.Add(AppMsg.Define($"{testName} executing", SeverityLevel.HiliteBL)); var sw = stopwatch(); test.Invoke(unit, null); exectime = snapshot(sw); messages.AddRange(unit.DequeueMessages()); messages.Add(AppMsg.Define($"{testName} executed. {exectime.Ms}ms", SeverityLevel.Info)); } catch (Exception e) { messages.AddRange(unit.DequeueMessages()); if (e.InnerException is ClaimException claim) { messages.Add(claim.Message); } else if (e.InnerException is AppException app) { messages.Add(app.Message); } else { messages.Add(ErrorMessages.Unanticipated(e ?? e.InnerException)); } messages.Add(AppMsg.Define($"{testName} failed", SeverityLevel.Error)); } finally { print(messages); if (PersistResults) { log(messages, LogArea.Test); } } return(exectime); }
public static IReadOnlyList <AppMsg> FormatMessages(this IEnumerable <MetricComparisonRecord> src, char delimiter = '|', bool digitcommas = false) { var records = src.ToList(); if (records.Count == 0) { return new AppMsg[] {} } ; var messages = new List <AppMsg>(records.Count + 1); messages.Add(AppMsg.Define(MetricComparisonRecord.GetHeaderText(delimiter), SeverityLevel.HiliteCL)); foreach (var record in src) { messages.Add(record.FormatMessage(delimiter, digitcommas)); } return(messages); }
public static AppMsg FormatMessage(this MetricComparisonRecord src, char delimiter = '|', bool digitcommas = false) => AppMsg.Define(src.DelimitedText(delimiter), SeverityLevel.Benchmark);
protected void TypeCaseEnd <M, N, S>([CallerMemberName] string caller = null) where M : ITypeNat, new() where N : ITypeNat, new() where S : struct => Enqueue(AppMsg.Define($"{typeof(T).Name}/{caller}<N{nati<M>()}xN{nati<N>()}:{typeof(S).DisplayName()}> succeeded", SeverityLevel.HiliteCL));
protected void NatCaseStart <N, A>([CallerMemberName] string caller = null) where N : ITypeNat, new() => Enqueue(AppMsg.Define($"{typeof(T).DisplayName()}/{caller}<N{nati<N>()},{typeof(A).DisplayName()}> executing", SeverityLevel.HiliteCL));
protected void TypeCaseEnd <A, B>([CallerMemberName] string caller = null) => Enqueue(AppMsg.Define($"{typeof(T).DisplayName()}/{caller}<{typeof(A).DisplayName()},{typeof(B).DisplayName()}> succeeded", SeverityLevel.HiliteCL));
protected void TypeCaseEnd <C>(AppMsg msg, [CallerMemberName] string caller = null) => Enqueue(AppMsg.Define($"{typeof(T).DisplayName()}/{caller}<{typeof(C).DisplayName()}> succeeded: {msg}", SeverityLevel.HiliteCL));
protected void TypeCaseStart <C>([CallerMemberName] string caller = null) => Enqueue(AppMsg.Define($"{typeof(T).DisplayName()}/{caller}<{typeof(C).DisplayName()}> executing", SeverityLevel.HiliteCL));
public static unsafe bool notnull(void *p, string msg = null, [Member] string caller = null, [File] string file = null, [Line] int?line = null) => (p != null) ? true : throw new ArgumentNullException(AppMsg.Define($"Pointer was null", SeverityLevel.Error, caller, file, line).ToString());
static AppMsg CompleteMsg <T>(ITimeSeries <T> series, Duration runtime) where T : struct => AppMsg.Define($"Series Id = {series.Id} | Last Term = {series.Observed} | Evolution Time = {runtime.Ms} ms", SeverityLevel.Info);
public static void fail(string msg, [Member] string caller = null, [File] string file = null, [Line] int?line = null) => throw failed(ClaimOpKind.Fail, AppMsg.Error(msg, caller, file, line));
internal static AppMsg BenchmarkEnd(OpId opid, long totalOpCount, Duration totalDuration) => AppMsg.Define(concat( $"{opid} summary".PadRight(28), Pipe, "Total Op Count", Eq, $"{totalOpCount}".PadRight(12), Pipe, "Total Duration", Eq, $"{totalDuration}"), SeverityLevel.HiliteCL);
public static ClaimException Define(ClaimOpKind op, AppMsg msg) => new ClaimException(op, msg);
public void Log(AppMsg src) { lock (locker) LogPath().Append(src.ToString()); }
ClaimException(ClaimOpKind kind, AppMsg msg) : base(msg.WithPrependedContent("fail(").WithAppendedContent(")")) { this.OpKind = kind; }