private static AzureBenchmarkResult ToAzureResult(BenchmarkResult b, AzureBenchmarkResult externalOutput) { AzureBenchmarkResult azureResult = AzureExperimentStorage.ToAzureBenchmarkResult(b); if (externalOutput != null) { azureResult.StdOut = externalOutput.StdOut; azureResult.StdOutExtStorageIdx = externalOutput.StdOutExtStorageIdx; azureResult.StdErr = externalOutput.StdErr; azureResult.StdErrExtStorageIdx = externalOutput.StdErrExtStorageIdx; } else { b.StdOut.Position = 0; azureResult.StdOut = Utils.StreamToString(b.StdOut, true); azureResult.StdOutExtStorageIdx = string.Empty; b.StdErr.Position = 0; azureResult.StdErr = Utils.StreamToString(b.StdErr, true); azureResult.StdErrExtStorageIdx = string.Empty; } return(azureResult); }
public override async Task <bool> TryDelete(IEnumerable <BenchmarkResult> toRemove) { if (toRemove == null) { throw new ArgumentNullException(nameof(toRemove)); } var benchmarks = Benchmarks; var removeSet = new HashSet <BenchmarkResult>(toRemove); if (removeSet.Count == 0) { return(true); } int n = benchmarks.Length; List <AzureBenchmarkResult> newAzureResults = new List <AzureBenchmarkResult>(n); List <BenchmarkResult> newResults = new List <BenchmarkResult>(n); List <AzureBenchmarkResult> deleteOuts = new List <AzureBenchmarkResult>(); for (int i = 0; i < n; i++) { var b = benchmarks[i]; if (!removeSet.Contains(b)) // remains { var azureResult = AzureExperimentStorage.ToAzureBenchmarkResult(b); newAzureResults.Add(azureResult); newResults.Add(b); } else // to be removed { removeSet.Remove(b); AzureBenchmarkResult ar; if (externalOutputs.TryGetValue(b, out ar)) { deleteOuts.Add(ar); } } } if (removeSet.Count != 0) { throw new ArgumentException("Some of the given results to remove do not belong to the experiment results"); } // Updating blob with results table bool success = await Upload(newAzureResults.ToArray()); if (!success) { return(false); } // Update benchmarks array Replace(newResults.ToArray()); // Deleting blobs with output foreach (var ar in deleteOuts) { try { var _ = storage.DeleteOutputs(ar); } catch (Exception ex) { Trace.WriteLine(string.Format("Exception when deleting output: {0}", ex)); } } return(true); }
public override async Task <Dictionary <BenchmarkResult, BenchmarkResult> > TryUpdateStatus(IEnumerable <BenchmarkResult> toModify, ResultStatus status) { if (toModify == null) { throw new ArgumentNullException(nameof(toModify)); } var mod = new Dictionary <BenchmarkResult, BenchmarkResult>(); foreach (var oldRes in toModify) { mod.Add(oldRes, null); } if (mod.Count == 0) { return(mod); } int n = Benchmarks.Length; var newBenchmarks = (BenchmarkResult[])Benchmarks.Clone(); var newAzureBenchmarks = new AzureBenchmarkResult[n]; for (int i = 0; i < n; i++) { var b = newBenchmarks[i]; if (mod.ContainsKey(b)) { if (b.Status != status) // updating status of this result { newBenchmarks[i] = new BenchmarkResult(b.ExperimentID, b.BenchmarkFileName, b.AcquireTime, b.NormalizedRuntime, b.TotalProcessorTime, b.WallClockTime, b.PeakMemorySizeMB, status, // <-- new status b.ExitCode, b.StdOut, b.StdErr, b.Properties); newAzureBenchmarks[i] = AzureExperimentStorage.ToAzureBenchmarkResult(newBenchmarks[i]); mod[b] = newBenchmarks[i]; } else // status is as required already { newAzureBenchmarks[i] = AzureExperimentStorage.ToAzureBenchmarkResult(b); mod.Remove(b); } } else // result doesn't change { newAzureBenchmarks[i] = AzureExperimentStorage.ToAzureBenchmarkResult(b); } } if (mod.Count == 0) { return(new Dictionary <BenchmarkResult, BenchmarkResult>()); // no changes } foreach (var item in mod) { if (item.Value == null) { throw new ArgumentException("Some of the given results to update do not belong to the experiment results"); } } bool success = await Upload(newAzureBenchmarks); if (!success) { return(null); } // Update benchmarks array Replace(newBenchmarks.ToArray()); return(mod); }