Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions src/Microsoft.Crank.Agent/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1733,6 +1733,12 @@ async Task StopJobAsync(bool abortCollection = false)

foreach (var processId in job.AllProcessIds)
{
// Should we keep the child process alive?
if (processId == job.ChildProcessId && job.KeepChildProcessAlive)
{
continue;
}

Process localProcess;

try
Expand Down Expand Up @@ -4727,6 +4733,7 @@ private static async Task<Process> StartProcess(string hostname, string benchmar
process.ErrorDataReceived += (_, e) =>
{
const string processIdMarker = "##ChildProcessId:";
const string keepAliveMarker = "KeepAlive:";

if (e != null && e.Data != null)
{
Expand All @@ -4743,12 +4750,24 @@ private static async Task<Process> StartProcess(string hostname, string benchmar
}

// Detect the app is wrapping a child process
if (e.Data.StartsWith(processIdMarker)
&& int.TryParse(e.Data.Substring(processIdMarker.Length), out var childProcessId))
if (e.Data.Trim().StartsWith(processIdMarker))
{
Log.Info($"Tracking child process id: {childProcessId}");
job.ChildProcessId = childProcessId;
stopwatch.Restart();
// ##ChildProcessId: 12345[; KeepAlive: true]
var segments = e.Data.Split(';', 2); // Max 2 arguments

if (int.TryParse(segments[0].Trim().AsSpan(processIdMarker.Length), out var childProcessId))
{
Log.Info($"Tracking child process id: {childProcessId}");
job.ChildProcessId = childProcessId;
stopwatch.Restart();
}

if (segments.Length > 1 &&
segments[1].Trim().StartsWith(keepAliveMarker, StringComparison.OrdinalIgnoreCase) &&
bool.TryParse(segments[1].Trim().AsSpan(keepAliveMarker.Length), out var keepAlive) && keepAlive)
{
job.KeepChildProcessAlive = true;
}
}
}
};
Expand Down
1 change: 1 addition & 0 deletions src/Microsoft.Crank.Controller/Documentation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ out of 1200% total available CPU time.
## Debugging

--[JOB].noClean <true|false> Whether to keep the work folder on the server or not. Default is false, such that each job is cleaned once it's finished.
--[JOB].keepChildProcessAlive <true|false> Whether to keep the child process, if tracked, alive. Default is false.
--[JOB].options.fetch <true|false> Whether the benchmark folder is downloaded. e.g., true. For Docker see '--[JOB].dockerFetchPath'
--[JOB].options.fetchOutput <filename> The name of the fetched archive. Can be a file prefix (app will add *.DATE*.zip) , or a specific name (end in *.zip) and no DATE* will be added e.g., c:\publishedapps\myApp
--[JOB].options.displayOutput <true|false> Whether to download and display the standard output of the benchmark.
Expand Down
1 change: 1 addition & 0 deletions src/Microsoft.Crank.Controller/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ Run 'crank [command] -?|-h|--help' for more information about a command.
## Debugging

--[JOB].noClean <true|false> Whether to keep the work folder on the server or not. Default is false, such that each job is cleaned once it's finished.
--[JOB].keepChildProcessAlive <true|false> Whether to keep the child process, if tracked, alive. Default is false.
--[JOB].options.fetch <true|false> Whether the benchmark folder is downloaded. e.g., true. For Docker see '--[JOB].dockerFetchPath'
--[JOB].options.fetchOutput <filename> The name of the fetched archive. Can be a file prefix (app will add *.DATE*.zip) , or a specific name (end in *.zip) and no DATE* will be added e.g., c:\publishedapps\myApp
--[JOB].options.displayOutput <true|false> Whether to download and display the standard output of the benchmark.
Expand Down
5 changes: 3 additions & 2 deletions src/Microsoft.Crank.EventSources/BenchmarksEventSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ public static void MeasureAndRegister(string name, string value, string descript
/// <summary>
/// Instructs the host agent to track CPU and memory usage for the specified process id.
/// </summary>
public static void SetChildProcessId(int pid)
public static void SetChildProcessId(int pid, bool? keepAlive = null)
{
Console.Error.WriteLine($"##ChildProcessId:{pid}");
keepAlive ??= false;
Console.Error.WriteLine($"##ChildProcessId:{pid};KeepAlive:{keepAlive}");
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
<Description>Helper classes to register metrics with the Microsoft.Crank tools.</Description>
<IsPackable>true</IsPackable>
<Authors>Microsoft</Authors>
<PackageId>Microsoft.Crank.EventSources</PackageId>
<PackageId>Microsoft.Crank.EventSources</PackageId>
<LangVersion>Latest</LangVersion>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>Latest</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions src/Microsoft.Crank.Models/Job.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ public Source Source
public string BasePath { get; set; }
public int ProcessId { get; set; }
public int ChildProcessId { get; set; }
public bool KeepChildProcessAlive { get; set; } = false;
public int ActiveProcessId => ChildProcessId > 0 ? ChildProcessId : ProcessId;
public int[] AllProcessIds => ChildProcessId > 0 ? [ChildProcessId, ProcessId] : [ProcessId];
public Dictionary<string, string> EnvironmentVariables { get; } = [];
Expand Down
Loading