// --------------------------------------------------------------------
using System;
-namespace Microsoft.Diagnostic.Repl
+namespace Microsoft.Diagnostics.Repl
{
/// <summary>
/// Base command option attribute.
using System.CommandLine.Invocation;
using System.Threading.Tasks;
-namespace Microsoft.Diagnostic.Repl
+namespace Microsoft.Diagnostics.Repl
{
/// <summary>
/// The common command context
using System.Reflection;
using System.Threading.Tasks;
-namespace Microsoft.Diagnostic.Repl
+namespace Microsoft.Diagnostics.Repl
{
public class CommandProcessor
{
using System;
using System.Text;
-namespace Microsoft.Diagnostic.Repl
+namespace Microsoft.Diagnostics.Repl
{
public sealed class CharToLineConverter
{
using System.Threading;
using System.Threading.Tasks;
-namespace Microsoft.Diagnostic.Repl
+namespace Microsoft.Diagnostics.Repl
{
public sealed class ConsoleProvider : IConsole
{
//
// --------------------------------------------------------------------
-namespace Microsoft.Diagnostic.Repl
+namespace Microsoft.Diagnostics.Repl
{
/// <summary>
/// The type of output.
namespace Microsoft.Diagnostics.Tools.RuntimeClient
{
- public static class DiagnosticHelpers
+ public static class DiagnosticsHelpers
{
/// <summary>
/// Controls the contents of the dump
/// <param name="dumpName">Path and file name of core dump</param>
/// <param name="dumpType">Type of dump</param>
/// <param name="diagnostics">If true, log to console the dump generation diagnostics</param>
- /// <returns>DiagnosticServerErrorCode</returns>
+ /// <returns>DiagnosticsServerErrorCode</returns>
public static int GenerateCoreDump(int processId, string dumpName, DumpType dumpType, bool diagnostics)
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
var payload = SerializeCoreDump(dumpName, dumpType, diagnostics);
- var message = new IpcMessage(DiagnosticServerCommandSet.Dump, (byte)DumpCommandId.GenerateCoreDump, payload);
+ var message = new IpcMessage(DiagnosticsServerCommandSet.Dump, (byte)DumpCommandId.GenerateCoreDump, payload);
var response = IpcClient.SendMessage(processId, message);
var hr = 0;
- switch ((DiagnosticServerCommandId)response.Header.CommandId)
+ switch ((DiagnosticsServerCommandId)response.Header.CommandId)
{
- case DiagnosticServerCommandId.Error:
- case DiagnosticServerCommandId.OK:
+ case DiagnosticsServerCommandId.Error:
+ case DiagnosticsServerCommandId.OK:
hr = BitConverter.ToInt32(response.Payload);
break;
default:
}
var header = new MessageHeader {
- RequestType = DiagnosticMessageType.AttachProfiler,
+ RequestType = DiagnosticsMessageType.AttachProfiler,
Pid = (uint)Process.GetCurrentProcess().Id,
};
byte[] serializedConfiguration = SerializeProfilerAttach(attachTimeout, profilerGuid, profilerPath, additionalData);
- var message = new IpcMessage(DiagnosticServerCommandSet.Profiler, (byte)ProfilerCommandId.AttachProfiler, serializedConfiguration);
+ var message = new IpcMessage(DiagnosticsServerCommandSet.Profiler, (byte)ProfilerCommandId.AttachProfiler, serializedConfiguration);
var response = IpcClient.SendMessage(processId, message);
var hr = 0;
- switch ((DiagnosticServerCommandId)response.Header.CommandId)
+ switch ((DiagnosticsServerCommandId)response.Header.CommandId)
{
- case DiagnosticServerCommandId.Error:
- case DiagnosticServerCommandId.OK:
+ case DiagnosticsServerCommandId.Error:
+ case DiagnosticsServerCommandId.OK:
hr = BitConverter.ToInt32(response.Payload);
break;
default:
{
public class IpcClient
{
- private static string DiagnosticPortPattern { get; } = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? @"^dotnet-diagnostic-(\d+)$" : @"^dotnet-diagnostic-(\d+)-(\d+)-socket$";
+ private static string DiagnosticsPortPattern { get; } = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? @"^dotnet-diagnostic-(\d+)$" : @"^dotnet-diagnostic-(\d+)-(\d+)-socket$";
private static string IpcRootPath { get; } = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? @"\\.\pipe\" : Path.GetTempPath();
}
/// <summary>
- /// Sends a single DiagnosticIpc Message to the dotnet process with PID processId.
+ /// Sends a single DiagnosticsIpc Message to the dotnet process with PID processId.
/// </summary>
/// <param name="processId">The PID of the dotnet process</param>
/// <param name="message">The DiagnosticsIpc Message to be sent</param>
}
/// <summary>
- /// Sends a single DiagnosticIpc Message to the dotnet process with PID processId
+ /// Sends a single DiagnosticsIpc Message to the dotnet process with PID processId
/// and returns the Stream for reuse in Optional Continuations.
/// </summary>
/// <param name="processId">The PID of the dotnet process</param>
namespace Microsoft.Diagnostics.Tools.RuntimeClient.DiagnosticsIpc
{
- public enum DiagnosticServerCommandSet : byte
+ public enum DiagnosticsServerCommandSet : byte
{
Dump = 0x01,
EventPipe = 0x02,
Server = 0xFF,
}
- public enum DiagnosticServerCommandId : byte
+ public enum DiagnosticsServerCommandId : byte
{
OK = 0x00,
Error = 0xFF,
{
IpcHeader() { }
- public IpcHeader(DiagnosticServerCommandSet commandSet, byte commandId)
+ public IpcHeader(DiagnosticsServerCommandSet commandSet, byte commandId)
{
CommandSet = (byte)commandSet;
CommandId = commandId;
Header = header;
}
- internal IpcMessage(DiagnosticServerCommandSet commandSet, byte commandId, byte[] payload = null)
+ internal IpcMessage(DiagnosticsServerCommandSet commandSet, byte commandId, byte[] payload = null)
{
Header = new IpcHeader(commandSet, commandId);
Payload = payload;
/// <summary>
/// Different diagnostic message types that are handled by the runtime.
/// </summary>
- public enum DiagnosticMessageType : uint
+ public enum DiagnosticsMessageType : uint
{
/// <summary>
/// Initiates core dump generation
{
public static class EventPipeClient
{
- private static string DiagnosticPortPattern { get; } = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? @"^dotnet-diagnostic-(\d+)$" : @"^dotnet-diagnostic-(\d+)-(\d+)-socket$";
+ private static string DiagnosticsPortPattern { get; } = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? @"^dotnet-diagnostic-(\d+)$" : @"^dotnet-diagnostic-(\d+)-(\d+)-socket$";
private static string IpcRootPath { get; } = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? @"\\.\pipe\" : Path.GetTempPath();
{
return Directory.GetFiles(IpcRootPath)
.Select(namedPipe => (new FileInfo(namedPipe)).Name)
- .Where(input => Regex.IsMatch(input, DiagnosticPortPattern))
- .Select(input => int.Parse(Regex.Match(input, DiagnosticPortPattern).Groups[1].Value, NumberStyles.Integer));
+ .Where(input => Regex.IsMatch(input, DiagnosticsPortPattern))
+ .Select(input => int.Parse(Regex.Match(input, DiagnosticsPortPattern).Groups[1].Value, NumberStyles.Integer));
}
/// <summary>
public static Stream CollectTracing(int processId, SessionConfiguration configuration, out ulong sessionId)
{
sessionId = 0;
- var message = new IpcMessage(DiagnosticServerCommandSet.EventPipe, (byte)EventPipeCommandId.CollectTracing, configuration.Serialize());
+ var message = new IpcMessage(DiagnosticsServerCommandSet.EventPipe, (byte)EventPipeCommandId.CollectTracing, configuration.Serialize());
var stream = IpcClient.SendMessage(processId, message, out var response);
- switch ((DiagnosticServerCommandId)response.Header.CommandId)
+ switch ((DiagnosticsServerCommandId)response.Header.CommandId)
{
- case DiagnosticServerCommandId.OK:
+ case DiagnosticsServerCommandId.OK:
sessionId = BitConverter.ToUInt64(response.Payload);
break;
- case DiagnosticServerCommandId.Error:
+ case DiagnosticsServerCommandId.Error:
// bad...
var hr = BitConverter.ToInt32(response.Payload);
throw new Exception($"Session start FAILED 0x{hr:X8}");
byte[] payload = BitConverter.GetBytes(sessionId);
- var response = IpcClient.SendMessage(processId, new IpcMessage(DiagnosticServerCommandSet.EventPipe, (byte)EventPipeCommandId.StopTracing, payload));
+ var response = IpcClient.SendMessage(processId, new IpcMessage(DiagnosticsServerCommandSet.EventPipe, (byte)EventPipeCommandId.StopTracing, payload));
- switch ((DiagnosticServerCommandId)response.Header.CommandId)
+ switch ((DiagnosticsServerCommandId)response.Header.CommandId)
{
- case DiagnosticServerCommandId.OK:
+ case DiagnosticsServerCommandId.OK:
return BitConverter.ToUInt64(response.Payload);
- case DiagnosticServerCommandId.Error:
+ case DiagnosticsServerCommandId.Error:
return 0;
default:
return 0;
/// <summary>
/// Request type.
/// </summary>
- public DiagnosticMessageType RequestType;
+ public DiagnosticsMessageType RequestType;
/// <summary>
/// Remote process Id.
using System.Runtime.InteropServices;
using System.Threading;
-namespace Microsoft.Diagnostic.Tools.Dump
+namespace Microsoft.Diagnostics.Tools.Dump
{
/// <summary>
/// The the common context for analyze commands
-using Microsoft.Diagnostic.Repl;
+using Microsoft.Diagnostics.Repl;
using Microsoft.Diagnostics.Runtime;
using SOS;
using System;
using System.Threading;
using System.Threading.Tasks;
-namespace Microsoft.Diagnostic.Tools.Dump
+namespace Microsoft.Diagnostics.Tools.Dump
{
public class Analyzer
{
-using Microsoft.Diagnostic.Repl;
+using Microsoft.Diagnostics.Repl;
using Microsoft.Diagnostics.Runtime;
using System.CommandLine;
using System.Threading.Tasks;
-namespace Microsoft.Diagnostic.Tools.Dump
+namespace Microsoft.Diagnostics.Tools.Dump
{
[Command(Name = "clrmodules", Help = "Lists the managed modules in the process.")]
public class ClrModulesCommand : CommandBase
-using Microsoft.Diagnostic.Repl;
+using Microsoft.Diagnostics.Repl;
using System.CommandLine;
using System.Threading.Tasks;
-namespace Microsoft.Diagnostic.Tools.Dump
+namespace Microsoft.Diagnostics.Tools.Dump
{
[Command(Name = "exit", Help = "Exit interactive mode.")]
[CommandAlias(Name = "quit")]
-using Microsoft.Diagnostic.Repl;
+using Microsoft.Diagnostics.Repl;
using System.CommandLine;
-namespace Microsoft.Diagnostic.Tools.Dump
+namespace Microsoft.Diagnostics.Tools.Dump
{
[Command(Name = "help", Help = "Display help for a command.")]
public class HelpCommand : CommandBase
-using Microsoft.Diagnostic.Repl;
+using Microsoft.Diagnostics.Repl;
using Microsoft.Diagnostics.Runtime;
using System.CommandLine;
using System.Linq;
using System.Threading.Tasks;
-namespace Microsoft.Diagnostic.Tools.Dump
+namespace Microsoft.Diagnostics.Tools.Dump
{
[Command(Name = "modules", Help = "Displays the native modules in the process.")]
[CommandAlias(Name = "lm")]
-using Microsoft.Diagnostic.Repl;
+using Microsoft.Diagnostics.Repl;
using System;
using System.CommandLine;
using System.IO;
using System.Linq;
-namespace Microsoft.Diagnostic.Tools.Dump
+namespace Microsoft.Diagnostics.Tools.Dump
{
[Command(Name = "clrstack", AliasExpansion = "ClrStack", Help = "Provides a stack trace of managed code only.")]
[Command(Name = "clrthreads", AliasExpansion = "Threads", Help = "List the managed threads running.")]
-using Microsoft.Diagnostic.Repl;
+using Microsoft.Diagnostics.Repl;
using System;
using System.Collections.Generic;
using System.CommandLine;
using System.Linq;
-namespace Microsoft.Diagnostic.Tools.Dump
+namespace Microsoft.Diagnostics.Tools.Dump
{
[Command(Name = "setthread", Help = "Sets or displays the current thread for the SOS commands.")]
[CommandAlias(Name = "threads")]
using System.Threading.Tasks;
using System.IO;
-namespace Microsoft.Diagnostic.Tools.Dump
+namespace Microsoft.Diagnostics.Tools.Dump
{
public partial class Dumper
{
using System.Threading.Tasks;
using Microsoft.Win32.SafeHandles;
-namespace Microsoft.Diagnostic.Tools.Dump
+namespace Microsoft.Diagnostics.Tools.Dump
{
public partial class Dumper
{
using System.Threading;
using System.Threading.Tasks;
-namespace Microsoft.Diagnostic.Tools.Dump
+namespace Microsoft.Diagnostics.Tools.Dump
{
public partial class Dumper
{
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
- DiagnosticHelpers.DumpType dumpType = type == DumpTypeOption.Heap ? DiagnosticHelpers.DumpType.WithHeap : DiagnosticHelpers.DumpType.Normal;
+ DiagnosticsHelpers.DumpType dumpType = type == DumpTypeOption.Heap ? DiagnosticsHelpers.DumpType.WithHeap : DiagnosticsHelpers.DumpType.Normal;
// Send the command to the runtime to initiate the core dump
- var hr = DiagnosticHelpers.GenerateCoreDump(processId, output, dumpType, diagnostics: false);
+ var hr = DiagnosticsHelpers.GenerateCoreDump(processId, output, dumpType, diagnostics: false);
if (hr != 0)
{
throw new InvalidOperationException($"Core dump generation FAILED 0x{hr:X8}");
using System.IO;
using System.Threading.Tasks;
-namespace Microsoft.Diagnostic.Tools.Dump
+namespace Microsoft.Diagnostics.Tools.Dump
{
class Program
{
static int Main(string[] args)
{
SendSmallerHeaderCommand();
- SendInvalidDiagnosticMessageTypeCommand();
+ SendInvalidDiagnosticsMessageTypeCommand();
SendInvalidInputData();
TestCollectEventPipeTracing();
return 100;
{
using (var bw = new BinaryWriter(stream))
{
- bw.Write((uint)DiagnosticMessageType.StartEventPipeTracing);
+ bw.Write((uint)DiagnosticsMessageType.StartEventPipeTracing);
bw.Flush();
stream.Position = 0;
}
}
- private static void SendInvalidDiagnosticMessageTypeCommand()
+ private static void SendInvalidDiagnosticsMessageTypeCommand()
{
Console.WriteLine("Send a wrong message type as the diagnostic header header.");
ulong sessionId = 0;
try
{
var header = new MessageHeader {
- RequestType = DiagnosticMessageType.CollectEventPipeTracing,
+ RequestType = DiagnosticsMessageType.CollectEventPipeTracing,
Pid = (uint)Process.GetCurrentProcess().Id,
};