Skip to content

Commit

Permalink
Add background profiling feature to executors that are missing it.
Browse files Browse the repository at this point in the history
  • Loading branch information
brdeyo committed Oct 31, 2023
1 parent e79cdb8 commit b27f0e4
Show file tree
Hide file tree
Showing 14 changed files with 340 additions and 309 deletions.
4 changes: 2 additions & 2 deletions .pipelines/azure-pipelines-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ resources:
options: --entrypoint=""

variables:
VcVersion : 1.11.6
VcVersion : 1.11.7
ROOT: $(Build.SourcesDirectory)
CDP_DEFINITION_BUILD_COUNT: $[counter('', 0)] # needed for onebranch.pipeline.version task https://aka.ms/obpipelines/versioning
ENABLE_PRS_DELAYSIGN: 1
Expand All @@ -42,7 +42,7 @@ stages:
displayName: 'Allow scripts to be executable on Linux'

# Ensure the artifact output/bin/obj directories are clean.
# - script: $(Build.SourcesDirectory)/clean.cmd
# - script: $(Build.SourcesDirectory)/clean.cmd
# displayName: 'Clean Output Directories'

# Build the repo.
Expand Down
2 changes: 1 addition & 1 deletion .pipelines/azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pool:
vmImage: windows-latest

variables:
VcVersion : 1.11.6
VcVersion : 1.11.7
ROOT: $(Build.SourcesDirectory)
CDP_DEFINITION_BUILD_COUNT: $[counter('', 0)] # needed for onebranch.pipeline.version task https://aka.ms/obpipelines/versioning
ENABLE_PRS_DELAYSIGN: 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,65 +244,68 @@ private Task ExecuteWorkloadAsync(EventContext telemetryContext, CancellationTok
}
}

// Run Workload
DateTime startTime = DateTime.UtcNow;
foreach (string definition in this.Definitions)
using (BackgroundOperations profiling = BackgroundOperations.BeginProfiling(this, cancellationToken))
{
this.OutFileName = $"{DateTimeOffset.Now.ToUnixTimeSeconds()}.out";

// Workload execution
string arguments = this.GenerateCommandArguments(definition);
string commandArguments = $"{baseArg} {this.ExecutablePath} {arguments}";

using (IProcessProxy process = this.systemManagement.ProcessManager.CreateProcess(psexec, commandArguments, this.psexecDir))
// Run Workload
foreach (string definition in this.Definitions)
{
this.CleanupTasks.Add(() => process.SafeKill());
this.OutFileName = $"{DateTimeOffset.Now.ToUnixTimeSeconds()}.out";

// Workload execution
string arguments = this.GenerateCommandArguments(definition);
string commandArguments = $"{baseArg} {this.ExecutablePath} {arguments}";

try
using (IProcessProxy process = this.systemManagement.ProcessManager.CreateProcess(psexec, commandArguments, this.psexecDir))
{
await process.StartAndWaitAsync(cancellationToken).ConfigureAwait(false);
this.CleanupTasks.Add(() => process.SafeKill());

if (!cancellationToken.IsCancellationRequested)
try
{
await this.LogProcessDetailsAsync(process, telemetryContext);
process.ThrowIfErrored<WorkloadException>(ProcessProxy.DefaultSuccessCodes, errorReason: ErrorReason.WorkloadFailed);
await process.StartAndWaitAsync(cancellationToken).ConfigureAwait(false);

if (!cancellationToken.IsCancellationRequested)
{
await this.LogProcessDetailsAsync(process, telemetryContext);
process.ThrowIfErrored<WorkloadException>(ProcessProxy.DefaultSuccessCodes, errorReason: ErrorReason.WorkloadFailed);

}
}
}
finally
{
if (!process.HasExited)
finally
{
process.Kill();
if (!process.HasExited)
{
process.Kill();
}
}
}
}

// Result Preparation
string commandArguments2 = $"{baseArg} {this.ExecutablePath} --in={this.OutFileName} --export=result.xml";
using (IProcessProxy process = this.systemManagement.ProcessManager.CreateProcess(psexec, commandArguments2, this.psexecDir))
{
this.CleanupTasks.Add(() => process.SafeKill());

try
// Result Preparation
string commandArguments2 = $"{baseArg} {this.ExecutablePath} --in={this.OutFileName} --export=result.xml";
using (IProcessProxy process = this.systemManagement.ProcessManager.CreateProcess(psexec, commandArguments2, this.psexecDir))
{
await process.StartAndWaitAsync(cancellationToken).ConfigureAwait(false);
this.CleanupTasks.Add(() => process.SafeKill());

if (!cancellationToken.IsCancellationRequested)
try
{
await this.LogProcessDetailsAsync(process, telemetryContext);
process.ThrowIfErrored<WorkloadException>(ProcessProxy.DefaultSuccessCodes, errorReason: ErrorReason.WorkloadFailed);
foreach (Metric metric in this.CaptureResults(process, commandArguments, definition, telemetryContext))
await process.StartAndWaitAsync(cancellationToken).ConfigureAwait(false);

if (!cancellationToken.IsCancellationRequested)
{
metrics.Add(metric);
await this.LogProcessDetailsAsync(process, telemetryContext);
process.ThrowIfErrored<WorkloadException>(ProcessProxy.DefaultSuccessCodes, errorReason: ErrorReason.WorkloadFailed);
foreach (Metric metric in this.CaptureResults(process, commandArguments, definition, telemetryContext))
{
metrics.Add(metric);
}
}
}
}
finally
{
if (!process.HasExited)
finally
{
process.Kill();
if (!process.HasExited)
{
process.Kill();
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,46 +100,49 @@ protected override async Task ExecuteAsync(EventContext telemetryContext, Cancel
DateTime startTime = DateTime.UtcNow;
string output = string.Empty;

switch (this.Platform)
using (BackgroundOperations profiling = BackgroundOperations.BeginProfiling(this, cancellationToken))
{
case PlatformID.Unix:
using (IProcessProxy process = await this.ExecuteCommandAsync("make", commandArguments, this.CoreMarkProDirectory, telemetryContext, cancellationToken))
{
if (!cancellationToken.IsCancellationRequested)
switch (this.Platform)
{
case PlatformID.Unix:
using (IProcessProxy process = await this.ExecuteCommandAsync("make", commandArguments, this.CoreMarkProDirectory, telemetryContext, cancellationToken))
{
if (process.IsErrored())
if (!cancellationToken.IsCancellationRequested)
{
if (process.IsErrored())
{
await this.LogProcessDetailsAsync(process, telemetryContext, "CoreMark Pro", logToFile: true);
process.ThrowIfWorkloadFailed();
}

await this.LogProcessDetailsAsync(process, telemetryContext, "CoreMark Pro", logToFile: true);
process.ThrowIfWorkloadFailed();
output = process.StandardOutput.ToString();
}

await this.LogProcessDetailsAsync(process, telemetryContext, "CoreMark Pro", logToFile: true);
output = process.StandardOutput.ToString();
}
}

break;
break;

case PlatformID.Win32NT:
DependencyPath cygwinPackage = await this.packageManager.GetPackageAsync("cygwin", CancellationToken.None)
.ConfigureAwait(false);
case PlatformID.Win32NT:
DependencyPath cygwinPackage = await this.packageManager.GetPackageAsync("cygwin", CancellationToken.None)
.ConfigureAwait(false);

using (IProcessProxy process = await this.ExecuteCygwinBashAsync($"make {commandArguments}", this.CoreMarkProDirectory, cygwinPackage.Path, telemetryContext, cancellationToken))
{
if (!cancellationToken.IsCancellationRequested)
using (IProcessProxy process = await this.ExecuteCygwinBashAsync($"make {commandArguments}", this.CoreMarkProDirectory, cygwinPackage.Path, telemetryContext, cancellationToken))
{
if (process.IsErrored())
if (!cancellationToken.IsCancellationRequested)
{
if (process.IsErrored())
{
await this.LogProcessDetailsAsync(process, telemetryContext, "CoreMark Pro", logToFile: true);
process.ThrowIfWorkloadFailed();
}

await this.LogProcessDetailsAsync(process, telemetryContext, "CoreMark Pro", logToFile: true);
process.ThrowIfWorkloadFailed();
output = process.StandardOutput.ToString();
}

await this.LogProcessDetailsAsync(process, telemetryContext, "CoreMark Pro", logToFile: true);
output = process.StandardOutput.ToString();
}
}

break;
break;
}
}

this.MetadataContract.AddForScenario(
Expand Down
Loading

0 comments on commit b27f0e4

Please sign in to comment.