-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Superbenchmark executor: online inference config file and custom repo link #369
Open
LiYueqian-James
wants to merge
8
commits into
microsoft:main
Choose a base branch
from
LiYueqian-James:yueqianli/SBConfigAndRepo
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2c2a5c5
support for online config file
LiYueqian-James 7540f57
support for custom sb repo link
LiYueqian-James 65e428d
SB custom github link
850fa4c
bug fix
85baff6
inf file donwload
1f7591b
init different repo
e6eca5b
Merge branch 'main' into yueqianli/SBConfigAndRepo
LiYueqian-James 8a0ca65
Merge branch 'main' into yueqianli/SBConfigAndRepo
LiYueqian-James File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,9 @@ 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 string repositoryName; | ||
|
||
private IFileSystem fileSystem; | ||
private IPackageManager packageManager; | ||
|
@@ -82,6 +85,17 @@ public string ConfigurationFile | |
} | ||
} | ||
|
||
/// <summary> | ||
/// Link to the superbench repo. | ||
/// </summary> | ||
public string RepositoryLink | ||
{ | ||
get | ||
{ | ||
return this.Parameters.GetValue<string>(nameof(SuperBenchmarkExecutor.RepositoryLink), DefaultSBRepoLink); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// The username to execute superbench, required. | ||
/// </summary> | ||
|
@@ -106,7 +120,7 @@ public string SuperBenchmarkDirectory | |
{ | ||
get | ||
{ | ||
return this.PlatformSpecifics.Combine(this.PlatformSpecifics.PackagesDirectory, "superbenchmark"); | ||
return this.PlatformSpecifics.Combine(this.PlatformSpecifics.PackagesDirectory, this.repositoryName); | ||
} | ||
} | ||
|
||
|
@@ -151,18 +165,47 @@ protected override async Task ExecuteAsync(EventContext telemetryContext, Cancel | |
/// </summary> | ||
protected override async Task InitializeAsync(EventContext telemetryContext, CancellationToken cancellationToken) | ||
{ | ||
SuperBenchmarkState state = await this.stateManager.GetStateAsync<SuperBenchmarkState>($"{nameof(SuperBenchmarkState)}", 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")) | ||
{ | ||
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()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's not add un-unit testable code here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are cmd line based methods preferred? like wget or curl? |
||
{ | ||
await Policy.Handle<Exception>().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<SuperBenchmarkState>(this.repositoryName, cancellationToken) | ||
?? new SuperBenchmarkState(); | ||
|
||
if (!state.SuperBenchmarkInitialized) | ||
{ | ||
// 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} 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"))) | ||
|
@@ -179,7 +222,7 @@ protected override async Task InitializeAsync(EventContext telemetryContext, Can | |
state.SuperBenchmarkInitialized = true; | ||
} | ||
|
||
await this.stateManager.SaveStateAsync<SuperBenchmarkState>($"{nameof(SuperBenchmarkState)}", state, cancellationToken); | ||
await this.stateManager.SaveStateAsync<SuperBenchmarkState>(this.repositoryName, state, cancellationToken); | ||
} | ||
|
||
private async Task ExecuteSbCommandAsync(string command, string commandArguments, string workingDirectory, EventContext telemetryContext, CancellationToken cancellationToken, bool runElevated) | ||
|
@@ -198,7 +241,7 @@ private async Task CaptureMetricsAsync(IProcessProxy process, string commandArgu | |
if (!cancellationToken.IsCancellationRequested) | ||
{ | ||
this.MetadataContract.AddForScenario( | ||
"SuperBenchmark", | ||
this.repositoryName, | ||
process.FullCommand(), | ||
toolVersion: null); | ||
|
||
|
@@ -215,12 +258,12 @@ private async Task CaptureMetricsAsync(IProcessProxy process, string commandArgu | |
IList<Metric> metrics = parser.Parse(); | ||
|
||
this.Logger.LogMetrics( | ||
toolName: "SuperBenchmark", | ||
scenarioName: "SuperBenchmark", | ||
toolName: this.repositoryName, | ||
scenarioName: this.repositoryName, | ||
process.StartTime, | ||
process.ExitTime, | ||
metrics, | ||
metricCategorization: $"{this.ConfigurationFile}", | ||
metricCategorization: $"{this.configFileFullPath}", | ||
scenarioArguments: commandArguments, | ||
this.Tags, | ||
telemetryContext); | ||
|
@@ -232,7 +275,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 | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to change the repository link? Even if we need to support extra config?