Skip to content

Commit

Permalink
Initial functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
mfilippov committed May 28, 2018
1 parent a074288 commit e6948bd
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Set the default behavior, in case people don't have core.autocrlf set.
* text=auto

# Declare files that will always have CRLF line endings on checkout.
*.sln text eol=crlf
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Usage: ClrStack.exe PID
19 changes: 19 additions & 0 deletions src/ClrStack.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClrStack", "ClrStack\ClrStack.csproj", "{2ECDA63E-31B6-4562-B88D-FDC51DCA1959}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2ECDA63E-31B6-4562-B88D-FDC51DCA1959}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2ECDA63E-31B6-4562-B88D-FDC51DCA1959}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2ECDA63E-31B6-4562-B88D-FDC51DCA1959}.Release|x64.ActiveCfg = Release|x64
{2ECDA63E-31B6-4562-B88D-FDC51DCA1959}.Release|x64.Build.0 = Release|x64
{2ECDA63E-31B6-4562-B88D-FDC51DCA1959}.Release|x86.ActiveCfg = Release|x86
{2ECDA63E-31B6-4562-B88D-FDC51DCA1959}.Release|x86.Build.0 = Release|x86
EndGlobalSection
EndGlobal
64 changes: 64 additions & 0 deletions src/ClrStack/ClrStack.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{2ECDA63E-31B6-4562-B88D-FDC51DCA1959}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ClrStack</RootNamespace>
<AssemblyName>ClrStack</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32bit>false</Prefer32bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
<OutputPath>bin\x64\Release\</OutputPath>
<PlatformTarget>x64</PlatformTarget>
<Prefer32bit>false</Prefer32bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<OutputPath>bin\x86\Release\</OutputPath>
<PlatformTarget>x86</PlatformTarget>
<Prefer32bit>true</Prefer32bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Diagnostics.Runtime, Version=0.9.0.0, Culture=neutral, PublicKeyToken=4c5463f04c407af6">
<HintPath>..\packages\Microsoft.Diagnostics.Runtime.0.9.180305.01\lib\net40\Microsoft.Diagnostics.Runtime.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
39 changes: 39 additions & 0 deletions src/ClrStack/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Globalization;
using System.Linq;
using Microsoft.Diagnostics.Runtime;

namespace ClrStack
{
internal static class Program
{
public static void Main(string[] args)
{
if (args.Length != 1 || !int.TryParse(args[0], NumberStyles.Integer, CultureInfo.InvariantCulture,out var pid))
{
Console.Error.WriteLine("Usage: ClrStack.exe [PID]");
return;
}
using (var target = DataTarget.AttachToProcess(pid, 1000, AttachFlag.NonInvasive))
{
var clrVersion = target.ClrVersions.FirstOrDefault();
if (clrVersion == null)
{
Console.WriteLine($"CLR not found in process: {pid}");
return;
}
var runtime = clrVersion.CreateRuntime();

foreach (var clrThread in runtime.Threads)
{
if (!clrThread.IsAlive)
continue;
Console.WriteLine($"Thread #{clrThread.ManagedThreadId}:");

foreach (var frame in clrThread.StackTrace)
Console.WriteLine($"\tat {frame}");
}
}
}
}
}
19 changes: 19 additions & 0 deletions src/ClrStack/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Reflection;
using System.Runtime.InteropServices;

[assembly: AssemblyTitle("ClrStack")]
[assembly: AssemblyDescription("Tool for capture thread dump from .NET process")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Mikhail Filippov")]
[assembly: AssemblyProduct("ClrStack")]
[assembly: AssemblyCopyright("Copyright © Mikhail Filippov 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

[assembly: ComVisible(false)]


[assembly: Guid("2ECDA63E-31B6-4562-B88D-FDC51DCA1959")]

[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
4 changes: 4 additions & 0 deletions src/ClrStack/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Diagnostics.Runtime" version="0.9.180305.01" targetFramework="net461" />
</packages>

0 comments on commit e6948bd

Please sign in to comment.