Browse Source

Merge pull request #2519 from icsharpcode/christophwille/measure

Add ETW for Performance Measuring
pull/2526/head
Christoph Wille 4 years ago committed by GitHub
parent
commit
7979d19299
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 33
      ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs
  2. 1
      ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj
  3. 59
      ICSharpCode.Decompiler/Instrumentation/DecompilerEventSource.cs

33
ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs

@ -1209,6 +1209,7 @@ namespace ICSharpCode.Decompiler.CSharp
EntityDeclaration DoDecompile(ITypeDefinition typeDef, DecompileRun decompileRun, ITypeResolveContext decompilationContext) EntityDeclaration DoDecompile(ITypeDefinition typeDef, DecompileRun decompileRun, ITypeResolveContext decompilationContext)
{ {
Debug.Assert(decompilationContext.CurrentTypeDefinition == typeDef); Debug.Assert(decompilationContext.CurrentTypeDefinition == typeDef);
var watch = System.Diagnostics.Stopwatch.StartNew();
try try
{ {
var typeSystemAstBuilder = CreateAstBuilder(decompileRun.Settings); var typeSystemAstBuilder = CreateAstBuilder(decompileRun.Settings);
@ -1361,6 +1362,11 @@ namespace ICSharpCode.Decompiler.CSharp
{ {
throw new DecompilerException(module, typeDef, innerException); throw new DecompilerException(module, typeDef, innerException);
} }
finally
{
watch.Stop();
Instrumentation.DecompilerEventSource.Log.DoDecompileTypeDefinition(typeDef.FullName, watch.ElapsedMilliseconds);
}
} }
enum EnumValueDisplayMode enum EnumValueDisplayMode
@ -1447,6 +1453,9 @@ namespace ICSharpCode.Decompiler.CSharp
EntityDeclaration DoDecompile(IMethod method, DecompileRun decompileRun, ITypeResolveContext decompilationContext) EntityDeclaration DoDecompile(IMethod method, DecompileRun decompileRun, ITypeResolveContext decompilationContext)
{ {
Debug.Assert(decompilationContext.CurrentMember == method); Debug.Assert(decompilationContext.CurrentMember == method);
var watch = System.Diagnostics.Stopwatch.StartNew();
try
{
var typeSystemAstBuilder = CreateAstBuilder(decompileRun.Settings); var typeSystemAstBuilder = CreateAstBuilder(decompileRun.Settings);
var methodDecl = typeSystemAstBuilder.ConvertEntity(method); var methodDecl = typeSystemAstBuilder.ConvertEntity(method);
int lastDot = method.Name.LastIndexOf('.'); int lastDot = method.Name.LastIndexOf('.');
@ -1485,6 +1494,12 @@ namespace ICSharpCode.Decompiler.CSharp
} }
return methodDecl; return methodDecl;
} }
finally
{
watch.Stop();
Instrumentation.DecompilerEventSource.Log.DoDecompileMethod(method.FullName, watch.ElapsedMilliseconds);
}
}
private bool IsCovariantReturnOverride(IEntity entity) private bool IsCovariantReturnOverride(IEntity entity)
{ {
@ -1684,6 +1699,7 @@ namespace ICSharpCode.Decompiler.CSharp
EntityDeclaration DoDecompile(IField field, DecompileRun decompileRun, ITypeResolveContext decompilationContext) EntityDeclaration DoDecompile(IField field, DecompileRun decompileRun, ITypeResolveContext decompilationContext)
{ {
Debug.Assert(decompilationContext.CurrentMember == field); Debug.Assert(decompilationContext.CurrentMember == field);
var watch = System.Diagnostics.Stopwatch.StartNew();
try try
{ {
var typeSystemAstBuilder = CreateAstBuilder(decompileRun.Settings); var typeSystemAstBuilder = CreateAstBuilder(decompileRun.Settings);
@ -1746,6 +1762,11 @@ namespace ICSharpCode.Decompiler.CSharp
{ {
throw new DecompilerException(module, field, innerException); throw new DecompilerException(module, field, innerException);
} }
finally
{
watch.Stop();
Instrumentation.DecompilerEventSource.Log.DoDecompileField(field.FullName, watch.ElapsedMilliseconds);
}
} }
internal static bool IsFixedField(IField field, out IType type, out int elementCount) internal static bool IsFixedField(IField field, out IType type, out int elementCount)
@ -1768,6 +1789,7 @@ namespace ICSharpCode.Decompiler.CSharp
EntityDeclaration DoDecompile(IProperty property, DecompileRun decompileRun, ITypeResolveContext decompilationContext) EntityDeclaration DoDecompile(IProperty property, DecompileRun decompileRun, ITypeResolveContext decompilationContext)
{ {
Debug.Assert(decompilationContext.CurrentMember == property); Debug.Assert(decompilationContext.CurrentMember == property);
var watch = System.Diagnostics.Stopwatch.StartNew();
try try
{ {
var typeSystemAstBuilder = CreateAstBuilder(decompileRun.Settings); var typeSystemAstBuilder = CreateAstBuilder(decompileRun.Settings);
@ -1822,11 +1844,17 @@ namespace ICSharpCode.Decompiler.CSharp
{ {
throw new DecompilerException(module, property, innerException); throw new DecompilerException(module, property, innerException);
} }
finally
{
watch.Stop();
Instrumentation.DecompilerEventSource.Log.DoDecompileProperty(property.FullName, watch.ElapsedMilliseconds);
}
} }
EntityDeclaration DoDecompile(IEvent ev, DecompileRun decompileRun, ITypeResolveContext decompilationContext) EntityDeclaration DoDecompile(IEvent ev, DecompileRun decompileRun, ITypeResolveContext decompilationContext)
{ {
Debug.Assert(decompilationContext.CurrentMember == ev); Debug.Assert(decompilationContext.CurrentMember == ev);
var watch = System.Diagnostics.Stopwatch.StartNew();
try try
{ {
var typeSystemAstBuilder = CreateAstBuilder(decompileRun.Settings); var typeSystemAstBuilder = CreateAstBuilder(decompileRun.Settings);
@ -1862,6 +1890,11 @@ namespace ICSharpCode.Decompiler.CSharp
{ {
throw new DecompilerException(module, ev, innerException); throw new DecompilerException(module, ev, innerException);
} }
finally
{
watch.Stop();
Instrumentation.DecompilerEventSource.Log.DoDecompileEvent(ev.FullName, watch.ElapsedMilliseconds);
}
} }
#region Sequence Points #region Sequence Points

1
ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj

@ -100,6 +100,7 @@
<Compile Include="IL\Transforms\LdLocaDupInitObjTransform.cs" /> <Compile Include="IL\Transforms\LdLocaDupInitObjTransform.cs" />
<Compile Include="IL\Transforms\PatternMatchingTransform.cs" /> <Compile Include="IL\Transforms\PatternMatchingTransform.cs" />
<Compile Include="IL\Transforms\RemoveInfeasiblePathTransform.cs" /> <Compile Include="IL\Transforms\RemoveInfeasiblePathTransform.cs" />
<Compile Include="Instrumentation\DecompilerEventSource.cs" />
<Compile Include="Metadata\ReferenceLoadInfo.cs" /> <Compile Include="Metadata\ReferenceLoadInfo.cs" />
<Compile Include="Semantics\OutVarResolveResult.cs" /> <Compile Include="Semantics\OutVarResolveResult.cs" />
<Compile Include="SingleFileBundle.cs" /> <Compile Include="SingleFileBundle.cs" />

59
ICSharpCode.Decompiler/Instrumentation/DecompilerEventSource.cs

@ -0,0 +1,59 @@
// Copyright (c) 2021 Christoph Wille
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System.Diagnostics.Tracing;
namespace ICSharpCode.Decompiler.Instrumentation
{
[EventSource(Name = "ICSharpCode.Decompiler")]
public sealed class DecompilerEventSource : EventSource
{
[Event(1, Level = EventLevel.Informational)]
public void DoDecompileEvent(string eventName, long elapsedMilliseconds)
{
WriteEvent(1, eventName, elapsedMilliseconds);
}
[Event(2, Level = EventLevel.Informational)]
public void DoDecompileProperty(string propertyName, long elapsedMilliseconds)
{
WriteEvent(2, propertyName, elapsedMilliseconds);
}
[Event(3, Level = EventLevel.Informational)]
public void DoDecompileField(string fieldName, long elapsedMilliseconds)
{
WriteEvent(3, fieldName, elapsedMilliseconds);
}
[Event(4, Level = EventLevel.Informational)]
public void DoDecompileTypeDefinition(string typeDefName, long elapsedMilliseconds)
{
WriteEvent(4, typeDefName, elapsedMilliseconds);
}
[Event(5, Level = EventLevel.Informational)]
public void DoDecompileMethod(string methodName, long elapsedMilliseconds)
{
WriteEvent(5, methodName, elapsedMilliseconds);
}
public static DecompilerEventSource Log = new DecompilerEventSource();
}
}
Loading…
Cancel
Save