/// <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)); } }
/// <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 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; }
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)); } }
/// <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)); }
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 AppMsg NotFalse(string msg, string caller, string file, int?line) => AppMsg.Define($"{msg ?? "The source value is is not false"}", SeverityLevel.Error, caller, file, line);
public static AppMsg FileDoesNotExist(FilePath path, [Caller] string caller = null, [File] string file = null, [Line] int?line = null) => AppMsg.Define($"The file {path} does not exist", SeverityLevel.Error, caller, file, line);
public static AppMsg Unanticipated(Exception e, [Caller] string caller = null, [File] string file = null, [Line] int?line = null) => AppMsg.Define(e?.ToString() ?? "Heh?", SeverityLevel.Error, caller, file, line);
public static AppMsg TooManyBytes(ByteSize requested, ByteSize available, string caller, string file, int?line) => AppMsg.Define($"The number of bytes, {requested} exceeds the maximum available, {available}", SeverityLevel.Error, caller, file, line);
public static AppMsg IndexOutOfRange(int index, int min, int max, string caller, string file, int?line) => AppMsg.Define($"The index {index} is not between {min} and {max}", SeverityLevel.Error, caller, file, line);
protected void TypeCaseEnd <C>(AppMsg msg, [CallerMemberName] string caller = null) => Enqueue(AppMsg.Define($"{typeof(T).DisplayName()}/{caller}<{typeof(C).DisplayName()}> succeeded: {msg}", SeverityLevel.HiliteCL));
public static bool eq(int lhs, int rhs, string msg, [Member] string caller = null, [File] string file = null, [Line] int?line = null) => lhs == rhs ? true : throw failed(ClaimOpKind.Eq, AppMsg.Define(msg, SeverityLevel.Error, caller, file, line));
public static AppMsg NotNonzero(string caller, string file, int?line) => AppMsg.Define($"Value is not nonzero", SeverityLevel.Error, caller, file, line);
public static AppMsg ItemsNotEqual(int index, object lhs, object rhs, string caller, string file, int?line) => AppMsg.Define($"Equality failure: lhs[{index}] = {lhs} != rhs[{index}] = {rhs}", SeverityLevel.Error, caller, file, line);
public static AppMsg NotLessThanOrEqual(object lhs, object rhs, string caller, string file, int?line) => AppMsg.Define($"!({lhs} <= {rhs})", SeverityLevel.Error, caller, file, line);
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());
public static AppMsg EmptySourceSpan(string caller, string file, int?line) => AppMsg.Define($"The source span was empty", SeverityLevel.Error, caller, file, line);
protected void TypeCaseStart <C>([CallerMemberName] string caller = null) => Enqueue(AppMsg.Define($"{typeof(T).DisplayName()}/{caller}<{typeof(C).DisplayName()}> executing", SeverityLevel.HiliteCL));
public static AppMsg LengthMismatch(int lhs, int rhs, string caller, string file, int?line) => AppMsg.Define($"Length mismatch: {lhs} != {rhs}", SeverityLevel.Error, caller, file, line);
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));
public static AppMsg NotBetween <T>(T x, T lhs, T rhs, string caller, string file, int?line) => AppMsg.Define($"The source value {x} is not between {lhs} and {rhs}", SeverityLevel.Error, caller, file, line);