Ejemplo n.º 1
0
 public static void Assert(this Benchmarker self, Expression <Func <bool> > expr)
 {
     if (self == null)
     {
         return;
     }
     if (!self.EnabledInProduction && !FiTechCoreExtensions.EnableBenchMarkers)
     {
         return;
     }
     try {
         bool result = expr.Compile().Invoke();
         if (!result && Debugger.IsAttached)
         {
             self.Mark($"Assert Failed {expr.ToString()} => {result}");
             Debugger.Break();
         }
     } catch (Exception x) {
         self.Mark($"Assert {expr.ToString()} => Exception", x);
         if (Debugger.IsAttached)
         {
             Debugger.Break();
         }
     }
 }
Ejemplo n.º 2
0
 public static void Wrap(this Benchmarker self, string label, Action action)
 {
     try {
         self.Mark($"[RegionStart] {label}");
         action.Invoke();
         self.Mark($"[RegionEndOk] {label}");
     }
     catch (Exception x) {
         self.Mark($"[RegionException] {label}", x);
         throw new Exception($"Error in Region {label}", x);
     }
 }
Ejemplo n.º 3
0
        public static async Task <T> Wrap <T>(this Benchmarker self, string label, Func <Task <T> > action)
        {
            T retv;

            try {
                self.Mark($"[RegionStart] {label}");
                retv = await action.Invoke();

                self.Mark($"[RegionEndOk] {label}");
            }
            catch (Exception x) {
                self.Mark($"[RegionException] {label}", x);
                retv = default(T);
                throw x;
            }

            return(retv);
        }
Ejemplo n.º 4
0
        public static T Wrap <T>(this Benchmarker self, string label, Func <T> action)
        {
            if (self == null)
            {
                return(default(T));
            }
            T retv;

            try {
                self.Mark($"[RegionStart] {label}");
                retv = action.Invoke();
                self.Mark($"[RegionEndOk] {label}");
            } catch (Exception x) {
                self.Mark($"[RegionException] {label}", x);
                throw new Exception($"Error in Region {label}", x);
            }

            return(retv);
        }