.NET Profilers and IL Rewriting - DDD Melbourne 2
-
Upload
shaun-wilde -
Category
Technology
-
view
16 -
download
5
description
Transcript of .NET Profilers and IL Rewriting - DDD Melbourne 2
![Page 2: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/2.jpg)
Who am I?
[email protected] [email protected]@scubamunki
Email:Email:
Twitter:
Specialize in providing project teams with the necessary frameworks and personnel during the critical early stages of the project.
![Page 3: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/3.jpg)
CoverageEye.NET◦ Originally hosted on GotDotNet
PartCover◦ Originally hosted on SourceForge◦ Forked to GitHub
https://github.com/sawilde/partcover.net4
OpenCover◦ Hosted on GitHub
https://github.com/sawilde/opencover
How did I get here?
![Page 4: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/4.jpg)
Profilers: What are they good for?◦ Quick review of some commercial and open
source .NET profilers Overview of the profiler API Code and Demos Basics of IL rewriting Code and Demos II Introducing new classes and methods Code and Demos III Extras (If time permits)
.NET Profilers aren’t (that) scary
![Page 5: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/5.jpg)
Profilers: What are they good for?
![Page 6: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/6.jpg)
Monitor Load/Unload Events◦ Application Domains◦ Assemblies◦ Modules◦ Classes
JIT Compilation Events Monitor threads, remoting and
native/managed transitions Monitor GC events Monitor exceptions Monitor method enter/leave
Monitor the runtime
![Page 7: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/7.jpg)
Get the names and signatures of classes and methods
Read the IL for methods (functions) Memory allocations
◦ Types◦ Garbage Collection
Call graphs
Interrogate the runtime
![Page 8: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/8.jpg)
Dynamically create new classes and methods
Rewrite the IL of existing methods Allocate memory Work with the GC
Interact with the runtime
![Page 9: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/9.jpg)
Commercial
Redgate ANTS
NCover (was originally Open Source)
JetBrains dotCover/dotTrace
CLRProfiler4 (Microsoft with Source Code)
Commercial and Open Source Profilers*
(*Obviously this list is not complete)
![Page 10: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/10.jpg)
Open Source
Nprof http://code.google.com/p/nprof/
SlimTune http://code.google.com/p/slimtune/
PartCover https://github.com/sawilde/partcover.net4
OpenCover https://github.com/sawilde/opencover
Commercial and Open Source Profilers*
(*Obviously this list is not complete)
![Page 11: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/11.jpg)
System.Reflection.Emit◦ .NET Framework
Mono.Cecil◦ https://github.com/mono/cecil
Other IL (Re)Writing Methods
![Page 12: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/12.jpg)
Important Interfaces Implementation and Registration
Overview of the Profiler API
![Page 13: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/13.jpg)
In-process COM object◦ i.e. a DLL
Native code◦ i.e. unmanaged code
Free threaded◦ i.e. the developer is responsible for any required
synchronisation 32/64 bit
◦ Like for like
Implementation
![Page 14: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/14.jpg)
I Cor Pr ofi l er I nf o2/ 3
I Unknown
Runt i me
I Cor Pr ofi l er Cal l back2/ 3
I Unknown
Pr ofi l er
Tar get Appl i cat i on
Launchi ng Appl i cat i onCOR_ENABLE_PROFI LI NG=1
COR_PROFI LER=<CLSI D or PROGI D of Pr ofi l er >
Cust om Appl i cat i on
Command Li ne
![Page 15: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/15.jpg)
.NET Runtime through the ages
![Page 16: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/16.jpg)
ICorProfilerCallback◦ 69 Methods
ICorProfilerInfo◦ 33 Methods
IMetaDataImport◦ 64 Methods
IMetaDataEmit◦ 49 Methods
.NET1
![Page 17: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/17.jpg)
ICorProfilerCallback2◦ 8 Methods
ICorProfilerInfo2◦ 21 Methods
IMetaDataImport2◦ 64 Methods
IMetaDataEmit2◦ 49 Methods
.NET2
![Page 18: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/18.jpg)
ICorProfilerCallback3◦ 3 Methods
ICorProfilerInfo3◦ 14 Methods
.NET4
![Page 19: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/19.jpg)
Methods
How much?
![Page 20: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/20.jpg)
Register the COM Object
Use Environment variables
c:>set COR_ENABLE_PROFILING=1c:>set COR_PROFILER=MyProfiler.Profiler
Instantiation
![Page 21: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/21.jpg)
NET4 profilers can be used to profile .NET2 assemblies
Need to be side-by-side CLR awarePick onePick firstPick all/many
◦ RunSxS http://archive.msdn.microsoft.com/RunSxS
.NET4
![Page 22: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/22.jpg)
Silverlight support
CORECLR_ENABLE_PROFILINGCORECLR_PROFILERCORECLR_PROFILER_PATH
.NET4
![Page 23: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/23.jpg)
Creating an ATL COM object with required interfaces
Demo 1
![Page 24: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/24.jpg)
![Page 25: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/25.jpg)
![Page 26: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/26.jpg)
![Page 27: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/27.jpg)
![Page 28: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/28.jpg)
![Page 29: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/29.jpg)
Create host and target processes
Launch Target with Profiler
Simple Target
Demo 2
![Page 30: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/30.jpg)
![Page 31: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/31.jpg)
![Page 32: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/32.jpg)
![Page 33: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/33.jpg)
![Page 34: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/34.jpg)
![Page 35: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/35.jpg)
![Page 36: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/36.jpg)
Requesting and handling events◦ ICorProfilerInfo::SetEventMask
COR_PRF_MONITOR_MODULE_LOADS
COR_PRF_MONITOR_JIT_COMPILATION
COR_PRF_DISABLE_INLINING
COR_PRF_DISABLE_OPTIMIZATIONS
Demo 3
![Page 37: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/37.jpg)
![Page 38: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/38.jpg)
![Page 39: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/39.jpg)
![Page 40: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/40.jpg)
![Page 41: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/41.jpg)
Getting assembly and method names
Interfaces◦ ICorProfilerInfo3◦ IMetaDataImport2
Demo 4
![Page 42: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/42.jpg)
![Page 43: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/43.jpg)
![Page 44: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/44.jpg)
![Page 45: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/45.jpg)
![Page 46: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/46.jpg)
![Page 47: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/47.jpg)
![Page 48: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/48.jpg)
![Page 49: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/49.jpg)
What is a Method?◦ Headers◦ Sections◦ Clauses
The Method Body◦ Operations◦ Branches◦ The Stack◦ Debug vs. Release
Basics of IL Rewriting
![Page 50: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/50.jpg)
Tiny and Fat Methods
1 0
CODE SIZE TYPE
Method with Tiny Header
![Page 51: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/51.jpg)
HEAD
ERM
ETHO
DSECTIO
NS
Method with Fat Header
![Page 52: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/52.jpg)
*
CODE SIZE
TYPE
LOCAL VARIABLES SIGNATURE TOKEN
HEADER SIZE FLAGS
0 0 1 1 * 1 1
MAX STACK
MO
RE SECTION
S
INITIALIZE LO
CAL VARIABLES
![Page 53: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/53.jpg)
Tiny and Fat Sections
EH TABLE
FAT FO
RMAT
MO
RE SECTIO
NS
* 0 1
KINDDATA SIZE RESERVED
Tiny Section
![Page 54: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/54.jpg)
EH TABLE
FAT FO
RMAT
MO
RE SECTIO
NS
* 1 1
KIND DATA SIZE
Fat Section
![Page 55: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/55.jpg)
Tiny and Fat Clauses
FLAGS
TRY OFFSET
TRY LENGTH
HANDLEROFFSET
HANDLERLENGTH
CLASSTOKEN/OFFSET
TINY CLAUSE
![Page 56: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/56.jpg)
FLAGS
TRY OFFSET
TRY LENGTH
HANDLEROFFSET
HANDLERLENGTH
CLASSTOKEN/OFFSET
FAT CLAUSE
![Page 57: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/57.jpg)
5 Types of Clauses◦ COR_ILEXCEPTION_CLAUSE_NONE◦ COR_ILEXCEPTION_CLAUSE_FILTER◦ COR_ILEXCEPTION_CLAUSE_FINALLY◦ COR_ILEXCEPTION_CLAUSE_FAULT◦ COR_ILEXCEPTION_CLAUSE_DUPLICATED
Clauses
![Page 58: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/58.jpg)
Try/Catch Code in handler block is called if an
exception of the type expected is thrown from code that is contained in the try block. (needs rewording)
COR_ILEXCEPTION_CLAUSE_NONE
![Page 59: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/59.jpg)
Variation on Try/Catch VB.NET only
COR_ILEXCEPTION_CLAUSE_FILTER
![Page 60: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/60.jpg)
Try/Finally Code in handler block always called
regardless of how the associated try block is exited.
COR_ILEXCEPTION_CLAUSE_FINALLY
![Page 61: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/61.jpg)
Try/Fault Code in handler block is only called if an
exception has occurred in the corresponding try block.
The exception continues on… IL Only?
COR_ILEXCEPTION_CLAUSE_FAULT
![Page 62: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/62.jpg)
A Mystery
// duplicated clause.. this clause was duplicated down to a funclet which was pulled out of line
COR_ILEXCEPTION_CLAUSE_DUPLICATED
![Page 63: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/63.jpg)
![Page 64: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/64.jpg)
The Method Body◦ Operations◦ Branches◦ The Stack◦ Debug vs. Release
The Method Body
![Page 65: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/65.jpg)
Contains all the information needed to interpret and write IL◦ Canonical Name◦ String Name◦ Stack Behaviour◦ Parameter Size◦ Length◦ Bytes◦ Control Flow
OPCODE.DEF
![Page 66: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/66.jpg)
![Page 67: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/67.jpg)
![Page 68: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/68.jpg)
OPCODE.DEF
![Page 69: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/69.jpg)
OPCODE.DEF
![Page 70: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/70.jpg)
Is there a difference?
Debug vs. Release
![Page 71: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/71.jpg)
![Page 72: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/72.jpg)
![Page 73: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/73.jpg)
Headers◦ Stack size◦ Method Size
Clauses◦ Offsets◦ Lengths
Branches◦ Size of Jump
Considerations when adding IL
![Page 74: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/74.jpg)
Make …◦ Tiny headers Fat◦ Tiny sections Fat◦ Tiny clauses Fat◦ Short branches Long
Cheat…◦ Use the parser from OpenCover
Common approach when adding IL
![Page 75: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/75.jpg)
Leverage the OpenCover parser
Demo 5
![Page 76: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/76.jpg)
![Page 77: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/77.jpg)
![Page 78: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/78.jpg)
![Page 79: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/79.jpg)
![Page 80: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/80.jpg)
![Page 81: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/81.jpg)
![Page 82: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/82.jpg)
Add a new Type◦ Exception◦ Define Constructor (.ctor)
Throw new Type◦ Add extra IL to TargetMethod
Adding new classes and methods I
![Page 83: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/83.jpg)
Interfaces◦ IMetaDataEmit2◦ IMetaDataAssemblyEmit
Adding New Classes and Methods
![Page 84: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/84.jpg)
![Page 85: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/85.jpg)
![Page 86: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/86.jpg)
![Page 87: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/87.jpg)
IL DASM
![Page 88: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/88.jpg)
![Page 89: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/89.jpg)
![Page 90: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/90.jpg)
![Page 91: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/91.jpg)
![Page 92: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/92.jpg)
![Page 93: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/93.jpg)
![Page 94: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/94.jpg)
![Page 95: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/95.jpg)
![Page 96: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/96.jpg)
Complicated Intensive
Hmmmm……
![Page 97: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/97.jpg)
![Page 98: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/98.jpg)
![Page 99: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/99.jpg)
![Page 100: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/100.jpg)
![Page 101: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/101.jpg)
![Page 102: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/102.jpg)
![Page 103: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/103.jpg)
Sequence Points◦ PDB Files
IL Rewriting◦ Points out of sync
Debugging
![Page 104: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/104.jpg)
![Page 105: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/105.jpg)
![Page 106: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/106.jpg)
![Page 107: .NET Profilers and IL Rewriting - DDD Melbourne 2](https://reader038.fdocuments.us/reader038/viewer/2022102813/54581a99af795997118b6420/html5/thumbnails/107.jpg)
The End
Demo code◦ https://github.com/sawilde/DDD2011_ProfilerDemo