public void GlobalSetup() { _conn = BenchmarkEnvironment.OpenConnection(); _cmd = new NpgsqlCommand(Queries[NumColumns], _conn); }
private static void ProcessRun(BenchmarkRepository environmentRepository, string runDirectory) { var outputFile = Path.Combine(runDirectory, "benchmarks.pb"); // If the output file already exists, assume we're done. if (File.Exists(outputFile)) { return; } var startFile = Path.Combine(runDirectory, "start.txt"); var endFile = Path.Combine(runDirectory, "end.txt"); var start = DateTimeOffset.ParseExact(File.ReadAllText(startFile).Trim(), "yyyy-MM-ddTHH:mm:sszzz", CultureInfo.InvariantCulture); var end = DateTimeOffset.ParseExact(File.ReadAllText(endFile).Trim(), "yyyy-MM-ddTHH:mm:sszzz", CultureInfo.InvariantCulture); var tfm = Path.GetFileName(runDirectory); var commit = Path.GetFileName(Path.GetDirectoryName(runDirectory)); var models = Directory.GetFiles(runDirectory, "*.json") .Select(file => JsonConvert.DeserializeObject <BriefJsonModel>(File.ReadAllText(file))) .Where(m => m.Benchmarks.Any()) .ToList(); if (!models.Any()) { // TODO: Throw? return; } var runKey = Guid.NewGuid().ToString(); File.WriteAllText(outputFile, runKey); var hostEnvironment = models.First().HostEnvironmentInfo; var environment = new BenchmarkEnvironment { Machine = Environment.MachineName.ToLowerInvariant(), OperatingSystem = hostEnvironment.OsVersion ?? "", Processor = hostEnvironment.ProcessorName ?? "", ProcessorCount = hostEnvironment.LogicalCoreCount, TargetFramework = tfm, JitModules = hostEnvironment.JitModules, HasRyuJit = hostEnvironment.HasRyuJit, Architecture = hostEnvironment.Architecture, RuntimeVersion = hostEnvironment.RuntimeVersion }; var environmentId = environmentRepository.GetOrAddEnvironmentId(environment); var run = new BenchmarkRun { BenchmarkRunId = Guid.NewGuid().ToString(), BenchmarkEnvironmentId = environmentId, Commit = commit, Start = start.ToTimestamp(), End = end.ToTimestamp(), BenchmarkDotNetVersion = hostEnvironment.BenchmarkDotNetVersion, }; var types = new List <BenchmarkType>(); foreach (var model in models) { var firstBenchmark = model.Benchmarks.First(); var typeId = Guid.NewGuid().ToString(); types.Add(new BenchmarkType { BenchmarkRunId = run.BenchmarkRunId, BenchmarkTypeId = typeId, FullTypeName = $"{firstBenchmark.Namespace}.{firstBenchmark.Type}", Namespace = firstBenchmark.Namespace, Type = firstBenchmark.Type, Benchmarks = { model.Benchmarks.Select(b => CreateBenchmark(b, typeId)).OrderBy(b => b.Method) } }); } run.Types_.AddRange(types.OrderBy(t => t.FullTypeName)); File.WriteAllBytes(outputFile, run.ToByteArray()); environmentRepository.AddRun(run); Console.WriteLine($"Created benchmark file for {commit} / {tfm}"); }