예제 #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));
     }
 }
예제 #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));
     }
 }
예제 #3
0
 protected void Trace(string msg, SeverityLevel?severity = null)
 {
     if (TraceEnabled)
     {
         Enqueue(AppMsg.Define($"{msg}", severity ?? SeverityLevel.Babble));
     }
 }
예제 #4
0
파일: Reactor.cs 프로젝트: 0xCM/z0
 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);
     }
 }
예제 #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));
     }
 }
예제 #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);
            }
        }
예제 #7
0
파일: Terminal.cs 프로젝트: 0xCM/arrows
 public string ReadLine(AppMsg msg = null)
 {
     if (msg != null)
     {
         WriteMessage(msg, false);
     }
     return(Console.ReadLine());
 }
예제 #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;
 }
예제 #9
0
 public AppException(AppMsg msg)
     : base(msg.ToString())
 {
     this.Message = msg;
     this.Caller  = Message.Caller;
     this.File    = Message.CallerFile;
     this.Line    = Message.FileLine;
 }
예제 #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));
            }
        }
예제 #11
0
파일: Terminal.cs 프로젝트: 0xCM/arrows
        public char ReadKey(AppMsg msg = null)
        {
            if (msg != null)
            {
                WriteMessage(msg, false);
            }

            return(Console.ReadKey().KeyChar);
        }
예제 #12
0
파일: Terminal.cs 프로젝트: 0xCM/arrows
 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;
     }
 }
예제 #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));
     }
 }
예제 #14
0
파일: MetricDelta.cs 프로젝트: 0xCM/arrows
        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));
        }
예제 #15
0
파일: Terminal.cs 프로젝트: 0xCM/arrows
 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));
         }
     }
 }
예제 #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);
        }
예제 #17
0
파일: Metric.x.cs 프로젝트: 0xCM/arrows
        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);
        }
예제 #18
0
파일: Metric.x.cs 프로젝트: 0xCM/arrows
 public static AppMsg FormatMessage(this MetricComparisonRecord src, char delimiter = '|', bool digitcommas = false)
 => AppMsg.Define(src.DelimitedText(delimiter), SeverityLevel.Benchmark);
예제 #19
0
파일: TestContext.cs 프로젝트: 0xCM/arrows
 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));
예제 #20
0
파일: TestContext.cs 프로젝트: 0xCM/arrows
 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));
예제 #21
0
파일: TestContext.cs 프로젝트: 0xCM/arrows
 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));
예제 #22
0
파일: TestContext.cs 프로젝트: 0xCM/arrows
 protected void TypeCaseEnd <C>(AppMsg msg, [CallerMemberName] string caller = null)
 => Enqueue(AppMsg.Define($"{typeof(T).DisplayName()}/{caller}<{typeof(C).DisplayName()}> succeeded: {msg}", SeverityLevel.HiliteCL));
예제 #23
0
파일: TestContext.cs 프로젝트: 0xCM/arrows
 protected void TypeCaseStart <C>([CallerMemberName] string caller = null)
 => Enqueue(AppMsg.Define($"{typeof(T).DisplayName()}/{caller}<{typeof(C).DisplayName()}> executing", SeverityLevel.HiliteCL));
예제 #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());
예제 #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);
예제 #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));
예제 #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);
예제 #28
0
 public static ClaimException Define(ClaimOpKind op, AppMsg msg)
 => new ClaimException(op, msg);
예제 #29
0
파일: Log.cs 프로젝트: 0xCM/arrows
 public void Log(AppMsg src)
 {
     lock (locker)
         LogPath().Append(src.ToString());
 }
예제 #30
0
 ClaimException(ClaimOpKind kind, AppMsg msg)
     : base(msg.WithPrependedContent("fail(").WithAppendedContent(")"))
 {
     this.OpKind = kind;
 }