예제 #1
0
        public static int Main(string[] args)
        {
            var diagnostics = new ErrorTrackingDiagnostics( );

            Diagnostics.Implementation = diagnostics;

            if (args.Length < 2)
            {
                Diagnostics.Error("USAGE: LlvmBindingsGenerator <llvmRoot> <extensionsRoot> [OutputPath]");
                return(-1);
            }

            string llvmRoot       = args[0];
            string extensionsRoot = args[1];
            string outputPath     = args.Length > 2 ? args[2] : System.Environment.CurrentDirectory;

            // read in the binding configuration from the YAML file
            // It is hoped, that going forward, the YAML file is the only thing that needs to change
            // but either way, helps keep the declarative part in a more easily understood format.
            string configPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "BindingsConfig.yml");
            var    config     = new ReadOnlyConfig(YamlConfiguration.ParseFrom(configPath));
            var    library    = new LibLlvmGeneratorLibrary(config, llvmRoot, extensionsRoot, outputPath);

            Driver.Run(library);
            return(diagnostics.ErrorCount);

            /* TODO:
             * Auto merge the generated docs XML with the Hand edited API Docs as hand merging is tedious and error prone.
             *  1) delete entries in APIDocs no longer in generated docs
             *  2) add entries to APIDocs for elements in generated docs but not in API Docs
             *  3) Leave everything else in APIDocs, intact
             */
        }
예제 #2
0
        private static int Run(Options options)
        {
            var diagnostics = new ErrorTrackingDiagnostics( )
            {
                Level = options.Diagnostics
            };

            Diagnostics.Implementation = diagnostics;
            string configPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "BindingsConfig.yml");

            try
            {
                // read in the binding configuration from the YAML file
                // It is hoped, that going forward, the YAML file is the only thing that needs to change
                // but either way, it helps keep the declarative part in a more easily edited format.
                var config  = new ReadOnlyConfig(YamlConfiguration.ParseFrom(configPath));
                var library = new LibLlvmGeneratorLibrary(config, options.LlvmRoot, options.ExtensionsRoot, options.OutputPath);
                Driver.Run(library);
            }
            catch (IOException ioex)
            {
                Diagnostics.Error(ioex.Message);
            }
            catch (YamlDotNet.Core.SyntaxErrorException yamlex)
            {
                // Sadly the yaml exception message includes the location info in a format that doesn't match any standard tooling
                // for parsing error messages, so unpack it to get just the message of interest and re-format
                var matcher = new Regex(@"\(Line\: \d+, Col\: \d+, Idx\: \d+\) - \(Line\: \d+, Col\: \d+, Idx\: \d+\)\: (.*)\Z");
                var result  = matcher.Match(yamlex.Message);
                if (result.Success)
                {
                    Diagnostics.Error("{0}({1},{2},{3},{4}): error CFG001: {5}"
                                      , configPath
                                      , yamlex.Start.Line
                                      , yamlex.Start.Column
                                      , yamlex.End.Line
                                      , yamlex.End.Column
                                      , result.Groups[1]);
                }
                else
                {
                    // message didn't match expectations, best effort at this point...
                    Diagnostics.Error(yamlex.Message);
                }
            }

            return(diagnostics.ErrorCount);

            /* TODO:
             * Auto merge the generated docs XML with the Hand edited API Docs as hand merging is tedious and error prone.
             *  1) delete entries in APIDocs no longer in generated docs
             *  2) add entries to APIDocs for elements in generated docs but not in API Docs
             *  3) Leave everything else in APIDocs, intact
             */
        }
        private static BenchmarkReport RunCore(Benchmark benchmark, ILogger logger, ReadOnlyConfig config, string rootArtifactsFolderPath, Func <Job, IToolchain> toolchainProvider, IResolver resolver, List <string> artifactsToCleanup)
        {
            var toolchain = toolchainProvider(benchmark.Job);

            logger.WriteLineHeader("// **************************");
            logger.WriteLineHeader("// Benchmark: " + benchmark.DisplayInfo);

            var assemblyResolveHelper = GetAssemblyResolveHelper(toolchain, logger);
            var generateResult        = Generate(logger, toolchain, benchmark, rootArtifactsFolderPath, config, resolver);

            try
            {
                if (!generateResult.IsGenerateSuccess)
                {
                    return(new BenchmarkReport(benchmark, generateResult, null, null, null, default(GcStats)));
                }

                var buildResult = Build(logger, toolchain, generateResult, benchmark, resolver);
                if (!buildResult.IsBuildSuccess)
                {
                    return(new BenchmarkReport(benchmark, generateResult, buildResult, null, null, default(GcStats)));
                }

                var(executeResults, gcStats) = Execute(logger, benchmark, toolchain, buildResult, config, resolver);

                var runs = new List <Measurement>();

                for (int index = 0; index < executeResults.Count; index++)
                {
                    var executeResult = executeResults[index];
                    runs.AddRange(executeResult.Data.Select(line => Measurement.Parse(logger, line, index + 1)).Where(r => r.IterationMode != IterationMode.Unknown));
                }

                return(new BenchmarkReport(benchmark, generateResult, buildResult, executeResults, runs, gcStats));
            }
            catch (Exception e)
            {
                logger.WriteLineError("// Exception: " + e);
                return(new BenchmarkReport(benchmark, generateResult, BuildResult.Failure(generateResult, e), Array.Empty <ExecuteResult>(), Array.Empty <Measurement>(), GcStats.Empty));
            }
            finally
            {
                if (!config.KeepBenchmarkFiles)
                {
                    artifactsToCleanup.AddRange(generateResult.ArtifactsToCleanup);
                }

                assemblyResolveHelper?.Dispose();
            }
        }
        private static BenchmarkReport RunCore(Benchmark benchmark, ILogger logger, ReadOnlyConfig config, string rootArtifactsFolderPath, Func <Job, IToolchain> toolchainProvider, IResolver resolver, BuildResult buildResult)
        {
            var toolchain = toolchainProvider(benchmark.Job);

            logger.WriteLineHeader("// **************************");
            logger.WriteLineHeader("// Benchmark: " + benchmark.DisplayInfo);

            var(executeResults, gcStats) = Execute(logger, benchmark, toolchain, buildResult, config, resolver);

            var runs = new List <Measurement>();

            for (int index = 0; index < executeResults.Count; index++)
            {
                var executeResult = executeResults[index];
                runs.AddRange(executeResult.Data.Select(line => Measurement.Parse(logger, line, index + 1)).Where(r => r.IterationMode != IterationMode.Unknown));
            }

            return(new BenchmarkReport(benchmark, buildResult, buildResult, executeResults, runs, gcStats));
        }
        private static BuildResult Build(Benchmark benchmark, ReadOnlyConfig config, string rootArtifactsFolderPath, Func <Job, IToolchain> toolchainProvider, IResolver resolver)
        {
            var toolchain = toolchainProvider(benchmark.Job);

            var generateResult = toolchain.Generator.GenerateProject(benchmark, NullLogger.Instance, rootArtifactsFolderPath, config, resolver);

            try
            {
                if (!generateResult.IsGenerateSuccess)
                {
                    return(BuildResult.Failure(generateResult));
                }

                return(toolchain.Builder.Build(generateResult, NullLogger.Instance, benchmark, resolver));
            }
            catch (Exception e)
            {
                return(BuildResult.Failure(generateResult, e));
            }
        }
예제 #6
0
        private void Initialize(IMembaseClientConfiguration configuration, string bucketName, string bucketPassword)
        {
            var roc = new ReadOnlyConfig(configuration);

            // make null both if we use the default bucket since we do not need to be authenticated
            if (String.IsNullOrEmpty(bucketName) || bucketName == "default")
            {
                bucketName     = null;
                bucketPassword = null;
            }
            else
            {
                bucketPassword = bucketPassword ?? String.Empty;
            }

            roc.OverrideBucket(bucketName, bucketPassword);

            this.configuration   = roc;
            this.deadTimeoutMsec = (long)this.configuration.SocketPool.DeadTimeout.TotalMilliseconds;
        }
예제 #7
0
        private static BenchmarkRunInfo MethodsToBenchmarksWithFullConfig(Type containingType, MethodInfo[] benchmarkMethods, ReadOnlyConfig fullConfig)
        {
            if (fullConfig == null)
            {
                throw new ArgumentNullException(nameof(fullConfig));
            }

            var helperMethods = containingType.GetMethods(); // benchmarkMethods can be filtered, without Setups, look #564

            var globalSetupMethods      = GetAttributedMethods <GlobalSetupAttribute>(helperMethods, "GlobalSetup");
            var globalCleanupMethods    = GetAttributedMethods <GlobalCleanupAttribute>(helperMethods, "GlobalCleanup");
            var iterationSetupMethods   = GetAttributedMethods <IterationSetupAttribute>(helperMethods, "IterationSetup");
            var iterationCleanupMethods = GetAttributedMethods <IterationCleanupAttribute>(helperMethods, "IterationCleanup");

            var targetMethods = benchmarkMethods.Where(method => method.HasAttribute <BenchmarkAttribute>()).ToArray();

            var parameterDefinitions   = GetParameterDefinitions(containingType);
            var parameterInstancesList = parameterDefinitions.Expand();

            var jobs = fullConfig.GetRunnableJobs();

            var targets = GetTargets(targetMethods, containingType, globalSetupMethods, globalCleanupMethods, iterationSetupMethods, iterationCleanupMethods).ToArray();

            var benchmarks = new List <BenchmarkCase>();

            foreach (var target in targets)
            {
                var argumentsDefinitions = GetArgumentsDefinitions(target.WorkloadMethod, target.Type).ToArray();

                var parameterInstanceses =
                    (from parameterInstance in parameterInstancesList
                     from argumentDefinition in argumentsDefinitions
                     select new ParameterInstances(parameterInstance.Items.Concat(argumentDefinition.Items).ToArray())).ToArray();

                benchmarks.AddRange(
                    from job in jobs
                    from parameterInstance in parameterInstanceses
                    select BenchmarkCase.Create(target, job, parameterInstance)
                    );
            }

            var filters            = fullConfig.GetFilters().ToList();
            var filteredBenchmarks = GetFilteredBenchmarks(benchmarks, filters);

            var orderProvider = fullConfig.GetOrderer() ?? DefaultOrderer.Instance;

            return(new BenchmarkRunInfo(
                       orderProvider.GetExecutionOrder(filteredBenchmarks).ToArray(),
                       containingType,
                       fullConfig));
        }
예제 #8
0
 public BenchmarkBuildInfo(BenchmarkCase benchmarkCase, ReadOnlyConfig config, int id)
 {
     BenchmarkCase = benchmarkCase;
     Config        = config;
     Id            = new BenchmarkId(id);
 }
        private static Dictionary <Benchmark, BuildResult> BuildInParallel(ILogger logger, string rootArtifactsFolderPath, Func <Job, IToolchain> toolchainProvider, IResolver resolver, Benchmark[] benchmarks, ReadOnlyConfig config, ref StartedClock globalChronometer)
        {
            using (benchmarks.Select(benchmark => GetAssemblyResolveHelper(toolchainProvider(benchmark.Job), logger)).FirstOrDefault(helper => helper != null))
            {
                logger.WriteLineHeader($"// ***** Building {benchmarks.Length} benchmark(s) in Parallel: Start   *****");

                var buildResults = benchmarks
                                   .AsParallel()
                                   .Select(benchmark => { return(benchmark, buildResult: Build(benchmark, config, rootArtifactsFolderPath, toolchainProvider, resolver)); })
                                   .ToDictionary(result => result.benchmark, result => result.buildResult);

                logger.WriteLineHeader($"// ***** Done, took {globalChronometer.GetElapsed().GetTimeSpan().ToFormattedTotalTime()}   *****");

                return(buildResults);
            }
        }
예제 #10
0
        private static BenchmarkRunInfo MethodsToBenchmarksWithFullConfig(Type containingType, MethodInfo[] benchmarkMethods, ReadOnlyConfig fullConfig)
        {
            if (fullConfig == null)
            {
                throw new ArgumentNullException(nameof(fullConfig));
            }

            var helperMethods = containingType.GetMethods(); // benchmarkMethods can be filtered, without Setups, look #564

            var globalSetupMethods      = GetAttributedMethods <GlobalSetupAttribute>(helperMethods, "GlobalSetup");
            var globalCleanupMethods    = GetAttributedMethods <GlobalCleanupAttribute>(helperMethods, "GlobalCleanup");
            var iterationSetupMethods   = GetAttributedMethods <IterationSetupAttribute>(helperMethods, "IterationSetup");
            var iterationCleanupMethods = GetAttributedMethods <IterationCleanupAttribute>(helperMethods, "IterationCleanup");

            var targetMethods = benchmarkMethods.Where(method => method.HasAttribute <BenchmarkAttribute>()).ToArray();

            var parameterDefinitions   = GetParameterDefinitions(containingType);
            var parameterInstancesList = parameterDefinitions.Expand();

            var rawJobs = fullConfig.GetJobs().ToArray();

            if (rawJobs.IsEmpty())
            {
                rawJobs = new[] { Job.Default }
            }
            ;
            var jobs = rawJobs.Distinct().ToArray();

            var targets = GetTargets(targetMethods, containingType, globalSetupMethods, globalCleanupMethods, iterationSetupMethods, iterationCleanupMethods).ToArray();

            var benchmarks = (
                from target in targets
                from job in jobs
                from parameterInstance in parameterInstancesList
                select new Benchmark(target, job, parameterInstance)).ToArray();

            var filters = fullConfig.GetFilters().ToList();

            benchmarks = GetFilteredBenchmarks(benchmarks, filters);

            var orderProvider = fullConfig.GetOrderProvider() ?? DefaultOrderProvider.Instance;

            return(new BenchmarkRunInfo(
                       orderProvider.GetExecutionOrder(benchmarks).ToArray(),
                       containingType,
                       fullConfig));
        }
예제 #11
0
 public BenchmarkRunInfo(BenchmarkCase[] benchmarksCase, Type type, ReadOnlyConfig config)
 {
     BenchmarksCases = benchmarksCase;
     Type            = type;
     Config          = config;
 }
예제 #12
0
 public BenchmarkRunInfo(Benchmark[] benchmarks, Type type, ReadOnlyConfig config)
 {
     Benchmarks = benchmarks;
     Type       = type;
     Config     = config;
 }
예제 #13
0
 public BenchmarkBuildInfo(Benchmark benchmark, ReadOnlyConfig config, int id)
 {
     Benchmark = benchmark;
     Config    = config;
     Id        = new BenchmarkId(id);
 }