Skip to content

Commit

Permalink
Address PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
stephentoub committed Mar 31, 2022
1 parent 519e4fb commit f0e9a7d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 26 deletions.
19 changes: 13 additions & 6 deletions src/Microsoft.Diagnostics.ExtensionCommands/DumpAsyncCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@ namespace Microsoft.Diagnostics.ExtensionCommands
[Command(Name = CommandName, Help = "Displays information about async \"stacks\" on the garbage-collected heap.")]
public sealed class DumpAsyncCommand : ExtensionCommandBase
{
/// <summary>Indent width.</summary>
private const int TabWidth = 2;
/// <summary>The name of the command.</summary>
private const string CommandName = "dumpasync";

/// <summary>Indent width.</summary>
private const int TabWidth = 2;
/// <summary>The command invocation syntax when used in Debugger Markup Language (DML) commands.</summary>
private const string DmlCommandInvoke = $"!ext {CommandName}";
private const string DmlCommandInvoke = $"!{CommandName}";

/// <summary>The help text to render when asked for help.</summary>
private static readonly string s_detailedHelpText =
"Usage: dumpasync [--stats] [--coalesce] [--address <object address>] [--methodtable <mt address>] [--type <partial type name>] [--tasks] [--completed] [--fields]" + Environment.NewLine +
$"Usage: {CommandName} [--stats] [--coalesce] [--address <object address>] [--methodtable <mt address>] [--type <partial type name>] [--tasks] [--completed] [--fields]" + Environment.NewLine +
Environment.NewLine +
"Displays information about async \"stacks\" on the garbage-collected heap. Stacks" + Environment.NewLine +
"are synthesized by finding all task objects (including async state machine box" + Environment.NewLine +
Expand All @@ -39,7 +40,13 @@ public sealed class DumpAsyncCommand : ExtensionCommandBase
" --type Only show stacks that include objects whose type includes the specified name in its name." + Environment.NewLine +
" --tasks Include stacks that contain only non-state machine task objects." + Environment.NewLine +
" --completed Include completed tasks in stacks." + Environment.NewLine +
" --fields Show fields for each async stack frame.";
" --fields Show fields for each async stack frame." + Environment.NewLine +
Environment.NewLine +
"Examples:" + Environment.NewLine +
$"Summarize all async frames associated with a specific method table address: !{CommandName} --stats --methodtable 0x00007ffbcfbe0970" + Environment.NewLine +
$"Show all stacks coalesced by common frames: !{CommandName} --coalesce" + Environment.NewLine +
$"Show each stack that includes \"ReadAsync\": !{CommandName} --type ReadAsync" + Environment.NewLine +
$"Show each stack that includes an object at a specific address, and include fields: !{CommandName} --address 0x000001264adce778 --fields";

/// <summary>Gets the runtime for the process. Set by the command framework.</summary>
public ClrRuntime? Runtime { get; set; }
Expand Down Expand Up @@ -529,9 +536,9 @@ Dictionary<ClrObject, AsyncObject> CollectObjects()
{
Console.CancellationToken.ThrowIfCancellationRequested();

// Skip invalid objects.
if (!obj.IsValid || obj.Type is null)
{
WriteLineError($"(Skipping invalid object {obj})");
continue;
}

Expand Down
16 changes: 2 additions & 14 deletions src/SOS/SOS.Extensions/ConsoleServiceFromDebuggerServices.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
using Microsoft.Diagnostics.DebugServices;
using Microsoft.Diagnostics.Runtime.Interop;
using System;
using System.Threading;

namespace SOS.Extensions
{
internal class ConsoleServiceFromDebuggerServices : IConsoleService
{
private readonly DebuggerServices _debuggerServices;
private int _supportsDml = -1;
private bool? _supportsDml;

public ConsoleServiceFromDebuggerServices(DebuggerServices debuggerServices)
{
Expand All @@ -25,18 +24,7 @@ public ConsoleServiceFromDebuggerServices(DebuggerServices debuggerServices)

public void WriteDml(string text) => _debuggerServices.OutputDmlString(DEBUG_OUTPUT.NORMAL, text);

public bool SupportsDml
{
get
{
int supportsDml = _supportsDml;
if (supportsDml < 0)
{
_supportsDml = supportsDml = _debuggerServices.SupportsDml ? 1 : 0;
}
return supportsDml != 0;
}
}
public bool SupportsDml => _supportsDml ??= _debuggerServices.SupportsDml;

public CancellationToken CancellationToken { get; set; }

Expand Down
13 changes: 7 additions & 6 deletions src/SOS/SOS.UnitTests/Scripts/WebApp.script
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,10 @@ VERIFY:\s+Hosted Runtime:\s+no\s+
VERIFY:\s+ID\s+OSID\s+ThreadOBJ\s+State.*\s+
VERIFY:\s+<DECVAL>\s+<DECVAL>\s+<HEXVAL>\s+<HEXVAL>.*\s+

SOSCOMMAND:DumpHeap -stat
VERIFY:\s*Statistics:\s+
VERIFY:\s+MT\s+Count\s+TotalSize\s+Class Name\s+
VERIFY:\s*<HEXVAL>\s+<DECVAL>\s+<DECVAL>\s+.*
VERIFY:\s*Total\s+<DECVAL>\s+objects\s+
!VERIFY:.*UNKNOWN.*
SOSCOMMAND:DumpAsync --stats
VERIFY:\s*MT\s+Count\s+Type\s*
VERIFY:\s*<HEXVAL>\s+<DECVAL>\s+.*

SOSCOMMAND:DumpAsync
VERIFY:\s*Stack 1\s*
VERIFY:\s*<HEXVAL>\s+<HEXVAL>\s+.*

0 comments on commit f0e9a7d

Please sign in to comment.