コード例 #1
0
        private ProfilerSession()
        {
            _settings   = new ProfilerSettings();
            _assertions = new List <Func <IResult, bool> >();
            _executor   = new ThreadSessionHandler();

            _sessionPipeline = new TaskExecutionChain();
            _sessionPipeline.SetNext(new ElapsedTimeSessionHandler());

            _processingPipeline = new ProcessingPipeline();
        }
コード例 #2
0
        /// <summary>
        /// Executes the task
        /// </summary>
        /// <param name="task">The task to run</param>
        /// <param name="settings">The settings for the profiler</param>
        /// <returns>The resulting collection of the executions</returns>
        public override IProfilerResult Execute(ITask task, ProfilerSettings settings)
        {
            ThreadHelper.SetProcessor();
            ThreadHelper.SetThreadPriority();

            var worker = new Worker();
            var p      = worker.Run(task, settings);

            return(new ProfilerResult
            {
                p
            });
        }
コード例 #3
0
        /// <summary>
        /// Executes the task
        /// </summary>
        /// <param name="task">The task to run</param>
        /// <param name="settings">The settings for the profiler</param>
        /// <returns>The resulting collection of the executions</returns>
        public override IProfilerResult Execute(ITask task, ProfilerSettings settings)
        {
            var sw = new Stopwatch();

            sw.Start();

            var result = base.Execute(task, settings);

            sw.Stop();
            result.ResultValues.Add("Elapsed", sw.Elapsed);

            return(result);
        }
コード例 #4
0
        /// <summary>
        /// Executes the task
        /// </summary>
        /// <param name="task">The task to run</param>
        /// <param name="settings">The settings for the profiler</param>
        /// <returns>The resulting collection of the executions</returns>
        public override IProfilerResult Execute(ITask task, ProfilerSettings settings)
        {
            var stopwatch = new Stopwatch();

            // warmup
            _logger.Write($"Warmup: Running Task once for warmup on Performance Analysis Benchmark");

            stopwatch.Start();

            task.Run(new ExecutionContext());

            stopwatch.Stop();

            var result = base.Execute(task, settings);

            result.ResultValues.Add("Warmup", stopwatch.Elapsed);

            return(result);
        }
コード例 #5
0
        /// <summary>
        /// Executes the task
        /// </summary>
        /// <param name="task">The task to run</param>
        /// <param name="settings">The settings for the profiler</param>
        /// <returns>The resulting collection of the executions</returns>
        public override IProfilerResult Execute(ITask task, ProfilerSettings settings)
        {
            lock (_threads)
            {
                for (int i = 0; i < _threadCount; i++)
                {
                    var thread = ThreadHelper.QueueTask(i, threadIndex =>
                    {
                        var worker = new Worker();
                        var p      = worker.Run(task, settings);
                        return(p);
                    });

                    System.Diagnostics.Trace.WriteLine($"MeasureMap - Start thread {thread.Id}");

                    _threads.Add(thread);
                }

                foreach (var thread in _threads)
                {
                    thread.Start();
                }
            }

            while (CountOpenThreads() > 0)
            {
                System.Threading.Tasks.Task.WaitAll(GetAwaitableThreads(), -1, CancellationToken.None);
            }

            var results = _threads.Select(s => s.Result);

            var collectîon = new ProfilerResult();

            foreach (var result in results)
            {
                collectîon.Add(result);
            }

            return(collectîon);
        }
コード例 #6
0
ファイル: Worker.cs プロジェクト: WickedFlame/MeasureMap
        /// <summary>
        /// Runs the provided task for the iteration count
        /// </summary>
        /// <param name="task">The task that has to be run</param>
        /// <param name="settings">The settings for the profiler</param>
        /// <returns></returns>
        public Result Run(ITask task, ProfilerSettings settings)
        {
            var result = new Result();

            ForceGarbageCollector();

            result.InitialSize = GC.GetTotalMemory(true);
            var context = new ExecutionContext();

            var runner = settings.Runner;

            runner.Run(settings, context, () =>
            {
                var iteration = task.Run(context);

                result.Add(iteration);
            });

            ForceGarbageCollector();
            result.EndSize = GC.GetTotalMemory(true);

            return(result);
        }
コード例 #7
0
 /// <summary>
 /// Executes the task
 /// </summary>
 /// <param name="task">The task to run</param>
 /// <param name="settings">The settings for the profiler</param>
 /// <returns>The resulting collection of the executions</returns>
 public IProfilerResult Execute(ITask task, ProfilerSettings settings)
 {
     return(_root.Execute(task, settings));
 }
コード例 #8
0
        /// <summary>
        /// Sets the amount of iterations that the profileing session should run the task
        /// </summary>
        /// <param name="runner">The benchmark runner</param>
        /// <param name="settings">The settings for thr profiler</param>
        /// <returns>The current profiling session</returns>
        public static BenchmarkRunner SetSettings(this BenchmarkRunner runner, ProfilerSettings settings)
        {
            settings.MergeChangesTo(runner.Settings);

            return(runner);
        }
コード例 #9
0
        /// <summary>
        /// Sets the settings that the profiler should use
        /// </summary>
        /// <param name="session">The current session</param>
        /// <param name="settings">The settings for thr profiler</param>
        /// <returns>The current profiling session</returns>
        public static ProfilerSession SetSettings(this ProfilerSession session, ProfilerSettings settings)
        {
            settings.MergeChangesTo(session.Settings);

            return(session);
        }
コード例 #10
0
 /// <summary>
 /// Creates an instance of the BenchmaekRunner
 /// </summary>
 public BenchmarkRunner()
 {
     _settings = new ProfilerSettings();
     _sessions = new Dictionary <string, ProfilerSession>();
 }
コード例 #11
0
        /// <summary>
        /// Executes the task
        /// </summary>
        /// <param name="task">The task to run</param>
        /// <param name="settings">The settings for the profiler</param>
        /// <returns>The resulting collection of the executions</returns>
        public override IProfilerResult Execute(ITask task, ProfilerSettings settings)
        {
            _action.Invoke();

            return(base.Execute(task, settings));
        }