예제 #1
0
        /// <summary>
        /// Launch appropriate optimizations if needed.
        /// </summary>
        private static void HandleOptims(Optimizer optimHandle, OptimizerOptions optimOpt)
        {
            var checkTypeValues = Enum.GetValues(typeof(OptimizerOptions));

            foreach (OptimizerOptions value in checkTypeValues)
            {
                if ((optimOpt & value) == value)
                {
                    switch (value)
                    {
                    case OptimizerOptions.CleanGarbage: optimHandle.CleanGarbage(); break;

                    case OptimizerOptions.GCLatency: optimHandle.OptimizeGCLatency(); break;

                    case OptimizerOptions.Thread: optimHandle.OptimizedCurrentThread(); break;

                    case OptimizerOptions.Process: optimHandle.OptimizedCurrentProcess(); break;

                    case OptimizerOptions.Process1: optimHandle.OptimizedCurrentProcess(1); break;

                    case OptimizerOptions.Process2: optimHandle.OptimizedCurrentProcess(3); break;

                    case OptimizerOptions.Process4: optimHandle.OptimizedCurrentProcess(15); break;

                    case OptimizerOptions.Process8: optimHandle.OptimizedCurrentProcess(255); break;

                    case OptimizerOptions.None:
                    default:
                        break;
                    }
                }
            }
        }
예제 #2
0
 ActionVisitor(OptimizerOptions options, MethodDefinition method, Action <Method> callback)
 {
     Options        = options;
     Type           = method.DeclaringType;
     Method         = method;
     MethodCallback = callback;
 }
예제 #3
0
 public bool Evaluate(OptimizerOptions options)
 {
     if (evaluated == null)
     {
         evaluated = Conditional == null || options.IsFeatureEnabled(Conditional) == Enabled;
     }
     return(evaluated.Value);
 }
예제 #4
0
        /// <summary>
        /// Measure the timing of the action method execution according to the numberOfIterations.
        /// NOTE: This is another way to measure a piece of code, creating and returning a completly new Measures instance.
        /// </summary>
        /// <param name="action"></param>
        /// <param name="numberOfIterations"></param>
        public static T Measure <T>(Action action, int numberOfIterations = 1, OptimizerOptions optimOpt = OptimizerOptions.None) where T : AbstractMeasures, new()
        {
            var timings = new T();
            var optim   = new Optimizer();

            HandleOptims(optim, optimOpt);
            for (var i = 0; i < numberOfIterations; i++)
            {
                Stopwatch chrono = Stopwatch.StartNew();
                action();
                chrono.Stop();
                timings.AddMeasure(chrono.Elapsed.TotalMilliseconds);
            }
            RestoreAllOptims(optim);
            return(timings);
        }
예제 #5
0
        ActionList OnConditional(XPathNavigator nav)
        {
            var name = nav.GetAttribute("feature");

            if (name == null || !nav.GetBoolAttribute("enabled", out var enabled))
            {
                throw ThrowError("<conditional> needs both `feature` and `enabled` arguments.");
            }

            OptimizerOptions.FeatureByName(name);

            var conditional = new ActionList(name, enabled);

            nav.ProcessChildren("namespace", conditional.Children, OnNamespaceEntry);
            nav.ProcessChildren("type", (Type)null, conditional.Children, OnTypeEntry);
            nav.ProcessChildren("method", (Type)null, conditional.Children, OnMethodEntry);

            return(conditional);
        }
 public void AddOptimizerOption(object key, object value)
 {
     OptimizerOptions.Add(new KeyValuePair(key, value));
 }
예제 #7
0
 /// <summary>
 /// Stops time interval measurement, resets the elapsed time to zero, and starts measuring elapsed time.
 /// </summary>
 public void Restart(OptimizerOptions optimOpt = OptimizerOptions.None)
 {
     HandleOptims(optimOpt);
     _stopwatch.Restart();
 }
예제 #8
0
 /// <summary>
 /// Launch appropriate optimizations if needed.
 /// </summary>
 private void HandleOptims(OptimizerOptions optimOpt)
 {
     HandleOptims(_optim, optimOpt);
 }
예제 #9
0
 public static void Visit(OptimizerOptions options, MethodDefinition method, Action <Method> callback)
 {
     new ActionVisitor(options, method, callback).Visit();
 }
예제 #10
0
 public static void Visit(OptimizerOptions options, TypeDefinition type, Action <Type> callback)
 {
     new ActionVisitor(options, type, callback).Visit();
 }
예제 #11
0
 ActionVisitor(OptimizerOptions options, TypeDefinition type, Action <Type> callback)
 {
     Options      = options;
     Type         = type;
     TypeCallback = callback;
 }
예제 #12
0
 public OptimizerReport(OptimizerOptions options)
 {
     Options = options;
 }