Beispiel #1
0
 /// <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));
     }
 }
Beispiel #2
0
 /// <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));
     }
 }
Beispiel #3
0
 protected void Trace(string msg, SeverityLevel?severity = null)
 {
     if (TraceEnabled)
     {
         Enqueue(AppMsg.Define($"{msg}", severity ?? SeverityLevel.Babble));
     }
 }
Beispiel #4
0
 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);
     }
 }
Beispiel #5
0
 /// <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));
     }
 }
Beispiel #6
0
        /// <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);
            }
        }
Beispiel #7
0
 public string ReadLine(AppMsg msg = null)
 {
     if (msg != null)
     {
         WriteMessage(msg, false);
     }
     return(Console.ReadLine());
 }
Beispiel #8
0
 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;
 }
Beispiel #9
0
 public AppException(AppMsg msg)
     : base(msg.ToString())
 {
     this.Message = msg;
     this.Caller  = Message.Caller;
     this.File    = Message.CallerFile;
     this.Line    = Message.FileLine;
 }
Beispiel #10
0
        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));
            }
        }
Beispiel #11
0
        public char ReadKey(AppMsg msg = null)
        {
            if (msg != null)
            {
                WriteMessage(msg, false);
            }

            return(Console.ReadKey().KeyChar);
        }
Beispiel #12
0
 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;
     }
 }
Beispiel #13
0
 /// <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));
     }
 }
Beispiel #14
0
        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));
        }
Beispiel #15
0
 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));
         }
     }
 }
Beispiel #16
0
        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);
        }
Beispiel #17
0
        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);
        }
Beispiel #18
0
 public static AppMsg FormatMessage(this MetricComparisonRecord src, char delimiter = '|', bool digitcommas = false)
 => AppMsg.Define(src.DelimitedText(delimiter), SeverityLevel.Benchmark);
Beispiel #19
0
 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));
Beispiel #20
0
 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));
Beispiel #21
0
 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));
Beispiel #22
0
 protected void TypeCaseEnd <C>(AppMsg msg, [CallerMemberName] string caller = null)
 => Enqueue(AppMsg.Define($"{typeof(T).DisplayName()}/{caller}<{typeof(C).DisplayName()}> succeeded: {msg}", SeverityLevel.HiliteCL));
Beispiel #23
0
 protected void TypeCaseStart <C>([CallerMemberName] string caller = null)
 => Enqueue(AppMsg.Define($"{typeof(T).DisplayName()}/{caller}<{typeof(C).DisplayName()}> executing", SeverityLevel.HiliteCL));
Beispiel #24
0
 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());
Beispiel #25
0
 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);
Beispiel #26
0
 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));
Beispiel #27
0
 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);
Beispiel #28
0
 public static ClaimException Define(ClaimOpKind op, AppMsg msg)
 => new ClaimException(op, msg);
Beispiel #29
0
 public void Log(AppMsg src)
 {
     lock (locker)
         LogPath().Append(src.ToString());
 }
Beispiel #30
0
 ClaimException(ClaimOpKind kind, AppMsg msg)
     : base(msg.WithPrependedContent("fail(").WithAppendedContent(")"))
 {
     this.OpKind = kind;
 }