Skip to content

Commit 3fe5132

Browse files
[counters] add --dsrouter switch (#5543)
We added this to `dotnet-gcdump` in fcaeae3 and `dotnet-trace` in a29f26d. This allows `dsrouter` to be launched, such as: > dotnet-counters collect --dsrouter android For finer control over the dotnet-dsrouter options, run it separately and connect to it using -p WARNING: dotnet-dsrouter is a development tool not intended for production environments. How to connect current dotnet-dsrouter pid=40432 with android device and diagnostics tooling. Start an application on android device with ONE of the following environment variables set: [Default Tracing] DOTNET_DiagnosticPorts=127.0.0.1:9000,nosuspend,connect [Startup Tracing] DOTNET_DiagnosticPorts=127.0.0.1:9000,suspend,connect See https://learn.microsoft.com/en-us/dotnet/core/diagnostics/dotnet-dsrouter for additional details and examples. info: dotnet-dsrouter-40432[0] Starting dotnet-dsrouter using pid=40432 info: dotnet-dsrouter-40432[0] Looking for Android NDK... info: dotnet-dsrouter-40432[0] Looking for Android SDK... info: dotnet-dsrouter-40432[0] Starting IPC server (dotnet-diagnostic-dsrouter-40432) <--> TCP server (127.0.0.1:9001) router. --counters is unspecified. Monitoring System.Runtime counters by default. Documentation PR: * dotnet/docs#47874
1 parent cddfe4f commit 3fe5132

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/Tools/dotnet-counters/CounterMonitor.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,10 @@ public async Task<ReturnCode> Monitor(
247247
_stdError.WriteLine(e.Message);
248248
return ReturnCode.ArgumentError;
249249
}
250+
finally
251+
{
252+
DsRouterProcessLauncher.Launcher.Cleanup();
253+
}
250254
}
251255
public async Task<ReturnCode> Collect(
252256
CancellationToken ct,
@@ -350,6 +354,10 @@ public async Task<ReturnCode> Collect(
350354
_stdError.WriteLine(e.Message);
351355
return ReturnCode.ArgumentError;
352356
}
357+
finally
358+
{
359+
DsRouterProcessLauncher.Launcher.Cleanup();
360+
}
353361
}
354362

355363
private static void ValidateNonNegative(int value, string argName)

src/Tools/dotnet-counters/Program.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ private static Command MonitorCommand()
3333
MaxHistogramOption,
3434
MaxTimeSeriesOption,
3535
DurationOption,
36-
ShowDeltasOption
36+
ShowDeltasOption,
37+
DSRouterOption
3738
};
3839

3940
monitorCommand.TreatUnmatchedTokensAsErrors = false; // see the logic in Main
@@ -50,7 +51,7 @@ private static Command MonitorCommand()
5051
maxTimeSeries: parseResult.GetValue(MaxTimeSeriesOption),
5152
duration: parseResult.GetValue(DurationOption),
5253
showDeltas: parseResult.GetValue(ShowDeltasOption),
53-
dsrouter: string.Empty
54+
dsrouter: parseResult.GetValue(DSRouterOption)
5455
));
5556

5657
return monitorCommand;
@@ -72,7 +73,8 @@ private static Command CollectCommand()
7273
ResumeRuntimeOption,
7374
MaxHistogramOption,
7475
MaxTimeSeriesOption,
75-
DurationOption
76+
DurationOption,
77+
DSRouterOption
7678
};
7779

7880
collectCommand.TreatUnmatchedTokensAsErrors = false; // see the logic in Main
@@ -90,7 +92,7 @@ private static Command CollectCommand()
9092
maxHistograms: parseResult.GetValue(MaxHistogramOption),
9193
maxTimeSeries: parseResult.GetValue(MaxTimeSeriesOption),
9294
duration: parseResult.GetValue(DurationOption),
93-
dsrouter: string.Empty));
95+
dsrouter: parseResult.GetValue(DSRouterOption)));
9496

9597
return collectCommand;
9698
}
@@ -139,6 +141,12 @@ private static Command CollectCommand()
139141
" To discover well-known provider and counter names, please visit https://learn.microsoft.com/dotnet/core/diagnostics/built-in-metrics."
140142
};
141143

144+
private static readonly Option<string> DSRouterOption =
145+
new("--dsrouter")
146+
{
147+
Description = @"The dsrouter command to start. Value should be one of ios, ios-sim, android, android-emu. Run `dotnet-dsrouter -h` for more information."
148+
};
149+
142150
private static Command ListCommand()
143151
{
144152
Command listCommand = new(

0 commit comments

Comments
 (0)