From 2c2a5c5d9b73ffb48a9a338cf5fa70df4c601ecd Mon Sep 17 00:00:00 2001 From: James Li Date: Wed, 21 Aug 2024 15:48:35 -0700 Subject: [PATCH 1/6] support for online config file --- .../SuperBenchmark/SuperBenchmarkExecutor.cs | 35 ++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/src/VirtualClient/VirtualClient.Actions/SuperBenchmark/SuperBenchmarkExecutor.cs b/src/VirtualClient/VirtualClient.Actions/SuperBenchmark/SuperBenchmarkExecutor.cs index 141ef7b91d..f929b1d20e 100644 --- a/src/VirtualClient/VirtualClient.Actions/SuperBenchmark/SuperBenchmarkExecutor.cs +++ b/src/VirtualClient/VirtualClient.Actions/SuperBenchmark/SuperBenchmarkExecutor.cs @@ -7,14 +7,14 @@ namespace VirtualClient.Actions using System.Collections.Generic; using System.IO; using System.IO.Abstractions; - using System.Runtime.InteropServices; + using System.Net.Http; using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis; using Microsoft.Extensions.DependencyInjection; + using Polly; using VirtualClient.Common; using VirtualClient.Common.Extensions; - using VirtualClient.Common.Platform; using VirtualClient.Common.Telemetry; using VirtualClient.Contracts; using VirtualClient.Contracts.Metadata; @@ -26,6 +26,7 @@ namespace VirtualClient.Actions public class SuperBenchmarkExecutor : VirtualClientComponent { private const string SuperBenchmarkRunShell = "RunSuperBenchmark.sh"; + private string configFileFullPath; private IFileSystem fileSystem; private IPackageManager packageManager; @@ -180,6 +181,32 @@ protected override async Task InitializeAsync(EventContext telemetryContext, Can } await this.stateManager.SaveStateAsync($"{nameof(SuperBenchmarkState)}", state, cancellationToken); + + // download config file if a link is provided - do this everytime in case the config file is saved online and has changed. + if (this.ConfigurationFile.StartsWith("http")) + { + var configFileUri = new Uri(this.ConfigurationFile); + string configFileName = Path.GetFileName(configFileUri.AbsolutePath); + string configFullPath = this.PlatformSpecifics.Combine(this.PlatformSpecifics.PackagesDirectory, configFileName); + + using (var client = new HttpClient()) + { + await Policy.Handle().WaitAndRetryAsync(5, (retries) => TimeSpan.FromSeconds(retries * 2)).ExecuteAsync(async () => + { + var response = await client.GetAsync(configFileUri); + using (var fs = new FileStream(configFullPath, FileMode.Create, FileAccess.Write, FileShare.Write)) + { + await response.Content.CopyToAsync(fs); + } + }); + } + + this.configFileFullPath = configFullPath; + } + else + { + this.configFileFullPath = this.ConfigurationFile; + } } private async Task ExecuteSbCommandAsync(string command, string commandArguments, string workingDirectory, EventContext telemetryContext, CancellationToken cancellationToken, bool runElevated) @@ -220,7 +247,7 @@ private async Task CaptureMetricsAsync(IProcessProxy process, string commandArgu process.StartTime, process.ExitTime, metrics, - metricCategorization: $"{this.ConfigurationFile}", + metricCategorization: $"{this.configFileFullPath}", scenarioArguments: commandArguments, this.Tags, telemetryContext); @@ -232,7 +259,7 @@ private async Task CaptureMetricsAsync(IProcessProxy process, string commandArgu private string GetCommandLineArguments() { - return @$"run --host-list localhost -c {this.ConfigurationFile}"; + return @$"run --host-list localhost -c {this.configFileFullPath}"; } internal class SuperBenchmarkState : State From 7540f5752ccc8dfa5cb4d51fe65d117e699517d1 Mon Sep 17 00:00:00 2001 From: James Li Date: Wed, 21 Aug 2024 15:56:19 -0700 Subject: [PATCH 2/6] support for custom sb repo link --- .../SuperBenchmark/SuperBenchmarkExecutor.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/VirtualClient/VirtualClient.Actions/SuperBenchmark/SuperBenchmarkExecutor.cs b/src/VirtualClient/VirtualClient.Actions/SuperBenchmark/SuperBenchmarkExecutor.cs index f929b1d20e..7a79cdb4d2 100644 --- a/src/VirtualClient/VirtualClient.Actions/SuperBenchmark/SuperBenchmarkExecutor.cs +++ b/src/VirtualClient/VirtualClient.Actions/SuperBenchmark/SuperBenchmarkExecutor.cs @@ -26,6 +26,7 @@ namespace VirtualClient.Actions public class SuperBenchmarkExecutor : VirtualClientComponent { private const string SuperBenchmarkRunShell = "RunSuperBenchmark.sh"; + private const string DefaultSBRepoLink = "https://github.com/microsoft/superbenchmark"; private string configFileFullPath; private IFileSystem fileSystem; @@ -83,6 +84,17 @@ public string ConfigurationFile } } + /// + /// Link to the superbench repo. + /// + public string RepositoryLink + { + get + { + return this.Parameters.GetValue(nameof(SuperBenchmarkExecutor.RepositoryLink), DefaultSBRepoLink); + } + } + /// /// The username to execute superbench, required. /// @@ -163,7 +175,7 @@ protected override async Task InitializeAsync(EventContext telemetryContext, Can string cloneDir = this.PlatformSpecifics.Combine(this.PlatformSpecifics.PackagesDirectory, "superbenchmark"); if (!this.fileSystem.Directory.Exists(cloneDir)) { - await this.ExecuteSbCommandAsync("git", $"clone -b v{this.Version} https://github.com/microsoft/superbenchmark", this.PlatformSpecifics.PackagesDirectory, telemetryContext, cancellationToken, true); + await this.ExecuteSbCommandAsync("git", $"clone -b v{this.Version} {this.RepositoryLink}", this.PlatformSpecifics.PackagesDirectory, telemetryContext, cancellationToken, true); } foreach (string file in this.fileSystem.Directory.GetFiles(this.PlatformSpecifics.GetScriptPath("superbenchmark"))) From 65e428dd7d0a604752611fefedc7f48933824d52 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Fri, 23 Aug 2024 20:25:37 +0000 Subject: [PATCH 3/6] SB custom github link --- .../SuperBenchmark/SuperBenchmarkExecutor.cs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/VirtualClient/VirtualClient.Actions/SuperBenchmark/SuperBenchmarkExecutor.cs b/src/VirtualClient/VirtualClient.Actions/SuperBenchmark/SuperBenchmarkExecutor.cs index 7a79cdb4d2..207d1ea03e 100644 --- a/src/VirtualClient/VirtualClient.Actions/SuperBenchmark/SuperBenchmarkExecutor.cs +++ b/src/VirtualClient/VirtualClient.Actions/SuperBenchmark/SuperBenchmarkExecutor.cs @@ -28,6 +28,7 @@ public class SuperBenchmarkExecutor : VirtualClientComponent private const string SuperBenchmarkRunShell = "RunSuperBenchmark.sh"; private const string DefaultSBRepoLink = "https://github.com/microsoft/superbenchmark"; private string configFileFullPath; + private string repositoryName; private IFileSystem fileSystem; private IPackageManager packageManager; @@ -119,7 +120,7 @@ public string SuperBenchmarkDirectory { get { - return this.PlatformSpecifics.Combine(this.PlatformSpecifics.PackagesDirectory, "superbenchmark"); + return this.PlatformSpecifics.Combine(this.PlatformSpecifics.PackagesDirectory, this.repositoryName); } } @@ -169,16 +170,19 @@ protected override async Task InitializeAsync(EventContext telemetryContext, Can if (!state.SuperBenchmarkInitialized) { + var repositoryLinkUri = new Uri(this.ConfigurationFile); + this.repositoryName = Path.GetFileName(repositoryLinkUri.AbsolutePath); + // This is to grant directory folders for await this.systemManager.MakeFilesExecutableAsync(this.PlatformSpecifics.CurrentDirectory, this.Platform, cancellationToken); - string cloneDir = this.PlatformSpecifics.Combine(this.PlatformSpecifics.PackagesDirectory, "superbenchmark"); + string cloneDir = this.PlatformSpecifics.Combine(this.PlatformSpecifics.PackagesDirectory, "this.repositoryName"); if (!this.fileSystem.Directory.Exists(cloneDir)) { await this.ExecuteSbCommandAsync("git", $"clone -b v{this.Version} {this.RepositoryLink}", this.PlatformSpecifics.PackagesDirectory, telemetryContext, cancellationToken, true); } - foreach (string file in this.fileSystem.Directory.GetFiles(this.PlatformSpecifics.GetScriptPath("superbenchmark"))) + foreach (string file in this.fileSystem.Directory.GetFiles(this.PlatformSpecifics.GetScriptPath("this.repositoryName"))) { this.fileSystem.File.Copy( file, @@ -237,7 +241,7 @@ private async Task CaptureMetricsAsync(IProcessProxy process, string commandArgu if (!cancellationToken.IsCancellationRequested) { this.MetadataContract.AddForScenario( - "SuperBenchmark", + this.repositoryName, process.FullCommand(), toolVersion: null); @@ -254,8 +258,8 @@ private async Task CaptureMetricsAsync(IProcessProxy process, string commandArgu IList metrics = parser.Parse(); this.Logger.LogMetrics( - toolName: "SuperBenchmark", - scenarioName: "SuperBenchmark", + toolName: this.repositoryName, + scenarioName: this.repositoryName, process.StartTime, process.ExitTime, metrics, From 850fa4cf1d63a8f1a33326afeaf7067b8cc10f0f Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Fri, 23 Aug 2024 21:30:45 +0000 Subject: [PATCH 4/6] bug fix --- .../SuperBenchmark/SuperBenchmarkExecutor.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/VirtualClient/VirtualClient.Actions/SuperBenchmark/SuperBenchmarkExecutor.cs b/src/VirtualClient/VirtualClient.Actions/SuperBenchmark/SuperBenchmarkExecutor.cs index 207d1ea03e..1e755dd0de 100644 --- a/src/VirtualClient/VirtualClient.Actions/SuperBenchmark/SuperBenchmarkExecutor.cs +++ b/src/VirtualClient/VirtualClient.Actions/SuperBenchmark/SuperBenchmarkExecutor.cs @@ -170,19 +170,19 @@ protected override async Task InitializeAsync(EventContext telemetryContext, Can if (!state.SuperBenchmarkInitialized) { - var repositoryLinkUri = new Uri(this.ConfigurationFile); + var repositoryLinkUri = new Uri(this.RepositoryLink); this.repositoryName = Path.GetFileName(repositoryLinkUri.AbsolutePath); // This is to grant directory folders for await this.systemManager.MakeFilesExecutableAsync(this.PlatformSpecifics.CurrentDirectory, this.Platform, cancellationToken); - string cloneDir = this.PlatformSpecifics.Combine(this.PlatformSpecifics.PackagesDirectory, "this.repositoryName"); + string cloneDir = this.PlatformSpecifics.Combine(this.PlatformSpecifics.PackagesDirectory, this.repositoryName); if (!this.fileSystem.Directory.Exists(cloneDir)) { await this.ExecuteSbCommandAsync("git", $"clone -b v{this.Version} {this.RepositoryLink}", this.PlatformSpecifics.PackagesDirectory, telemetryContext, cancellationToken, true); } - foreach (string file in this.fileSystem.Directory.GetFiles(this.PlatformSpecifics.GetScriptPath("this.repositoryName"))) + foreach (string file in this.fileSystem.Directory.GetFiles(this.PlatformSpecifics.GetScriptPath("superbenchmark"))) { this.fileSystem.File.Copy( file, From 85baff6488a7de4cd8602727498d857255d8d353 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Mon, 26 Aug 2024 18:08:02 +0000 Subject: [PATCH 5/6] inf file donwload --- .../SuperBenchmark/SuperBenchmarkExecutor.cs | 52 +++++++++---------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/src/VirtualClient/VirtualClient.Actions/SuperBenchmark/SuperBenchmarkExecutor.cs b/src/VirtualClient/VirtualClient.Actions/SuperBenchmark/SuperBenchmarkExecutor.cs index 1e755dd0de..b35b262824 100644 --- a/src/VirtualClient/VirtualClient.Actions/SuperBenchmark/SuperBenchmarkExecutor.cs +++ b/src/VirtualClient/VirtualClient.Actions/SuperBenchmark/SuperBenchmarkExecutor.cs @@ -165,6 +165,32 @@ protected override async Task ExecuteAsync(EventContext telemetryContext, Cancel /// protected override async Task InitializeAsync(EventContext telemetryContext, CancellationToken cancellationToken) { + // download config file if a link is provided + if (this.ConfigurationFile.StartsWith("http")) + { + var configFileUri = new Uri(this.ConfigurationFile); + string configFileName = Path.GetFileName(configFileUri.AbsolutePath); + string configFullPath = this.PlatformSpecifics.Combine(this.SuperBenchmarkDirectory, configFileName); + + using (var client = new HttpClient()) + { + await Policy.Handle().WaitAndRetryAsync(5, (retries) => TimeSpan.FromSeconds(retries * 2)).ExecuteAsync(async () => + { + var response = await client.GetAsync(configFileUri); + using (var fs = new FileStream(configFullPath, FileMode.Create, FileAccess.Write, FileShare.Write)) + { + await response.Content.CopyToAsync(fs); + } + }); + } + + this.configFileFullPath = configFullPath; + } + else + { + this.configFileFullPath = this.ConfigurationFile; + } + SuperBenchmarkState state = await this.stateManager.GetStateAsync($"{nameof(SuperBenchmarkState)}", cancellationToken) ?? new SuperBenchmarkState(); @@ -197,32 +223,6 @@ protected override async Task InitializeAsync(EventContext telemetryContext, Can } await this.stateManager.SaveStateAsync($"{nameof(SuperBenchmarkState)}", state, cancellationToken); - - // download config file if a link is provided - do this everytime in case the config file is saved online and has changed. - if (this.ConfigurationFile.StartsWith("http")) - { - var configFileUri = new Uri(this.ConfigurationFile); - string configFileName = Path.GetFileName(configFileUri.AbsolutePath); - string configFullPath = this.PlatformSpecifics.Combine(this.PlatformSpecifics.PackagesDirectory, configFileName); - - using (var client = new HttpClient()) - { - await Policy.Handle().WaitAndRetryAsync(5, (retries) => TimeSpan.FromSeconds(retries * 2)).ExecuteAsync(async () => - { - var response = await client.GetAsync(configFileUri); - using (var fs = new FileStream(configFullPath, FileMode.Create, FileAccess.Write, FileShare.Write)) - { - await response.Content.CopyToAsync(fs); - } - }); - } - - this.configFileFullPath = configFullPath; - } - else - { - this.configFileFullPath = this.ConfigurationFile; - } } private async Task ExecuteSbCommandAsync(string command, string commandArguments, string workingDirectory, EventContext telemetryContext, CancellationToken cancellationToken, bool runElevated) From 1f7591bd4a31e0605b7c6ef8f26392510b27197d Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Mon, 26 Aug 2024 19:37:34 +0000 Subject: [PATCH 6/6] init different repo --- .../SuperBenchmark/SuperBenchmarkExecutor.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/VirtualClient/VirtualClient.Actions/SuperBenchmark/SuperBenchmarkExecutor.cs b/src/VirtualClient/VirtualClient.Actions/SuperBenchmark/SuperBenchmarkExecutor.cs index b35b262824..1cf7d11495 100644 --- a/src/VirtualClient/VirtualClient.Actions/SuperBenchmark/SuperBenchmarkExecutor.cs +++ b/src/VirtualClient/VirtualClient.Actions/SuperBenchmark/SuperBenchmarkExecutor.cs @@ -165,6 +165,9 @@ protected override async Task ExecuteAsync(EventContext telemetryContext, Cancel /// protected override async Task InitializeAsync(EventContext telemetryContext, CancellationToken cancellationToken) { + var repositoryLinkUri = new Uri(this.RepositoryLink); + this.repositoryName = Path.GetFileName(repositoryLinkUri.AbsolutePath); + // download config file if a link is provided if (this.ConfigurationFile.StartsWith("http")) { @@ -191,14 +194,11 @@ await Policy.Handle().WaitAndRetryAsync(5, (retries) => TimeSpan.From this.configFileFullPath = this.ConfigurationFile; } - SuperBenchmarkState state = await this.stateManager.GetStateAsync($"{nameof(SuperBenchmarkState)}", cancellationToken) + SuperBenchmarkState state = await this.stateManager.GetStateAsync(this.repositoryName, cancellationToken) ?? new SuperBenchmarkState(); if (!state.SuperBenchmarkInitialized) { - var repositoryLinkUri = new Uri(this.RepositoryLink); - this.repositoryName = Path.GetFileName(repositoryLinkUri.AbsolutePath); - // This is to grant directory folders for await this.systemManager.MakeFilesExecutableAsync(this.PlatformSpecifics.CurrentDirectory, this.Platform, cancellationToken); @@ -222,7 +222,7 @@ await Policy.Handle().WaitAndRetryAsync(5, (retries) => TimeSpan.From state.SuperBenchmarkInitialized = true; } - await this.stateManager.SaveStateAsync($"{nameof(SuperBenchmarkState)}", state, cancellationToken); + await this.stateManager.SaveStateAsync(this.repositoryName, state, cancellationToken); } private async Task ExecuteSbCommandAsync(string command, string commandArguments, string workingDirectory, EventContext telemetryContext, CancellationToken cancellationToken, bool runElevated)