COMMANDS
list Display a list of counter names and descriptions
+ ps Display a list of dotnet processes that can be monitored
monitor Display periodically refreshing values of selected counters
LIST
COMMANDS
collect Collects a diagnostic trace from a currently running process
- list-processes Lists dotnet processes that can be attached to.
+ ps Lists dotnet processes that can be attached to.
list-profiles Lists pre-built tracing profiles with a description of what providers and filters are in each profile.
convert Converts traces to alternate formats for use with alternate trace analysis tools
collect Capture dumps from a process
analyze Starts an interactive shell with debugging commands to explore a dump
+ ps Display a list of dotnet processes to create dump from
COLLECT
*COMMANDS*
list Display a list of counter names and descriptions
+ ps Display a list of dotnet processes that can be monitored
monitor Display periodically refreshing values of selected counters
+*PS*
+ dotnet-counters ps
+
+ Display a list of dotnet processes that can be monitored.
+
+ Examples:
+ > dotnet-counters ps
+
+ 15683 WebApi /home/suwhang/repos/WebApi/WebApi
+ 16324 dotnet /usr/local/share/dotnet/dotnet
+
*LIST*
dotnet-counters list [-h|--help]
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Security.Principal;
+using System.Text;
using System.Text.RegularExpressions;
namespace Microsoft.Diagnostics.Tools.RuntimeClient
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.CommandLine;
+using System.Diagnostics;
+using System.Linq;
+using System.Text;
+
+using Microsoft.Diagnostics.Tools.RuntimeClient;
+
+namespace Microsoft.Internal.Common.Commands
+{
+ public class ProcessStatusCommandHandler
+ {
+ /// <summary>
+ /// Print the current list of available .NET core processes for diagnosis and their statuses
+ /// </summary>
+ public static void PrintProcessStatus(IConsole console)
+ {
+ try
+ {
+ StringBuilder sb = new StringBuilder();
+ var processes = EventPipeClient.ListAvailablePorts()
+ .Select(GetProcessById)
+ .Where(process => process != null)
+ .OrderBy(process => process.ProcessName)
+ .ThenBy(process => process.Id);
+
+ foreach (var process in processes)
+ {
+ try
+ {
+ sb.Append($"{process.Id, 10} {process.ProcessName, -10} {process.MainModule.FileName}\n");
+ }
+ catch (InvalidOperationException)
+ {
+ sb.Append($"{process.Id, 10} {process.ProcessName, -10} [Elevated process - cannot determine path]\n");
+ }
+ }
+ console.Out.WriteLine(sb.ToString());
+ }
+ catch (InvalidOperationException ex)
+ {
+ console.Out.WriteLine(ex.ToString());
+ }
+ }
+
+ private static Process GetProcessById(int processId)
+ {
+ try
+ {
+ return Process.GetProcessById(processId);
+ }
+ catch (ArgumentException)
+ {
+ return null;
+ }
+ }
+ }
+}
using System.Threading.Tasks;
using System.Collections.Generic;
using Microsoft.Diagnostics.Tools.RuntimeClient;
+using Microsoft.Internal.Common.Commands;
namespace Microsoft.Diagnostics.Tools.Counters
{
new Option[] { },
handler: CommandHandler.Create<IConsole>(List));
- private static Command ListProcessesCommand() =>
+ private static Command ProcessStatusCommand() =>
new Command(
- "list-processes",
+ "ps",
"Display a list of dotnet processes that can be monitored.",
new Option[] { },
- handler: CommandHandler.Create<IConsole>(ListProcesses));
-
- private static int ListProcesses(IConsole console)
- {
- var processes = EventPipeClient.ListAvailablePorts()
- .Select(GetProcess)
- .Where(process => process != null)
- .OrderBy(process => process.ProcessName)
- .ThenBy(process => process.Id);
-
- foreach (var process in processes)
- {
- try
- {
- console.Out.WriteLine($"{process.Id, 10} {process.ProcessName, -10} {process.MainModule.FileName}");
- }
- catch (Exception)
- {
- console.Out.WriteLine($"{process.Id, 10} {process.ProcessName, -10} [Elevated process - cannot determine path]");
- }
- }
-
- return 0;
- }
-
- private static System.Diagnostics.Process GetProcess(int processId)
- {
- try
- {
- return System.Diagnostics.Process.GetProcessById(processId);
- }
- catch (ArgumentException)
- {
- return null;
- }
- }
+ handler: CommandHandler.Create<IConsole>(ProcessStatusCommandHandler.PrintProcessStatus));
public static int List(IConsole console)
{
var parser = new CommandLineBuilder()
.AddCommand(MonitorCommand())
.AddCommand(ListCommand())
- .AddCommand(ListProcessesCommand())
+ .AddCommand(ProcessStatusCommand())
.UseDefaults()
.Build();
return parser.InvokeAsync(args);
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)..\dotnet-trace\Extensions.cs" Link="Extensions.cs" />
+ <Compile Include="..\Common\Commands\ProcessStatus.cs" Link="ProcessStatus.cs" />
</ItemGroup>
<ItemGroup>
using System.CommandLine.Invocation;
using System.IO;
using System.Threading.Tasks;
+using Microsoft.Diagnostics.Tools.RuntimeClient;
+using Microsoft.Internal.Common.Commands;
namespace Microsoft.Diagnostics.Tools.Dump
{
var parser = new CommandLineBuilder()
.AddCommand(CollectCommand())
.AddCommand(AnalyzeCommand())
+ .AddCommand(ProcessStatusCommand())
.UseDefaults()
.Build();
new[] { "-c", "--command" },
"Run the command on start.",
new Argument<string[]>() { Name = "command", Arity = ArgumentArity.ZeroOrMore });
+
+ private static Command ProcessStatusCommand() =>
+ new Command(
+ "ps",
+ "Display a list of dotnet processes to create dump from",
+ new Option[] { },
+ handler: CommandHandler.Create<IConsole>(ProcessStatusCommandHandler.PrintProcessStatus));
}
}
<PackageReference Include="Microsoft.Diagnostics.Runtime" Version="$(MicrosoftDiagnosticsRuntimeVersion)" />
<PackageReference Include="Microsoft.SymbolStore" Version="$(MicrosoftSymbolStoreVersion)" />
</ItemGroup>
+
+ <ItemGroup>
+ <Compile Include="..\Common\Commands\ProcessStatus.cs" Link="ProcessStatus.cs" />
+ </ItemGroup>
<ItemGroup>
<ProjectReference Include="$(MSBuildThisFileDirectory)..\..\Microsoft.Diagnostics.Repl\Microsoft.Diagnostics.Repl.csproj" />
// See the LICENSE file in the project root for more information.
using Microsoft.Diagnostics.Tools.RuntimeClient;
+using Microsoft.Internal.Common.Commands;
using System;
using System.CommandLine;
-using System.Diagnostics;
-using System.Linq;
using System.Threading.Tasks;
namespace Microsoft.Diagnostics.Tools.Trace
{
public static async Task<int> GetActivePorts(IConsole console)
{
- try
- {
- var processes = EventPipeClient.ListAvailablePorts()
- .Select(GetProcessById)
- .Where(process => process != null)
- .OrderBy(process => process.ProcessName)
- .ThenBy(process => process.Id);
-
- foreach (var process in processes)
- {
- try
- {
- Console.Out.WriteLine($"{process.Id, 10} {process.ProcessName, -10} {process.MainModule.FileName}");
- }
- catch (Exception)
- {
- Console.Out.WriteLine($"{process.Id, 10} {process.ProcessName, -10} [Elevated process - cannot determine path]");
- }
- }
-
- await Task.FromResult(0);
- return 0;
- }
- catch (Exception ex)
- {
- Console.Error.WriteLine($"[ERROR] {ex.ToString()}");
- return 1;
- }
- }
-
- private static Process GetProcessById(int processId)
- {
- try
- {
- return Process.GetProcessById(processId);
- }
- catch (ArgumentException)
- {
- return null;
- }
+ ProcessStatusCommandHandler.PrintProcessStatus(console);
+ await Task.FromResult(0);
+ return 0;
}
public static Command ListProcessesCommand() =>
new Command(
- name: "list-processes",
+ name: "ps",
description: "Lists dotnet processes that can be attached to.",
handler: System.CommandLine.Invocation.CommandHandler.Create<IConsole>(GetActivePorts),
isHidden: false);
<ProjectReference Include="$(MSBuildThisFileDirectory)..\..\Microsoft.Diagnostics.Tools.RuntimeClient\Microsoft.Diagnostics.Tools.RuntimeClient.csproj" />
</ItemGroup>
+ <ItemGroup>
+ <Compile Include="..\Common\Commands\ProcessStatus.cs" Link="ProcessStatus.cs" />
+ </ItemGroup>
+
<ItemGroup>
<InternalsVisibleTo Include="DotnetTrace.UnitTests" />
</ItemGroup>