-
-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from benaadams/code
Add 0.0.1 code
- Loading branch information
Showing
18 changed files
with
2,029 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 15 | ||
VisualStudioVersion = 15.0.27019.1 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{A2FCCAAC-BE90-4F7E-B95F-A72D46DDD6B3}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{59CA6310-4AA5-4093-95D4-472B94DC0CD4}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ben.Demystifier", "src\Ben.Demystifier\Ben.Demystifier.csproj", "{5410A056-89AB-4912-BD1E-A63616AD91D0}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ben.Demystifier.Test", "test\Ben.Demystifier.Test\Ben.Demystifier.Test.csproj", "{B9E150B0-AEEB-4D98-8BE1-92C1296699A2}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sample", "sample", "{455921D3-DD54-4355-85CF-F4009DF2AB70}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StackTrace", "sample\StackTrace\StackTrace.csproj", "{E161FC12-53C2-47CD-A5FC-3684B86723A9}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{5410A056-89AB-4912-BD1E-A63616AD91D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{5410A056-89AB-4912-BD1E-A63616AD91D0}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{5410A056-89AB-4912-BD1E-A63616AD91D0}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{5410A056-89AB-4912-BD1E-A63616AD91D0}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{B9E150B0-AEEB-4D98-8BE1-92C1296699A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{B9E150B0-AEEB-4D98-8BE1-92C1296699A2}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{B9E150B0-AEEB-4D98-8BE1-92C1296699A2}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{B9E150B0-AEEB-4D98-8BE1-92C1296699A2}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{E161FC12-53C2-47CD-A5FC-3684B86723A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{E161FC12-53C2-47CD-A5FC-3684B86723A9}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{E161FC12-53C2-47CD-A5FC-3684B86723A9}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{E161FC12-53C2-47CD-A5FC-3684B86723A9}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(NestedProjects) = preSolution | ||
{5410A056-89AB-4912-BD1E-A63616AD91D0} = {A2FCCAAC-BE90-4F7E-B95F-A72D46DDD6B3} | ||
{B9E150B0-AEEB-4D98-8BE1-92C1296699A2} = {59CA6310-4AA5-4093-95D4-472B94DC0CD4} | ||
{E161FC12-53C2-47CD-A5FC-3684B86723A9} = {455921D3-DD54-4355-85CF-F4009DF2AB70} | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {841B7D5F-E810-4F94-A529-002C7E075216} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Runtime.CompilerServices; | ||
using System.Threading.Tasks; | ||
|
||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
Exception exception = null; | ||
try | ||
{ | ||
new Program(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
exception = ex.Demystify(); | ||
} | ||
|
||
Console.WriteLine(exception); | ||
} | ||
|
||
static Action<string, bool> s_action = (string s, bool b) => s_func(s, b); | ||
static Func<string, bool, (string val, bool)> s_func = (string s, bool b) => (RefMethod(s), b); | ||
|
||
Action<Action<object>, object> _action = (Action<object> lambda, object state) => lambda(state); | ||
|
||
static string s = ""; | ||
|
||
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)] | ||
Program() : this(() => Start()) | ||
{ | ||
|
||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)] | ||
Program(Action action) | ||
{ | ||
RunAction((state) => _action((s) => action(), state), null); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)] | ||
static IEnumerable<string> Iterator(int startAt) | ||
{ | ||
var list = new List<int>() { 1, 2, 3, 4 }; | ||
foreach (var item in list) | ||
{ | ||
// Throws the exception | ||
list.Add(item); | ||
|
||
yield return item.ToString(); | ||
} | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)] | ||
static async Task<string> MethodAsync(int value) | ||
{ | ||
await Task.Delay(0); | ||
return GenericClass<byte>.GenericMethod(ref value); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)] | ||
static async Task<string> MethodAsync<TValue>(TValue value) | ||
{ | ||
return await MethodAsync(1); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)] | ||
static void RunAction(Action<object> lambda, object state) | ||
{ | ||
lambda(state); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)] | ||
static string RunLambda(Func<string> lambda) | ||
{ | ||
|
||
return lambda(); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)] | ||
static (string val, bool) Method(string value) | ||
{ | ||
Func<string> func = () => MethodAsync(value).GetAwaiter().GetResult(); | ||
var anonType = new { func }; | ||
return (RunLambda(() => anonType.func()), true); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)] | ||
static ref string RefMethod(int value) | ||
{ | ||
return ref s; | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)] | ||
static string RefMethod(in string value) | ||
{ | ||
var val = value; | ||
return LocalFuncParam(value).ToString(); | ||
|
||
int LocalFuncParam(string s) | ||
{ | ||
return int.Parse(LocalFuncRefReturn()); | ||
} | ||
|
||
ref string LocalFuncRefReturn() | ||
{ | ||
Method(val); | ||
return ref s; | ||
} | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)] | ||
static string Start() | ||
{ | ||
return LocalFunc2(true, false).ToString(); | ||
|
||
void LocalFunc1(long l) | ||
{ | ||
Start((val: "", true)); | ||
} | ||
|
||
bool LocalFunc2(bool b1, bool b2) | ||
{ | ||
LocalFunc1(1); | ||
return true; | ||
} | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)] | ||
static ref string RefMethod(bool value) | ||
{ | ||
return ref s; | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)] | ||
static void Start((string val, bool) param) | ||
{ | ||
s_action.Invoke(param.val, param.Item2); | ||
} | ||
|
||
|
||
class GenericClass<TSuperType> | ||
{ | ||
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)] | ||
public static string GenericMethod<TSubType>(ref TSubType value) | ||
{ | ||
var returnVal = ""; | ||
for (var i = 0; i < 10; i++) | ||
{ | ||
try | ||
{ | ||
returnVal += string.Join(", ", Iterator(5).Select(s => s)); | ||
} | ||
catch (Exception ex) | ||
{ | ||
throw new Exception(ex.Message, ex); | ||
} | ||
} | ||
|
||
return returnVal; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp2.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> | ||
<LangVersion>7.2</LangVersion> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> | ||
<LangVersion>7.2</LangVersion> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Ben.Demystifier\Ben.Demystifier.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<Product>Ben Core</Product> | ||
<Title>Ben.Demystifier</Title> | ||
<Description>High performance understanding for stack traces (Make error logs more productive)</Description> | ||
<Authors>ben_a_adams</Authors> | ||
<RepositoryUrl>https://github.com/benaadams/Ben.Demystifier</RepositoryUrl> | ||
<RepositoryType>git</RepositoryType> | ||
<IncludeSymbols>true</IncludeSymbols> | ||
<IncludeSource>true</IncludeSource> | ||
<Version>0.0.1</Version> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>netstandard2.0;net46</TargetFrameworks> | ||
<LangVersion>7.2</LangVersion> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp"> | ||
<Version>2.4.0</Version> | ||
</PackageReference> | ||
<PackageReference Include="System.Diagnostics.DiagnosticSource"> | ||
<Version>4.4.1</Version> | ||
</PackageReference> | ||
<PackageReference Include="System.Reflection.Metadata"> | ||
<Version>1.5.0</Version> | ||
</PackageReference> | ||
<PackageReference Include="System.Threading.Tasks.Extensions"> | ||
<Version>4.4.0</Version> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Copyright (c) Ben A Adams. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System.Reflection; | ||
|
||
namespace System.Diagnostics | ||
{ | ||
public class EnhancedStackFrame : StackFrame | ||
{ | ||
private string _fileName; | ||
private int _lineNumber; | ||
private int _colNumber; | ||
|
||
public StackFrame StackFrame { get; } | ||
|
||
public ResolvedMethod MethodInfo { get; } | ||
|
||
internal EnhancedStackFrame(StackFrame stackFrame, ResolvedMethod methodInfo, string fileName, int lineNumber, int colNumber) | ||
: base(fileName, lineNumber, colNumber) | ||
{ | ||
StackFrame = stackFrame; | ||
MethodInfo = methodInfo; | ||
|
||
_fileName = fileName; | ||
_lineNumber = lineNumber; | ||
_colNumber = colNumber; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the column number in the file that contains the code that is executing. | ||
/// This information is typically extracted from the debugging symbols for the executable. | ||
/// </summary> | ||
/// <returns>The file column number, or 0 (zero) if the file column number cannot be determined.</returns> | ||
public override int GetFileColumnNumber() => _colNumber; | ||
|
||
/// <summary> | ||
/// Gets the line number in the file that contains the code that is executing. | ||
/// This information is typically extracted from the debugging symbols for the executable. | ||
/// </summary> | ||
/// <returns>The file line number, or 0 (zero) if the file line number cannot be determined.</returns> | ||
public override int GetFileLineNumber() => _lineNumber; | ||
|
||
/// <summary> | ||
/// Gets the file name that contains the code that is executing. | ||
/// This information is typically extracted from the debugging symbols for the executable. | ||
/// </summary> | ||
/// <returns>The file name, or null if the file name cannot be determined.</returns> | ||
public override string GetFileName() => _fileName; | ||
|
||
/// <summary> | ||
/// Gets the offset from the start of the Microsoft intermediate language (MSIL) | ||
/// code for the method that is executing. This offset might be an approximation | ||
/// depending on whether or not the just-in-time (JIT) compiler is generating debugging | ||
/// code. The generation of this debugging information is controlled by the System.Diagnostics.DebuggableAttribute. | ||
/// </summary> | ||
/// <returns>The offset from the start of the MSIL code for the method that is executing.</returns> | ||
public override int GetILOffset() => StackFrame.GetILOffset(); | ||
|
||
/// <summary> | ||
/// Gets the method in which the frame is executing. | ||
/// </summary> | ||
/// <returns>The method in which the frame is executing.</returns> | ||
public override MethodBase GetMethod() => StackFrame.GetMethod(); | ||
|
||
/// <summary> | ||
/// Gets the offset from the start of the native just-in-time (JIT)-compiled code | ||
/// for the method that is being executed. The generation of this debugging information | ||
/// is controlled by the System.Diagnostics.DebuggableAttribute class. | ||
/// </summary> | ||
/// <returns>The offset from the start of the JIT-compiled code for the method that is being executed.</returns> | ||
public override int GetNativeOffset() => StackFrame.GetNativeOffset(); | ||
|
||
/// <summary> | ||
/// Builds a readable representation of the stack trace. | ||
/// </summary> | ||
/// <returns>A readable representation of the stack trace.</returns> | ||
public override string ToString() => MethodInfo.ToString(); | ||
} | ||
} |
Oops, something went wrong.