static Task <double> RunReference(string[] args) { //TextWriterTraceListener tr1 = new TextWriterTraceListener(System.Console.Out); //Debug.Listeners.Add(tr1); #if DEBUG string workerDir = @"C:\temp\azworker-tmp"; #else string workerDir = Path.Combine(Environment.GetEnvironmentVariable(SharedDirEnvVariableName), Environment.GetEnvironmentVariable(JobIdEnvVariableName)); #endif string normalFilePath = Path.Combine(workerDir, PerformanceCoefficientFileName); string refJsonPath = Path.Combine(workerDir, "reference.json"); if (!File.Exists(refJsonPath)) { //no reference experiment Trace.WriteLine("Reference.json not found, assuming normal 1.0."); File.WriteAllText(normalFilePath, "1.0"); return(Task.FromResult(1.0)); } var exp = ParseReferenceExperiment(refJsonPath); var pathForBenchmarks = Path.Combine(workerDir, "refdata", "data"); var execPath = Path.Combine(workerDir, "refdata", exp.Definition.Executable); Domain domain = ResolveDomain(exp.Definition.DomainName); string[] benchmarks = Directory.EnumerateFiles(pathForBenchmarks).Select(fn => Path.Combine(pathForBenchmarks, fn)).ToArray(); Trace.WriteLine(string.Format("Found {0} benchmarks in folder {1}", benchmarks.Length, pathForBenchmarks)); BenchmarkResult[] results = new BenchmarkResult[benchmarks.Length]; for (int i = 0; i < benchmarks.Length; ++i) { Trace.WriteLine(string.Format("Processing reference file {0}", benchmarks[i])); results[i] = LocalExperimentRunner.RunBenchmark( -1, execPath, exp.Definition.Parameters, "ref", benchmarks[i], exp.Repetitions, exp.Definition.BenchmarkTimeout, exp.Definition.MemoryLimitMB, null, null, domain, 1.0); } var totalRuntime = results.Sum(r => r.NormalizedCPUTime); if (totalRuntime <= 0.0) { totalRuntime = 0.1; } double normal = exp.ReferenceValue / totalRuntime; Console.WriteLine("Reference data: " + normal.ToString()); File.WriteAllText(normalFilePath, normal.ToString()); return(Task.FromResult(normal)); }
static async Task Measure(string[] args) { int experimentId = int.Parse(args[0], CultureInfo.InvariantCulture); string benchmarkId = args[1]; string executable = args[2]; string arguments = args[3]; string targetFile = args[4]; TimeSpan timeout = TimeSpan.FromSeconds(double.Parse(args[5], CultureInfo.InvariantCulture)); string domainName = args[6]; Uri outputQueueUri = new Uri(args[7]); Uri outputBlobContainerUri = new Uri(args[8]); int maxRepetitions = int.Parse(args[9], CultureInfo.InvariantCulture); double maxTime = double.Parse(args[10], CultureInfo.InvariantCulture); double memoryLimit = 0; // no limit long? outputLimit = null; long? errorLimit = null; //if (args.Length > 6) //{ // workerInfo = args[6]; if (args.Length > 11) { memoryLimit = double.Parse(args[11], CultureInfo.InvariantCulture); if (args.Length > 12) { outputLimit = args[12] == "null" ? null : (long?)long.Parse(args[12], CultureInfo.InvariantCulture); if (args.Length > 13) { errorLimit = args[13] == "null" ? null : (long?)long.Parse(args[13], CultureInfo.InvariantCulture); } } } //} double normal = 1.0; string workerDir = Path.Combine(Environment.GetEnvironmentVariable(SharedDirEnvVariableName), Environment.GetEnvironmentVariable(JobIdEnvVariableName)); executable = Path.Combine(workerDir, "exec", executable); string normalFilePath = Path.Combine(workerDir, PerformanceCoefficientFileName); if (File.Exists(normalFilePath)) { normal = double.Parse(File.ReadAllText(normalFilePath), CultureInfo.InvariantCulture); Trace.WriteLine(string.Format("Normal found within file: {0}", normal)); } else { Trace.WriteLine("Normal not found within file, computing."); normal = await RunReference(new string[] { }); } Domain domain = ResolveDomain(domainName); BenchmarkResult result = LocalExperimentRunner.RunBenchmark( experimentId, executable, arguments, benchmarkId, Path.GetFullPath(targetFile), 0, timeout, memoryLimit, outputLimit, errorLimit, domain, normal, maxRepetitions, maxTime); await AzureExperimentStorage.PutResult(experimentId, result, new CloudQueue(outputQueueUri), new CloudBlobContainer(outputBlobContainerUri)); }