Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,9 @@ public TestMLPerfExecutor(IServiceCollection dependencies, IDictionary<string, I
return base.InitializeAsync(context, cancellationToken);
}

public new Task SetupEnvironmentAsync(CancellationToken cancellationToken)
public new Task SetupEnvironmentAsync(EventContext context, CancellationToken cancellationToken)
{
return base.SetupEnvironmentAsync(cancellationToken);
return base.SetupEnvironmentAsync(context, cancellationToken);
}

public new Task CreateScratchSpace(CancellationToken cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,11 @@ protected override async Task ExecuteAsync(EventContext telemetryContext, Cancel
{
string commandLineArguments = this.GetCommandLineArguments();

using (IProcessProxy process = await this.ExecuteCommandAsync("7z", commandLineArguments, this.Compressor7zipDirectory, telemetryContext, cancellationToken)
using (IProcessProxy process = await this.ExecuteCommandAsync("7z", commandLineArguments, this.Compressor7zipDirectory, telemetryContext, cancellationToken, runElevated: true)
.ConfigureAwait(false))
{
if (!cancellationToken.IsCancellationRequested)
{
await this.LogProcessDetailsAsync(process, telemetryContext, "7Zip", logToFile: true);

process.ThrowIfWorkloadFailed();
this.CaptureMetrics(process, telemetryContext, commandLineArguments);
}
Expand All @@ -119,8 +117,33 @@ protected override async Task InitializeAsync(EventContext telemetryContext, Can
// Choose default file for compression and decompression if files/dirs are not provided.
if (string.IsNullOrWhiteSpace(this.InputFilesOrDirs))
{
await this.ExecuteCommandAsync("wget", $"https://sun.aei.polsl.pl//~sdeor/corpus/silesia.zip", this.Compressor7zipDirectory, cancellationToken);
await this.ExecuteCommandAsync("unzip", "silesia.zip -d silesia", this.Compressor7zipDirectory, cancellationToken);
using (IProcessProxy process = await this.ExecuteCommandAsync(
"wget",
$"https://sun.aei.polsl.pl//~sdeor/corpus/silesia.zip",
this.Compressor7zipDirectory,
telemetryContext,
cancellationToken,
runElevated: true))
{
if (!cancellationToken.IsCancellationRequested)
{
process.ThrowIfErrored<WorkloadException>(process.StandardError.ToString(), ErrorReason.WorkloadUnexpectedAnomaly);
}
}

using (IProcessProxy process = await this.ExecuteCommandAsync(
"unzip",
"silesia.zip -d silesia",
this.Compressor7zipDirectory,
telemetryContext,
cancellationToken,
runElevated: true))
{
if (!cancellationToken.IsCancellationRequested)
{
process.ThrowIfErrored<WorkloadException>(process.StandardError.ToString(), ErrorReason.WorkloadUnexpectedAnomaly);
}
}
}

state.Compressor7zipStateInitialized = true;
Expand Down Expand Up @@ -155,37 +178,6 @@ private void CaptureMetrics(IProcessProxy process, EventContext telemetryContext
telemetryContext);
}

private async Task ExecuteCommandAsync(string pathToExe, string commandLineArguments, string workingDirectory, CancellationToken cancellationToken)
{
if (!cancellationToken.IsCancellationRequested)
{
this.Logger.LogTraceMessage($"Executing process '{pathToExe}' '{commandLineArguments}' at directory '{workingDirectory}'.");

EventContext telemetryContext = EventContext.Persisted()
.AddContext("command", pathToExe)
.AddContext("commandArguments", commandLineArguments);

await this.Logger.LogMessageAsync($"{nameof(Compression7zipExecutor)}.ExecuteProcess", telemetryContext, async () =>
{
DateTime start = DateTime.Now;
using (IProcessProxy process = this.systemManager.ProcessManager.CreateElevatedProcess(this.Platform, pathToExe, commandLineArguments, workingDirectory))
{
this.CleanupTasks.Add(() => process.SafeKill());
await process.StartAndWaitAsync(cancellationToken)
.ConfigureAwait(false);

if (!cancellationToken.IsCancellationRequested)
{
await this.LogProcessDetailsAsync(process, telemetryContext)
.ConfigureAwait(false);

process.ThrowIfErrored<WorkloadException>(errorReason: ErrorReason.WorkloadFailed);
}
}
}).ConfigureAwait(false);
}
}

private string GetCommandLineArguments()
{
string inputFilesOrDirs = string.IsNullOrWhiteSpace(this.InputFilesOrDirs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace VirtualClient.Actions
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO.Abstractions;
using System.Runtime.InteropServices;
using System.Threading;
Expand Down Expand Up @@ -101,7 +102,7 @@ public string DotNetSdkPackageName
/// </summary>
protected override async Task ExecuteAsync(EventContext telemetryContext, CancellationToken cancellationToken)
{
Task serverTask = this.StartAspNetServerAsync(cancellationToken);
Task serverTask = this.StartAspNetServerAsync(telemetryContext, cancellationToken);
await this.RunBombardierAsync(telemetryContext, cancellationToken)
.ConfigureAwait(false);

Expand Down Expand Up @@ -150,8 +151,15 @@ await this.systemManagement.MakeFileExecutableAsync(this.bombardierFilePath, thi
// ~/vc/packages/dotnet/dotnet build -c Release -p:BenchmarksTargetFramework=net8.0
// Build the aspnetbenchmark project
string buildArgument = $"build -c Release -p:BenchmarksTargetFramework={this.TargetFramework}";
await this.ExecuteCommandAsync(this.dotnetExePath, buildArgument, this.aspnetBenchDirectory, cancellationToken)
.ConfigureAwait(false);

using (IProcessProxy process = await this.ExecuteCommandAsync(this.dotnetExePath, buildArgument, this.aspnetBenchDirectory, telemetryContext, cancellationToken, runElevated: true)
.ConfigureAwait(false))
{
if (!cancellationToken.IsCancellationRequested)
{
process.ThrowIfErrored<WorkloadException>(process.StandardError.ToString(), ErrorReason.WorkloadUnexpectedAnomaly);
}
}

// "C:\Users\vcvmadmin\Benchmarks\src\Benchmarks\bin\Release\net8.0\Benchmarks.dll"
this.aspnetBenchDllPath = this.Combine(
Expand Down Expand Up @@ -192,7 +200,7 @@ private void CaptureMetrics(IProcessProxy process, EventContext telemetryContext
}
}

private Task StartAspNetServerAsync(CancellationToken cancellationToken)
private async Task StartAspNetServerAsync(EventContext telemetryContext, CancellationToken cancellationToken)
{
// Example:
// dotnet <path_to_binary>\Benchmarks.dll --nonInteractive true --scenarios json --urls http://localhost:5000 --server Kestrel --kestrelTransport Sockets --protocol http
Expand All @@ -202,7 +210,13 @@ private Task StartAspNetServerAsync(CancellationToken cancellationToken)
string headers = @"--header ""Accept: application/json,text/html;q=0.9,application/xhtml+xml;q=0.9,application/xml;q=0.8,*/*;q=0.7"" --header ""Connection: keep-alive""";
this.serverArgument = $"{this.aspnetBenchDllPath} {options} {headers}";

return this.ExecuteCommandAsync(this.dotnetExePath, this.serverArgument, this.aspnetBenchDirectory, cancellationToken, isServer: true);
using (IProcessProxy process = await this.ExecuteCommandAsync(this.dotnetExePath, this.serverArgument, this.aspnetBenchDirectory, telemetryContext, cancellationToken, runElevated: true)
.ConfigureAwait(false))
{
this.killServer = () => process.SafeKill();
}

return;
}

private async Task RunBombardierAsync(EventContext telemetryContext, CancellationToken cancellationToken)
Expand All @@ -218,47 +232,11 @@ private async Task RunBombardierAsync(EventContext telemetryContext, Cancellatio
{
if (!cancellationToken.IsCancellationRequested)
{
await this.LogProcessDetailsAsync(process, telemetryContext, "AspNetBench", logToFile: true);

process.ThrowIfWorkloadFailed();
process.ThrowIfWorkloadFailed(process.StandardError.ToString());
this.CaptureMetrics(process, telemetryContext);
}
}
}
}

private async Task ExecuteCommandAsync(string pathToExe, string commandLineArguments, string workingDirectory, CancellationToken cancellationToken, bool isServer = false)
{
if (!cancellationToken.IsCancellationRequested)
{
this.Logger.LogTraceMessage($"Executing process '{pathToExe}' '{commandLineArguments}' at directory '{workingDirectory}'.");

EventContext telemetryContext = EventContext.Persisted()
.AddContext("command", pathToExe)
.AddContext("commandArguments", commandLineArguments);

using (IProcessProxy process = this.systemManagement.ProcessManager.CreateElevatedProcess(this.Platform, pathToExe, commandLineArguments, workingDirectory))
{
if (isServer)
{
this.killServer = () => process.SafeKill();
}

this.CleanupTasks.Add(() => process.SafeKill());
await process.StartAndWaitAsync(cancellationToken).ConfigureAwait(false);

if (!cancellationToken.IsCancellationRequested)
{
await this.LogProcessDetailsAsync(process, telemetryContext);

if (!isServer)
{
// We will kill the server at the end, exit code is -1, and we don't want it to log as failure.
process.ThrowIfWorkloadFailed();
}
}
}
}
}
}
}
Loading
Loading