/// <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; } } } }
ActionVisitor(OptimizerOptions options, MethodDefinition method, Action <Method> callback) { Options = options; Type = method.DeclaringType; Method = method; MethodCallback = callback; }
public bool Evaluate(OptimizerOptions options) { if (evaluated == null) { evaluated = Conditional == null || options.IsFeatureEnabled(Conditional) == Enabled; } return(evaluated.Value); }
/// <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); }
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)); }
/// <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(); }
/// <summary> /// Launch appropriate optimizations if needed. /// </summary> private void HandleOptims(OptimizerOptions optimOpt) { HandleOptims(_optim, optimOpt); }
public static void Visit(OptimizerOptions options, MethodDefinition method, Action <Method> callback) { new ActionVisitor(options, method, callback).Visit(); }
public static void Visit(OptimizerOptions options, TypeDefinition type, Action <Type> callback) { new ActionVisitor(options, type, callback).Visit(); }
ActionVisitor(OptimizerOptions options, TypeDefinition type, Action <Type> callback) { Options = options; Type = type; TypeCallback = callback; }
public OptimizerReport(OptimizerOptions options) { Options = options; }