Skip to content

How to halt dotnet-trace in an automated context (CI job) #2881

@danielo-unity3d

Description

@danielo-unity3d

Hi.
The dotnet-trace tool expects to end collection when it receives a Ctrl-C/break command or a newline, however, I've been unsuccessful setting up a script to do this in automated fashion. How exactly are we to send the termination event to the tracing tool.

The basic setup is:

echo "Creating dotnet-trace with diagnostic port"

$psi = New-Object System.Diagnostics.ProcessStartInfo;
$psi.FileName = "dotnet-trace"
$psi.Arguments = @("collect", "--output", "AppToMonitor-diag.nettrace", "--diagnostic-port", "AppToMonitor-diag.sock")
$psi.UseShellExecute = $false
$psi.RedirectStandardInput = $true

$p = [System.Diagnostics.Process]::Start($psi);

# Time passes, the application is run, one or more times, etc
# Perhaps it is run from another window in parallel, having set
sleep 10

The output of the trace program is:

No profile or providers specified, defaulting to trace profile 'cpu-sampling'

Provider Name                           Keywords            Level               Enabled By
Microsoft-DotNETCore-SampleProfiler     0x0000F00000000000  Informational(4)    --profile 
Microsoft-Windows-DotNETRuntime         0x00000014C14FCCBD  Informational(4)    --profile 

Waiting for connection on /home/username/Unity.Licensing.Client-diag.sock
Start an application with the following environment variable: DOTNET_DiagnosticPorts=/home/username/AppToMonitor-diag.sock

Then, to attempt to halt the application, any input should work, since a newline also should terminate the tool:

$p.StandardInput.WriteLine([System.Text.Encoding]::ASCII.GetString(3));

I can't seem to get it to stop gracefully on Windows (such that the trace is then legible, and the symbols are correctly identified, ie. missing Rundown events?).
On Linux or MacOS (because we need this to be cross-platform), then we could just resort to calling kill -SIGQUIT $pid, which appears to notify the trace tool correctly.

See issue #976, where using the --duration flag is difficult for us, as we don't know how long the job will run (varies by multiple orders of magnitude, and changes according to load on the host)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions