Пример #1
0
        public ActionResult SimpleStartWatchingWithIgnored()
        {
            using var pm = PerformanceMeter <PerformanceMeterController> .StartWatching();

            // put your code with some logic here

            // sleep 1 sec
            Thread.Sleep(1000);

            // ignore this block in performance watching
            using (pm.Ignore())
            {
                Thread.Sleep(5000);
            }

            // skip this step with minSaveMs (do not save the step results, but take into account its duration)
            using (pm.StepIf("Skipped step", minSaveMs: 1000))
            {
                Thread.Sleep(999);
            }

            // execute action without performance watching
            pm.Executing().WithoutWatching().Start(() => Thread.Sleep(2000));

            return(Ok());
        }
Пример #2
0
        public ActionResult <string> StartWatchingWithCallerNameFromAttribute([FromBody] string value)
        {
            // the method’s performance info will be amended with the caller's name (if internal HttpContextAccessor is null)
            using var pm = PerformanceMeter <PerformanceMeterController> .StartWatching();

            return(Ok(value));
        }
Пример #3
0
        public ActionResult SimpleStartWatchingFuncMethod()
        {
            using var pm = PerformanceMeter <PerformanceMeterController> .StartWatching(SimpleStartWatchingFuncMethod);

            // put your code with some logic here

            return(Ok());
        }
        public ActionResult SimpleStartWatching()
        {
            using (PerformanceMeter <PerformanceMeterController> .StartWatching())
            {
                // put your code with some logic here

                return(Ok());
            }
        }
Пример #5
0
        public ActionResult PublicTestGetSimpleMethodWithActionAndIterations(uint iterations = 1)
        {
            using var pm = PerformanceMeter <PerformanceMeterController> .StartWatching();

            // execute an action that throws the exception to be handled by the exception handler
            pm.Executing()
            .Start(() => Debug.WriteLine($"Iterations: {iterations}"), iterations);

            return(Ok());
        }
Пример #6
0
        public ActionResult PublicTestGetSimpleMethodWithActionThrowsException()
        {
            using var pm = PerformanceMeter <PerformanceMeterController> .StartWatching();

            // execute an action that throws the exception to be handled by the exception handler
            pm.Executing()
            .WithExceptionHandler((ex) => Debug.WriteLine(ex.Message))
            .Start(() => throw new Exception(PerformanceMeter <PerformanceMeterController> .Print()));

            return(Ok());
        }
Пример #7
0
        public ActionResult SimpleStartWatchingWithActionThrowsCustomException()
        {
            using var pm = PerformanceMeter <PerformanceMeterController> .StartWatching();

            // put your code with some logic here

            // execute action throws custom Exception with exception handler
            pm.Executing <CustomException>()
            .WithExceptionHandler((ex) => { Debug.WriteLine("Custom exception was occured!"); })
            .Start(() => throw new CustomException("Action exception!!!"));

            return(Ok());
        }
Пример #8
0
        public ActionResult SimpleStartWatchingWithThrowsExceptions()
        {
            using var pm = PerformanceMeter <PerformanceMeterController> .StartWatching();

            // execute an action that throws the exception to be handled by the exception handler
            pm.Executing()
            .WithExceptionHandler((ex) => Debug.WriteLine(ex.Message))
            .Start(() => throw new Exception("Exception"));

            // execute action throws custom Exception with exception handler
            pm.Executing <CustomException>()
            .WithExceptionHandler((ex) => { Debug.WriteLine(ex.Message); })
            .Start(() => throw new CustomException("Custom exception was occured!"));

            return(Ok());
        }
        public ActionResult <string> SimpleStartWatchingWithoutWatching()
        {
            //using var pm = PerformanceMeter<PerformanceMeterController>.StartWatching();
            using (var pm = PerformanceMeter <PerformanceMeterController> .StartWatching())
            {
                // put your code with some logic here

                // sleep 1 sec
                Thread.Sleep(1000);

                // execute action without watching
                pm.Executing()
                .WithoutWatching()
                .Start(() => Thread.Sleep(2000));

                // execute action with sleeping 500 ms
                pm.Inline(() =>
                {
                    Thread.Sleep(500);
                    Debug.WriteLine("Sleep 500 ms");
                });

                // execute action without watching
                pm.InlineIgnored(() =>
                {
                    Thread.Sleep(100);
                    Debug.WriteLine("Sleep 1000 ms");
                });

                // execute Func<string> returns string
                var result = pm.Executing()
                             .Start(() =>
                {
                    Thread.Sleep(2000);
                    return("1");
                });

                return(Ok(result));
            }
        }