コード例 #1
0
        public static int Run(IHost host, Benchmark benchmark, BenchmarkActionCodegen codegenMode, IConfig config)
        {
            // the first thing to do is to let diagnosers hook in before anything happens
            // so all jit-related diagnosers can catch first jit compilation!
            host.BeforeAnythingElse();

            try
            {
                // we are not using Runnable here in any direct way in order to avoid strong dependency Main<=>Runnable
                // which could cause the jitting/assembly loading to happen before we do anything
                // we have some jitting diagnosers and we want them to catch all the informations!!

                var inProcessRunnableTypeName = $"{typeof(InProcessRunner).FullName}+{nameof(Runnable)}";
                var type = typeof(InProcessRunner).GetTypeInfo().Assembly.GetType(inProcessRunnableTypeName);
                if (type == null)
                {
                    throw new InvalidOperationException($"Bug: type {inProcessRunnableTypeName} not found.");
                }

                type.GetMethod(nameof(Runnable.RunCore), BindingFlags.Public | BindingFlags.Static)
                .Invoke(null, new object[] { host, benchmark, codegenMode, config });

                return(0);
            }
            catch (Exception ex)
            {
                host.WriteLine(ex.ToString());
                return(-1);
            }
            finally
            {
                host.AfterAll();
            }
        }
コード例 #2
0
        public static int Run(IHost host, BenchmarkCase benchmarkCase, BenchmarkActionCodegen codegenMode, IConfig config)
        {
            // the first thing to do is to let diagnosers hook in before anything happens
            // so all jit-related diagnosers can catch first jit compilation!
            host.BeforeAnythingElse();

            try
            {
                // we are not using Runnable here in any direct way in order to avoid strong dependency Main<=>Runnable
                // which could cause the jitting/assembly loading to happen before we do anything
                // we have some jitting diagnosers and we want them to catch all the informations!!

                var inProcessRunnableTypeName = $"{typeof(InProcessRunner).FullName}+{nameof(Runnable)}";
                var type = typeof(InProcessRunner).GetTypeInfo().Assembly.GetType(inProcessRunnableTypeName);
                if (type == null)
                {
                    throw new InvalidOperationException($"Bug: type {inProcessRunnableTypeName} not found.");
                }

                type.GetMethod(nameof(Runnable.RunCore), BindingFlags.Public | BindingFlags.Static)
                .Invoke(null, new object[] { host, benchmarkCase, codegenMode, config });

                return(0);
            }
            catch (Exception oom) when(oom is OutOfMemoryException || oom is TargetInvocationException reflection && reflection.InnerException is OutOfMemoryException)
            {
                host.WriteLine();
                host.WriteLine("OutOfMemoryException!");
                host.WriteLine("BenchmarkDotNet continues to run additional iterations until desired accuracy level is achieved. It's possible only if the benchmark method doesn't have any side-effects.");
                host.WriteLine("If your benchmark allocates memory and keeps it alive, you are creating a memory leak.");
                host.WriteLine("You should redesign your benchmark and remove the side-effects. You can use `OperationsPerInvoke`, `IterationSetup` and `IterationCleanup` to do that.");
                host.WriteLine();
                host.WriteLine(oom.ToString());

                return(-1);
            }
            catch (Exception ex)
            {
                host.WriteLine();
                host.WriteLine(ex.ToString());
                return(-1);
            }
            finally
            {
                host.AfterAll();
            }
        }
コード例 #3
0
        public static int Run(
            BenchmarkId benchmarkId,
            Assembly partitionAssembly,
            BenchmarkCase benchmarkCase,
            IHost host)
        {
            // the first thing to do is to let diagnosers hook in before anything happens
            // so all jit-related diagnosers can catch first jit compilation!
            host.BeforeAnythingElse();

            try
            {
                // we are not using Runnable here in any direct way in order to avoid strong dependency Main<=>Runnable
                // which could cause the jitting/assembly loading to happen before we do anything
                // we have some jitting diagnosers and we want them to catch all the informations!!

                var runCallback = GetRunCallback(benchmarkId, partitionAssembly);

                runCallback.Invoke(null, new object[] { benchmarkCase, host });
                return(0);
            }
            catch (Exception oom) when(
                oom is OutOfMemoryException ||
                oom is TargetInvocationException reflection && reflection.InnerException is OutOfMemoryException)
            {
                DumpOutOfMemory(host, oom);
                return(-1);
            }
            catch (Exception ex)
            {
                DumpError(host, ex);
                return(-1);
            }
            finally
            {
                host.AfterAll();
            }
        }