Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Microsoft.Diagnostics.NETCore.Client Implementation #617

Merged
merged 43 commits into from
Dec 6, 2019
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
22030df
First batch of files
sywhang Nov 6, 2019
3fde2a7
Make dotnet-counters use the diagnostics client library
sywhang Nov 6, 2019
d9efaff
Port dotnet-trace
sywhang Nov 7, 2019
13c8306
Port dotnet-dump
sywhang Nov 7, 2019
f8667ff
Implement WriteDump
sywhang Nov 7, 2019
54b78a6
Implement AttachProfiler
sywhang Nov 7, 2019
fa48772
Implement GetPublishedProcesses
sywhang Nov 7, 2019
9c8dc4d
Implement dispose overrides
sywhang Nov 7, 2019
614ba31
Port dotnet-gcdump
sywhang Nov 7, 2019
142e938
Port dotnet-trace tests
sywhang Nov 7, 2019
e22532d
Default keyword is not ulong.max
sywhang Nov 7, 2019
45886f1
Fix argument parser
sywhang Nov 7, 2019
4dec226
Merge remote-tracking branch 'upstream/master' into dev/suwhang/rcl-i…
sywhang Nov 13, 2019
ccd1c17
Add diagnostics client library to diagnostics solution
sywhang Nov 13, 2019
46f0402
Fix few bugs, start throwing relevant exceptions
sywhang Nov 14, 2019
31aaa2a
Add more exception throws
sywhang Nov 14, 2019
3b51ff0
Undo accidental change
sywhang Nov 14, 2019
f087d15
Fix build error, address PR feedback
sywhang Nov 14, 2019
0642cad
remove TODO and add asserts on header parse
sywhang Nov 15, 2019
a0b3c57
Add exception handling for counters
sywhang Nov 15, 2019
1a47b41
Add exception handling for dotnet-trace
sywhang Nov 15, 2019
48333bd
Fix default keyword not being all fs when no keyword specified
sywhang Nov 15, 2019
bec51df
Add test for DiagnosticsClient library
sywhang Nov 15, 2019
5151b30
Remove unused regex
sywhang Nov 15, 2019
d3cf367
Add TestHelpers to DiagnosticsClient test
sywhang Nov 15, 2019
6fc7fb3
Added test runner, GetPublishedProcesses tests
sywhang Nov 18, 2019
488e137
Fix test run on Linux
sywhang Nov 18, 2019
3697a54
Add Tracee
sywhang Nov 18, 2019
272a459
Rename test file
sywhang Nov 18, 2019
81e446d
Dump test added
sywhang Nov 18, 2019
dba6940
Add EventPipeSession tests
sywhang Nov 18, 2019
bba974e
Add some more failure test
sywhang Nov 18, 2019
810e67d
remove useless test
sywhang Nov 18, 2019
21465f5
Add license headers
sywhang Nov 18, 2019
ac5c16d
add diagnostics client library test to project
sywhang Nov 18, 2019
48892d4
Squashing some commits
sywhang Nov 26, 2019
44e1163
Merge with master
sywhang Nov 26, 2019
17eff82
Fix build
sywhang Nov 26, 2019
22613bf
PR feedback
sywhang Dec 4, 2019
233a8b5
more nits
sywhang Dec 4, 2019
adc565c
Merge branch 'master' into dev/suwhang/rcl-implementation
sywhang Dec 4, 2019
968574d
Make public classes sealed
sywhang Dec 5, 2019
c61bcf9
fix build
sywhang Dec 5, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 129 additions & 0 deletions diagnostics.sln
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dotnet-gcdump", "src\Tools\
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotnetCounters.UnitTests", "src\tests\dotnet-counters\DotnetCounters.UnitTests.csproj", "{E5A7DC6C-BF8D-418A-BCBD-094EB748FA82}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Diagnostics.NETCore.Client", "src\Microsoft.Diagnostics.NETCore.Client\Microsoft.Diagnostics.NETCore.Client.csproj", "{D8BE9C81-194E-43E5-82CF-2080892FBDE7}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Diagnostics.NETCore.Client.UnitTests", "src\tests\Microsoft.Diagnostics.NETCore.Client\Microsoft.Diagnostics.NETCore.Client.UnitTests.csproj", "{6F4DD2F8-1C7B-4A87-B7E5-1BEE9F5AC128}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tracee", "src\tests\Tracee\Tracee.csproj", "{C79D6069-2C18-48CB-846E-71F7168C2F7D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EventPipe.UnitTests", "src\tests\eventpipe\EventPipe.UnitTests.csproj", "{CED9ABBA-861E-4C0A-9359-22351208EF27}"
EndProject
Global
Expand Down Expand Up @@ -890,6 +896,126 @@ Global
{E5A7DC6C-BF8D-418A-BCBD-094EB748FA82}.RelWithDebInfo|x64.Build.0 = Release|Any CPU
{E5A7DC6C-BF8D-418A-BCBD-094EB748FA82}.RelWithDebInfo|x86.ActiveCfg = Release|Any CPU
{E5A7DC6C-BF8D-418A-BCBD-094EB748FA82}.RelWithDebInfo|x86.Build.0 = Release|Any CPU
{D8BE9C81-194E-43E5-82CF-2080892FBDE7}.Checked|Any CPU.ActiveCfg = Debug|Any CPU
{D8BE9C81-194E-43E5-82CF-2080892FBDE7}.Checked|Any CPU.Build.0 = Debug|Any CPU
{D8BE9C81-194E-43E5-82CF-2080892FBDE7}.Checked|ARM.ActiveCfg = Debug|Any CPU
{D8BE9C81-194E-43E5-82CF-2080892FBDE7}.Checked|ARM.Build.0 = Debug|Any CPU
{D8BE9C81-194E-43E5-82CF-2080892FBDE7}.Checked|ARM64.ActiveCfg = Debug|Any CPU
{D8BE9C81-194E-43E5-82CF-2080892FBDE7}.Checked|ARM64.Build.0 = Debug|Any CPU
{D8BE9C81-194E-43E5-82CF-2080892FBDE7}.Checked|x64.ActiveCfg = Debug|Any CPU
{D8BE9C81-194E-43E5-82CF-2080892FBDE7}.Checked|x64.Build.0 = Debug|Any CPU
{D8BE9C81-194E-43E5-82CF-2080892FBDE7}.Checked|x86.ActiveCfg = Debug|Any CPU
{D8BE9C81-194E-43E5-82CF-2080892FBDE7}.Checked|x86.Build.0 = Debug|Any CPU
{D8BE9C81-194E-43E5-82CF-2080892FBDE7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D8BE9C81-194E-43E5-82CF-2080892FBDE7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D8BE9C81-194E-43E5-82CF-2080892FBDE7}.Debug|ARM.ActiveCfg = Debug|Any CPU
{D8BE9C81-194E-43E5-82CF-2080892FBDE7}.Debug|ARM.Build.0 = Debug|Any CPU
{D8BE9C81-194E-43E5-82CF-2080892FBDE7}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{D8BE9C81-194E-43E5-82CF-2080892FBDE7}.Debug|ARM64.Build.0 = Debug|Any CPU
{D8BE9C81-194E-43E5-82CF-2080892FBDE7}.Debug|x64.ActiveCfg = Debug|Any CPU
{D8BE9C81-194E-43E5-82CF-2080892FBDE7}.Debug|x64.Build.0 = Debug|Any CPU
{D8BE9C81-194E-43E5-82CF-2080892FBDE7}.Debug|x86.ActiveCfg = Debug|Any CPU
{D8BE9C81-194E-43E5-82CF-2080892FBDE7}.Debug|x86.Build.0 = Debug|Any CPU
{D8BE9C81-194E-43E5-82CF-2080892FBDE7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D8BE9C81-194E-43E5-82CF-2080892FBDE7}.Release|Any CPU.Build.0 = Release|Any CPU
{D8BE9C81-194E-43E5-82CF-2080892FBDE7}.Release|ARM.ActiveCfg = Release|Any CPU
{D8BE9C81-194E-43E5-82CF-2080892FBDE7}.Release|ARM.Build.0 = Release|Any CPU
{D8BE9C81-194E-43E5-82CF-2080892FBDE7}.Release|ARM64.ActiveCfg = Release|Any CPU
{D8BE9C81-194E-43E5-82CF-2080892FBDE7}.Release|ARM64.Build.0 = Release|Any CPU
{D8BE9C81-194E-43E5-82CF-2080892FBDE7}.Release|x64.ActiveCfg = Release|Any CPU
{D8BE9C81-194E-43E5-82CF-2080892FBDE7}.Release|x64.Build.0 = Release|Any CPU
{D8BE9C81-194E-43E5-82CF-2080892FBDE7}.Release|x86.ActiveCfg = Release|Any CPU
{D8BE9C81-194E-43E5-82CF-2080892FBDE7}.Release|x86.Build.0 = Release|Any CPU
{D8BE9C81-194E-43E5-82CF-2080892FBDE7}.RelWithDebInfo|Any CPU.ActiveCfg = Release|Any CPU
{D8BE9C81-194E-43E5-82CF-2080892FBDE7}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU
{D8BE9C81-194E-43E5-82CF-2080892FBDE7}.RelWithDebInfo|ARM.ActiveCfg = Release|Any CPU
{D8BE9C81-194E-43E5-82CF-2080892FBDE7}.RelWithDebInfo|ARM.Build.0 = Release|Any CPU
{D8BE9C81-194E-43E5-82CF-2080892FBDE7}.RelWithDebInfo|ARM64.ActiveCfg = Release|Any CPU
{D8BE9C81-194E-43E5-82CF-2080892FBDE7}.RelWithDebInfo|ARM64.Build.0 = Release|Any CPU
{D8BE9C81-194E-43E5-82CF-2080892FBDE7}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU
{D8BE9C81-194E-43E5-82CF-2080892FBDE7}.RelWithDebInfo|x64.Build.0 = Release|Any CPU
{D8BE9C81-194E-43E5-82CF-2080892FBDE7}.RelWithDebInfo|x86.ActiveCfg = Release|Any CPU
{D8BE9C81-194E-43E5-82CF-2080892FBDE7}.RelWithDebInfo|x86.Build.0 = Release|Any CPU
{6F4DD2F8-1C7B-4A87-B7E5-1BEE9F5AC128}.Checked|Any CPU.ActiveCfg = Debug|Any CPU
{6F4DD2F8-1C7B-4A87-B7E5-1BEE9F5AC128}.Checked|Any CPU.Build.0 = Debug|Any CPU
{6F4DD2F8-1C7B-4A87-B7E5-1BEE9F5AC128}.Checked|ARM.ActiveCfg = Debug|Any CPU
{6F4DD2F8-1C7B-4A87-B7E5-1BEE9F5AC128}.Checked|ARM.Build.0 = Debug|Any CPU
{6F4DD2F8-1C7B-4A87-B7E5-1BEE9F5AC128}.Checked|ARM64.ActiveCfg = Debug|Any CPU
{6F4DD2F8-1C7B-4A87-B7E5-1BEE9F5AC128}.Checked|ARM64.Build.0 = Debug|Any CPU
{6F4DD2F8-1C7B-4A87-B7E5-1BEE9F5AC128}.Checked|x64.ActiveCfg = Debug|Any CPU
{6F4DD2F8-1C7B-4A87-B7E5-1BEE9F5AC128}.Checked|x64.Build.0 = Debug|Any CPU
{6F4DD2F8-1C7B-4A87-B7E5-1BEE9F5AC128}.Checked|x86.ActiveCfg = Debug|Any CPU
{6F4DD2F8-1C7B-4A87-B7E5-1BEE9F5AC128}.Checked|x86.Build.0 = Debug|Any CPU
{6F4DD2F8-1C7B-4A87-B7E5-1BEE9F5AC128}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6F4DD2F8-1C7B-4A87-B7E5-1BEE9F5AC128}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6F4DD2F8-1C7B-4A87-B7E5-1BEE9F5AC128}.Debug|ARM.ActiveCfg = Debug|Any CPU
{6F4DD2F8-1C7B-4A87-B7E5-1BEE9F5AC128}.Debug|ARM.Build.0 = Debug|Any CPU
{6F4DD2F8-1C7B-4A87-B7E5-1BEE9F5AC128}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{6F4DD2F8-1C7B-4A87-B7E5-1BEE9F5AC128}.Debug|ARM64.Build.0 = Debug|Any CPU
{6F4DD2F8-1C7B-4A87-B7E5-1BEE9F5AC128}.Debug|x64.ActiveCfg = Debug|Any CPU
{6F4DD2F8-1C7B-4A87-B7E5-1BEE9F5AC128}.Debug|x64.Build.0 = Debug|Any CPU
{6F4DD2F8-1C7B-4A87-B7E5-1BEE9F5AC128}.Debug|x86.ActiveCfg = Debug|Any CPU
{6F4DD2F8-1C7B-4A87-B7E5-1BEE9F5AC128}.Debug|x86.Build.0 = Debug|Any CPU
{6F4DD2F8-1C7B-4A87-B7E5-1BEE9F5AC128}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6F4DD2F8-1C7B-4A87-B7E5-1BEE9F5AC128}.Release|Any CPU.Build.0 = Release|Any CPU
{6F4DD2F8-1C7B-4A87-B7E5-1BEE9F5AC128}.Release|ARM.ActiveCfg = Release|Any CPU
{6F4DD2F8-1C7B-4A87-B7E5-1BEE9F5AC128}.Release|ARM.Build.0 = Release|Any CPU
{6F4DD2F8-1C7B-4A87-B7E5-1BEE9F5AC128}.Release|ARM64.ActiveCfg = Release|Any CPU
{6F4DD2F8-1C7B-4A87-B7E5-1BEE9F5AC128}.Release|ARM64.Build.0 = Release|Any CPU
{6F4DD2F8-1C7B-4A87-B7E5-1BEE9F5AC128}.Release|x64.ActiveCfg = Release|Any CPU
{6F4DD2F8-1C7B-4A87-B7E5-1BEE9F5AC128}.Release|x64.Build.0 = Release|Any CPU
{6F4DD2F8-1C7B-4A87-B7E5-1BEE9F5AC128}.Release|x86.ActiveCfg = Release|Any CPU
{6F4DD2F8-1C7B-4A87-B7E5-1BEE9F5AC128}.Release|x86.Build.0 = Release|Any CPU
{6F4DD2F8-1C7B-4A87-B7E5-1BEE9F5AC128}.RelWithDebInfo|Any CPU.ActiveCfg = Release|Any CPU
{6F4DD2F8-1C7B-4A87-B7E5-1BEE9F5AC128}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU
{6F4DD2F8-1C7B-4A87-B7E5-1BEE9F5AC128}.RelWithDebInfo|ARM.ActiveCfg = Release|Any CPU
{6F4DD2F8-1C7B-4A87-B7E5-1BEE9F5AC128}.RelWithDebInfo|ARM.Build.0 = Release|Any CPU
{6F4DD2F8-1C7B-4A87-B7E5-1BEE9F5AC128}.RelWithDebInfo|ARM64.ActiveCfg = Release|Any CPU
{6F4DD2F8-1C7B-4A87-B7E5-1BEE9F5AC128}.RelWithDebInfo|ARM64.Build.0 = Release|Any CPU
{6F4DD2F8-1C7B-4A87-B7E5-1BEE9F5AC128}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU
{6F4DD2F8-1C7B-4A87-B7E5-1BEE9F5AC128}.RelWithDebInfo|x64.Build.0 = Release|Any CPU
{6F4DD2F8-1C7B-4A87-B7E5-1BEE9F5AC128}.RelWithDebInfo|x86.ActiveCfg = Release|Any CPU
{6F4DD2F8-1C7B-4A87-B7E5-1BEE9F5AC128}.RelWithDebInfo|x86.Build.0 = Release|Any CPU
{C79D6069-2C18-48CB-846E-71F7168C2F7D}.Checked|Any CPU.ActiveCfg = Debug|Any CPU
{C79D6069-2C18-48CB-846E-71F7168C2F7D}.Checked|Any CPU.Build.0 = Debug|Any CPU
{C79D6069-2C18-48CB-846E-71F7168C2F7D}.Checked|ARM.ActiveCfg = Debug|Any CPU
{C79D6069-2C18-48CB-846E-71F7168C2F7D}.Checked|ARM.Build.0 = Debug|Any CPU
{C79D6069-2C18-48CB-846E-71F7168C2F7D}.Checked|ARM64.ActiveCfg = Debug|Any CPU
{C79D6069-2C18-48CB-846E-71F7168C2F7D}.Checked|ARM64.Build.0 = Debug|Any CPU
{C79D6069-2C18-48CB-846E-71F7168C2F7D}.Checked|x64.ActiveCfg = Debug|Any CPU
{C79D6069-2C18-48CB-846E-71F7168C2F7D}.Checked|x64.Build.0 = Debug|Any CPU
{C79D6069-2C18-48CB-846E-71F7168C2F7D}.Checked|x86.ActiveCfg = Debug|Any CPU
{C79D6069-2C18-48CB-846E-71F7168C2F7D}.Checked|x86.Build.0 = Debug|Any CPU
{C79D6069-2C18-48CB-846E-71F7168C2F7D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C79D6069-2C18-48CB-846E-71F7168C2F7D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C79D6069-2C18-48CB-846E-71F7168C2F7D}.Debug|ARM.ActiveCfg = Debug|Any CPU
{C79D6069-2C18-48CB-846E-71F7168C2F7D}.Debug|ARM.Build.0 = Debug|Any CPU
{C79D6069-2C18-48CB-846E-71F7168C2F7D}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{C79D6069-2C18-48CB-846E-71F7168C2F7D}.Debug|ARM64.Build.0 = Debug|Any CPU
{C79D6069-2C18-48CB-846E-71F7168C2F7D}.Debug|x64.ActiveCfg = Debug|Any CPU
{C79D6069-2C18-48CB-846E-71F7168C2F7D}.Debug|x64.Build.0 = Debug|Any CPU
{C79D6069-2C18-48CB-846E-71F7168C2F7D}.Debug|x86.ActiveCfg = Debug|Any CPU
{C79D6069-2C18-48CB-846E-71F7168C2F7D}.Debug|x86.Build.0 = Debug|Any CPU
{C79D6069-2C18-48CB-846E-71F7168C2F7D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C79D6069-2C18-48CB-846E-71F7168C2F7D}.Release|Any CPU.Build.0 = Release|Any CPU
{C79D6069-2C18-48CB-846E-71F7168C2F7D}.Release|ARM.ActiveCfg = Release|Any CPU
{C79D6069-2C18-48CB-846E-71F7168C2F7D}.Release|ARM.Build.0 = Release|Any CPU
{C79D6069-2C18-48CB-846E-71F7168C2F7D}.Release|ARM64.ActiveCfg = Release|Any CPU
{C79D6069-2C18-48CB-846E-71F7168C2F7D}.Release|ARM64.Build.0 = Release|Any CPU
{C79D6069-2C18-48CB-846E-71F7168C2F7D}.Release|x64.ActiveCfg = Release|Any CPU
{C79D6069-2C18-48CB-846E-71F7168C2F7D}.Release|x64.Build.0 = Release|Any CPU
{C79D6069-2C18-48CB-846E-71F7168C2F7D}.Release|x86.ActiveCfg = Release|Any CPU
{C79D6069-2C18-48CB-846E-71F7168C2F7D}.Release|x86.Build.0 = Release|Any CPU
{C79D6069-2C18-48CB-846E-71F7168C2F7D}.RelWithDebInfo|Any CPU.ActiveCfg = Debug|Any CPU
{C79D6069-2C18-48CB-846E-71F7168C2F7D}.RelWithDebInfo|Any CPU.Build.0 = Debug|Any CPU
{C79D6069-2C18-48CB-846E-71F7168C2F7D}.RelWithDebInfo|ARM.ActiveCfg = Debug|Any CPU
{C79D6069-2C18-48CB-846E-71F7168C2F7D}.RelWithDebInfo|ARM.Build.0 = Debug|Any CPU
{C79D6069-2C18-48CB-846E-71F7168C2F7D}.RelWithDebInfo|ARM64.ActiveCfg = Debug|Any CPU
{C79D6069-2C18-48CB-846E-71F7168C2F7D}.RelWithDebInfo|ARM64.Build.0 = Debug|Any CPU
{C79D6069-2C18-48CB-846E-71F7168C2F7D}.RelWithDebInfo|x64.ActiveCfg = Debug|Any CPU
{C79D6069-2C18-48CB-846E-71F7168C2F7D}.RelWithDebInfo|x64.Build.0 = Debug|Any CPU
{C79D6069-2C18-48CB-846E-71F7168C2F7D}.RelWithDebInfo|x86.ActiveCfg = Debug|Any CPU
{C79D6069-2C18-48CB-846E-71F7168C2F7D}.RelWithDebInfo|x86.Build.0 = Debug|Any CPU
{CED9ABBA-861E-4C0A-9359-22351208EF27}.Checked|Any CPU.ActiveCfg = Debug|Any CPU
{CED9ABBA-861E-4C0A-9359-22351208EF27}.Checked|Any CPU.Build.0 = Debug|Any CPU
{CED9ABBA-861E-4C0A-9359-22351208EF27}.Checked|ARM.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -960,6 +1086,9 @@ Global
{AEDCCF5B-5AD0-4D64-BF73-5CF468E07D22} = {03479E19-3F18-49A6-910A-F5041E27E7C0}
{936678B3-3392-4F4F-943C-B6A4BFCBAADC} = {B62728C8-1267-4043-B46F-5537BBAEC692}
{E5A7DC6C-BF8D-418A-BCBD-094EB748FA82} = {03479E19-3F18-49A6-910A-F5041E27E7C0}
{D8BE9C81-194E-43E5-82CF-2080892FBDE7} = {19FAB78C-3351-4911-8F0C-8C6056401740}
{6F4DD2F8-1C7B-4A87-B7E5-1BEE9F5AC128} = {03479E19-3F18-49A6-910A-F5041E27E7C0}
{C79D6069-2C18-48CB-846E-71F7168C2F7D} = {03479E19-3F18-49A6-910A-F5041E27E7C0}
{CED9ABBA-861E-4C0A-9359-22351208EF27} = {03479E19-3F18-49A6-910A-F5041E27E7C0}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
// 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.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Globalization;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;

namespace Microsoft.Diagnostics.NETCore.Client
{
/// <summary>
/// This is a top-level class that contains methods to send various diagnostics command to the runtime.
/// </summary>
public class DiagnosticsClient
Copy link
Member

@jorive jorive Nov 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I do not see a virtual method in this class (no plan on allowing inheritance), therefore I would make it sealed.

{
private int _processId;
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();
sywhang marked this conversation as resolved.
Show resolved Hide resolved

public DiagnosticsClient(int processId)
{
_processId = processId;
}

/// <summary>
/// Start tracing the application and return an EventPipeSession object
/// </summary>
/// <param name="providers">An IEnumerable containing the list of Providers to turn on.</param>
/// <param name="requestRundown">If true, request rundown events from the runtime</param>
/// <param name="circularBufferMB">The size of the runtime's buffer for collecting events in MB</param>
/// <returns>
/// An EventPipeSession object representing the EventPipe session that just started.
/// </returns>
public EventPipeSession StartEventPipeSession(IEnumerable<EventPipeProvider> providers, bool requestRundown=true, int circularBufferMB=256)
{
return new EventPipeSession(_processId, providers, requestRundown, circularBufferMB);
}

/// <summary>
/// Trigger a core dump generation.
/// </summary>
/// <param name="dumpType">Type of the dump to be generated</param>
/// <param name="dumpPath">Full path to the dump to be generated. By default it is /tmp/coredump.{pid}</param>
/// <param name="logDumpGeneration">When set to true, display the dump generation debug log to the console.</param>
public void WriteDump(DumpType dumpType, string dumpPath, bool logDumpGeneration=false)
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
throw new PlatformNotSupportedException($"Unsupported operating system: {RuntimeInformation.OSDescription}");

if (string.IsNullOrEmpty(dumpPath))
throw new ArgumentNullException($"{nameof(dumpPath)} required");

var payload = SerializeCoreDump(dumpPath, dumpType, logDumpGeneration);
var message = new IpcMessage(DiagnosticsServerCommandSet.Dump, (byte)DumpCommandId.GenerateCoreDump, payload);
var response = IpcClient.SendMessage(_processId, message);
var hr = 0;
switch ((DiagnosticsServerCommandId)response.Header.CommandId)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: This switch statement is almost the same as the one below. They could be placed into a function.

{
case DiagnosticsServerCommandId.Error:
hr = BitConverter.ToInt32(response.Payload, 0);
throw new ServerErrorException($"Writing dump failed (HRESULT: 0x{hr:X8})");
case DiagnosticsServerCommandId.OK:
return;
default:
throw new ServerErrorException($"Writing dump failed - server responded with unknown command");
}
}

/// <summary>
/// Attach a profiler.
/// </summary>
/// <param name="attachTimeout">Timeout for attaching the profiler</param>
/// <param name="profilerGuid">Guid for the profiler to be attached</param>
/// <param name="profilerPath">Path to the profiler to be attached</param>
/// <param name="additionalData">Additional data to be passed to the profiler</param>
public void AttachProfiler(TimeSpan attachTimeout, Guid profilerGuid, string profilerPath, byte[] additionalData=null)
{
if (profilerGuid == null || profilerGuid == Guid.Empty)
{
throw new ArgumentException($"{nameof(profilerGuid)} must be a valid Guid");
}

if (String.IsNullOrEmpty(profilerPath))
{
throw new ArgumentException($"{nameof(profilerPath)} must be non-null");
}

var header = new MessageHeader {
sywhang marked this conversation as resolved.
Show resolved Hide resolved
RequestType = DiagnosticsMessageType.AttachProfiler,
Pid = (uint)Process.GetCurrentProcess().Id,
};

byte[] serializedConfiguration = SerializeProfilerAttach((uint)attachTimeout.TotalSeconds, profilerGuid, profilerPath, additionalData);
var message = new IpcMessage(DiagnosticsServerCommandSet.Profiler, (byte)ProfilerCommandId.AttachProfiler, serializedConfiguration);
var response = IpcClient.SendMessage(_processId, message);
switch ((DiagnosticsServerCommandId)response.Header.CommandId)
{
case DiagnosticsServerCommandId.Error:
var hr = BitConverter.ToInt32(response.Payload, 0);
throw new ServerErrorException($"Profiler attach failed (HRESULT: 0x{hr:X8})");
case DiagnosticsServerCommandId.OK:
return;
default:
throw new ServerErrorException($"Profiler attach failed - server responded with unknown command");
}

// TODO: the call to set up the pipe and send the message operates on a different timeout than attachTimeout, which is for the runtime.
sywhang marked this conversation as resolved.
Show resolved Hide resolved
// We should eventually have a configurable timeout for the message passing, potentially either separately from the
// runtime timeout or respect attachTimeout as one total duration.
}

/// <summary>
/// Get all the active processes that can be attached to.
/// </summary>
/// <returns>
/// IEnumerable of all the active process IDs.
/// </returns>
public static IEnumerable<int> GetPublishedProcesses()
{
return Directory.GetFiles(IpcRootPath)
sywhang marked this conversation as resolved.
Show resolved Hide resolved
.Select(namedPipe => (new FileInfo(namedPipe)).Name)
.Where(input => Regex.IsMatch(input, DiagnosticsPortPattern))
.Select(input => int.Parse(Regex.Match(input, DiagnosticsPortPattern).Groups[1].Value, NumberStyles.Integer))
.Distinct();
}

private static byte[] SerializeCoreDump(string dumpName, DumpType dumpType, bool diagnostics)
{
using (var stream = new MemoryStream())
using (var writer = new BinaryWriter(stream))
{
writer.WriteString(dumpName);
writer.Write((uint)dumpType);
writer.Write((uint)(diagnostics ? 1 : 0));

writer.Flush();
return stream.ToArray();
}
}

private static byte[] SerializeProfilerAttach(uint attachTimeout, Guid profilerGuid, string profilerPath, byte[] additionalData)
{
using (var stream = new MemoryStream())
using (var writer = new BinaryWriter(stream))
{
writer.Write(attachTimeout);
writer.Write(profilerGuid.ToByteArray());
writer.WriteString(profilerPath);

if (additionalData == null)
{
writer.Write(0);
}
else
{
writer.Write(additionalData.Length);
writer.Write(additionalData);
}

writer.Flush();
return stream.ToArray();
}
}
}
}
Loading