SlideShare una empresa de Scribd logo
1 de 107
.NET Profilers aren’t scary shaun.wilde@commonvision.com.au shaun_wilde@hotmail.com @scubamunki Email: Email: Twitter:
Who am I? Specialize in providing project teams with the necessary frameworks and personnel during the critical early stages of the project. shaun.wilde@commonvision.com.au shaun_wilde@hotmail.com @scubamunki Email: Email: Twitter:
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?
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
Profilers: What are they good for?
Monitor Load/Unload Events Application Domains Assemblies Modules Classes JIT Compilation Events Monitor threads, remotingand native/managed transitions Monitor GC events Monitor exceptions Monitor method enter/leave Monitor the runtime
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
Dynamically create new classes and methods Rewrite the IL of existing methods Allocate memory Work with the GC Interact with the runtime
Commercial Redgate ANTS NCover(was originally Open Source) JetBrainsdotCover/dotTrace CLRProfiler4 (Microsoft with Source Code) Commercial and Open Source Profilers* (*Obviously this list is not complete)
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)
System.Reflection.Emit .NET Framework Mono.Cecil https://github.com/mono/cecil Other IL (Re)Writing Methods
Important Interfaces Implementation and Registration Overview of the Profiler API
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
.NET Runtime through the ages
ICorProfilerCallback 69 Methods ICorProfilerInfo 33 Methods IMetaDataImport 64 Methods IMetaDataEmit 49 Methods .NET1
ICorProfilerCallback2 8 Methods ICorProfilerInfo2 21 Methods IMetaDataImport2 64 Methods IMetaDataEmit2 49 Methods .NET2
ICorProfilerCallback3 3 Methods ICorProfilerInfo3 14 Methods .NET4
How much?
Register the COM Object Use Environment variables c:>set COR_ENABLE_PROFILING=1 c:>set COR_PROFILER=MyProfiler.Profiler Instantiation
[object Object]
Need to be side-by-side CLR awarePick one Pick first Pick all/many RunSxS http://archive.msdn.microsoft.com/RunSxS .NET4
Silverlight support CORECLR_ENABLE_PROFILING CORECLR_PROFILER CORECLR_PROFILER_PATH .NET4
Creating an ATL COM object with required interfaces Demo 1
Create host and target processes Launch Target with Profiler Simple Target Demo 2
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
Getting assembly and method names Interfaces ICorProfilerInfo3 IMetaDataImport2 Demo 4
What is a Method? Headers Sections Clauses The Method Body Operations Branches The Stack Debug vs. Release Basics of IL Rewriting
Tiny and Fat Methods
Tiny and Fat Sections
Tiny and Fat Clauses
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
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
Variation on Try/Catch VB.NET only COR_ILEXCEPTION_CLAUSE_FILTER
Try/Finally Code in handler block always called regardless of how the associated try block is exited. COR_ILEXCEPTION_CLAUSE_FINALLY
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
A Mystery // duplicated clause..  this clause was duplicated down to a funclet which was pulled out of line COR_ILEXCEPTION_CLAUSE_DUPLICATED
The Method Body Operations Branches The Stack Debug vs. Release The Method Body
Contains all the information needed to interpret and write  IL Canonical Name String Name Stack Behaviour Parameter Size Length Bytes Control Flow OPCODE.DEF
OPCODE.DEF
OPCODE.DEF
Is there a difference? Debug vs. Release
Headers Stack size Method Size Clauses Offsets Lengths Branches Size of Jump Considerations when adding IL
Make … Tiny headers Fat Tiny sections Fat Tiny clauses Fat Short branches Long  Cheat… Use the parser from OpenCover Common approach when adding IL
Leverage the OpenCover parser Demo 5
Add a new Type Exception Define Constructor (.ctor) Throw new Type Add extra IL to TargetMethod Adding new classes and methods I
Interfaces IMetaDataEmit2 IMetaDataAssemblyEmit Adding New Classes and Methods
IL DASM
Complicated Intensive Hmmmm……
Sequence Points PDB Files IL Rewriting Points out of sync Debugging

Más contenido relacionado

La actualidad más candente

Trusted Third Parties are NOT Trust Worthy!
Trusted Third Parties are NOT Trust Worthy!Trusted Third Parties are NOT Trust Worthy!
Trusted Third Parties are NOT Trust Worthy!nettitude_labs
 
PVS-Studio and static code analysis technique
PVS-Studio and static code analysis techniquePVS-Studio and static code analysis technique
PVS-Studio and static code analysis techniqueAndrey Karpov
 
.Net Hijacking to Defend PowerShell BSidesSF2017
.Net Hijacking to Defend PowerShell BSidesSF2017 .Net Hijacking to Defend PowerShell BSidesSF2017
.Net Hijacking to Defend PowerShell BSidesSF2017 Amanda Rousseau
 
[2014 CodeEngn Conference 10] 정광운 - 안드로이드에서도 한번 후킹을 해볼까 (Hooking on Android)
[2014 CodeEngn Conference 10] 정광운 -  안드로이드에서도 한번 후킹을 해볼까 (Hooking on Android)[2014 CodeEngn Conference 10] 정광운 -  안드로이드에서도 한번 후킹을 해볼까 (Hooking on Android)
[2014 CodeEngn Conference 10] 정광운 - 안드로이드에서도 한번 후킹을 해볼까 (Hooking on Android)GangSeok Lee
 
Writing clean code in C# and .NET
Writing clean code in C# and .NETWriting clean code in C# and .NET
Writing clean code in C# and .NETDror Helper
 
Continuous Integration: Live Static Analysis with Puma Scan
Continuous Integration: Live Static Analysis with Puma ScanContinuous Integration: Live Static Analysis with Puma Scan
Continuous Integration: Live Static Analysis with Puma ScanCypress Data Defense
 
Crowd debugging (FSE 2015)
Crowd debugging (FSE 2015)Crowd debugging (FSE 2015)
Crowd debugging (FSE 2015)Sung Kim
 
Python code profiling - Jackson Isaac
Python code profiling - Jackson IsaacPython code profiling - Jackson Isaac
Python code profiling - Jackson IsaacJackson Isaac
 
Python - code quality and production monitoring
Python - code quality and production monitoringPython - code quality and production monitoring
Python - code quality and production monitoringDavid Melamed
 
Steelcon 2015 Reverse-Engineering Obfuscated Android Applications
Steelcon 2015 Reverse-Engineering Obfuscated Android ApplicationsSteelcon 2015 Reverse-Engineering Obfuscated Android Applications
Steelcon 2015 Reverse-Engineering Obfuscated Android ApplicationsTom Keetch
 
What Can Reverse Engineering Do For You?
What Can Reverse Engineering Do For You?What Can Reverse Engineering Do For You?
What Can Reverse Engineering Do For You?Amanda Rousseau
 
Abusing Adobe Reader’s JavaScript APIs by Abdul-Aziz Hariri & Brian Gorenc - ...
Abusing Adobe Reader’s JavaScript APIs by Abdul-Aziz Hariri & Brian Gorenc - ...Abusing Adobe Reader’s JavaScript APIs by Abdul-Aziz Hariri & Brian Gorenc - ...
Abusing Adobe Reader’s JavaScript APIs by Abdul-Aziz Hariri & Brian Gorenc - ...CODE BLUE
 
Pharo Optimising JIT Internals
Pharo Optimising JIT InternalsPharo Optimising JIT Internals
Pharo Optimising JIT InternalsESUG
 
Java code coverage with JCov. Implementation details and use cases.
Java code coverage with JCov. Implementation details and use cases.Java code coverage with JCov. Implementation details and use cases.
Java code coverage with JCov. Implementation details and use cases.Alexandre (Shura) Iline
 
Refactoring a go project
Refactoring a go projectRefactoring a go project
Refactoring a go projectDan Tran
 
FRIDA 101 Android
FRIDA 101 AndroidFRIDA 101 Android
FRIDA 101 AndroidTony Thomas
 

La actualidad más candente (20)

Trusted Third Parties are NOT Trust Worthy!
Trusted Third Parties are NOT Trust Worthy!Trusted Third Parties are NOT Trust Worthy!
Trusted Third Parties are NOT Trust Worthy!
 
PVS-Studio and static code analysis technique
PVS-Studio and static code analysis techniquePVS-Studio and static code analysis technique
PVS-Studio and static code analysis technique
 
.Net Hijacking to Defend PowerShell BSidesSF2017
.Net Hijacking to Defend PowerShell BSidesSF2017 .Net Hijacking to Defend PowerShell BSidesSF2017
.Net Hijacking to Defend PowerShell BSidesSF2017
 
[2014 CodeEngn Conference 10] 정광운 - 안드로이드에서도 한번 후킹을 해볼까 (Hooking on Android)
[2014 CodeEngn Conference 10] 정광운 -  안드로이드에서도 한번 후킹을 해볼까 (Hooking on Android)[2014 CodeEngn Conference 10] 정광운 -  안드로이드에서도 한번 후킹을 해볼까 (Hooking on Android)
[2014 CodeEngn Conference 10] 정광운 - 안드로이드에서도 한번 후킹을 해볼까 (Hooking on Android)
 
Writing clean code in C# and .NET
Writing clean code in C# and .NETWriting clean code in C# and .NET
Writing clean code in C# and .NET
 
Continuous Integration: Live Static Analysis with Puma Scan
Continuous Integration: Live Static Analysis with Puma ScanContinuous Integration: Live Static Analysis with Puma Scan
Continuous Integration: Live Static Analysis with Puma Scan
 
Crowd debugging (FSE 2015)
Crowd debugging (FSE 2015)Crowd debugging (FSE 2015)
Crowd debugging (FSE 2015)
 
Python code profiling - Jackson Isaac
Python code profiling - Jackson IsaacPython code profiling - Jackson Isaac
Python code profiling - Jackson Isaac
 
Clean Code V2
Clean Code V2Clean Code V2
Clean Code V2
 
Pragmatic Code Coverage
Pragmatic Code CoveragePragmatic Code Coverage
Pragmatic Code Coverage
 
Introduction to Frida
Introduction to FridaIntroduction to Frida
Introduction to Frida
 
Python - code quality and production monitoring
Python - code quality and production monitoringPython - code quality and production monitoring
Python - code quality and production monitoring
 
Steelcon 2015 Reverse-Engineering Obfuscated Android Applications
Steelcon 2015 Reverse-Engineering Obfuscated Android ApplicationsSteelcon 2015 Reverse-Engineering Obfuscated Android Applications
Steelcon 2015 Reverse-Engineering Obfuscated Android Applications
 
What Can Reverse Engineering Do For You?
What Can Reverse Engineering Do For You?What Can Reverse Engineering Do For You?
What Can Reverse Engineering Do For You?
 
Abusing Adobe Reader’s JavaScript APIs by Abdul-Aziz Hariri & Brian Gorenc - ...
Abusing Adobe Reader’s JavaScript APIs by Abdul-Aziz Hariri & Brian Gorenc - ...Abusing Adobe Reader’s JavaScript APIs by Abdul-Aziz Hariri & Brian Gorenc - ...
Abusing Adobe Reader’s JavaScript APIs by Abdul-Aziz Hariri & Brian Gorenc - ...
 
Reverse Engineering Android Application
Reverse Engineering Android ApplicationReverse Engineering Android Application
Reverse Engineering Android Application
 
Pharo Optimising JIT Internals
Pharo Optimising JIT InternalsPharo Optimising JIT Internals
Pharo Optimising JIT Internals
 
Java code coverage with JCov. Implementation details and use cases.
Java code coverage with JCov. Implementation details and use cases.Java code coverage with JCov. Implementation details and use cases.
Java code coverage with JCov. Implementation details and use cases.
 
Refactoring a go project
Refactoring a go projectRefactoring a go project
Refactoring a go project
 
FRIDA 101 Android
FRIDA 101 AndroidFRIDA 101 Android
FRIDA 101 Android
 

Similar a .NET Profilers and IL Rewriting - DDD Melbourne 2

powershell-is-dead-epic-learnings-london
powershell-is-dead-epic-learnings-londonpowershell-is-dead-epic-learnings-london
powershell-is-dead-epic-learnings-londonnettitude_labs
 
Fast and Generic Malware Triage Using openioc_scan Volatility Plugin
Fast and Generic Malware Triage Using openioc_scan Volatility PluginFast and Generic Malware Triage Using openioc_scan Volatility Plugin
Fast and Generic Malware Triage Using openioc_scan Volatility PluginTakahiro Haruyama
 
FIWARE Wednesday Webinars - How to Debug IoT Agents
FIWARE Wednesday Webinars - How to Debug IoT AgentsFIWARE Wednesday Webinars - How to Debug IoT Agents
FIWARE Wednesday Webinars - How to Debug IoT AgentsFIWARE
 
Net framework
Net frameworkNet framework
Net frameworkTuan Ngo
 
Mocking vtcc3 - en
Mocking   vtcc3 - enMocking   vtcc3 - en
Mocking vtcc3 - envgrondin
 
Common ASP.NET Design Patterns - Telerik India DevCon 2013
Common ASP.NET Design Patterns - Telerik India DevCon 2013Common ASP.NET Design Patterns - Telerik India DevCon 2013
Common ASP.NET Design Patterns - Telerik India DevCon 2013Steven Smith
 
Introduction to llvm
Introduction to llvmIntroduction to llvm
Introduction to llvmTao He
 
Lap around .net 4
Lap around .net 4Lap around .net 4
Lap around .net 4Abdul Khan
 
PHP 7 Crash Course - php[world] 2015
PHP 7 Crash Course - php[world] 2015PHP 7 Crash Course - php[world] 2015
PHP 7 Crash Course - php[world] 2015Colin O'Dell
 
springtraning-7024840-phpapp01.pdf
springtraning-7024840-phpapp01.pdfspringtraning-7024840-phpapp01.pdf
springtraning-7024840-phpapp01.pdfBruceLee275640
 
Aspect Oriented Programming Through C#.NET
Aspect Oriented Programming Through C#.NETAspect Oriented Programming Through C#.NET
Aspect Oriented Programming Through C#.NETWaqas Tariq
 
Rifartek Robot Training Course - How to use ClientRobot
Rifartek Robot Training Course - How to use ClientRobotRifartek Robot Training Course - How to use ClientRobot
Rifartek Robot Training Course - How to use ClientRobotTsai Tsung-Yi
 
.NET Fundamentals and Business Application Development
.NET Fundamentals and Business Application Development.NET Fundamentals and Business Application Development
.NET Fundamentals and Business Application Development명신 김
 

Similar a .NET Profilers and IL Rewriting - DDD Melbourne 2 (20)

powershell-is-dead-epic-learnings-london
powershell-is-dead-epic-learnings-londonpowershell-is-dead-epic-learnings-london
powershell-is-dead-epic-learnings-london
 
Fast and Generic Malware Triage Using openioc_scan Volatility Plugin
Fast and Generic Malware Triage Using openioc_scan Volatility PluginFast and Generic Malware Triage Using openioc_scan Volatility Plugin
Fast and Generic Malware Triage Using openioc_scan Volatility Plugin
 
FIWARE Wednesday Webinars - How to Debug IoT Agents
FIWARE Wednesday Webinars - How to Debug IoT AgentsFIWARE Wednesday Webinars - How to Debug IoT Agents
FIWARE Wednesday Webinars - How to Debug IoT Agents
 
The Veil-Framework
The Veil-FrameworkThe Veil-Framework
The Veil-Framework
 
Net framework
Net frameworkNet framework
Net framework
 
Mocking vtcc3 - en
Mocking   vtcc3 - enMocking   vtcc3 - en
Mocking vtcc3 - en
 
C sharp
C sharpC sharp
C sharp
 
News In The Net40
News In The Net40News In The Net40
News In The Net40
 
Common ASP.NET Design Patterns - Telerik India DevCon 2013
Common ASP.NET Design Patterns - Telerik India DevCon 2013Common ASP.NET Design Patterns - Telerik India DevCon 2013
Common ASP.NET Design Patterns - Telerik India DevCon 2013
 
Introduction to llvm
Introduction to llvmIntroduction to llvm
Introduction to llvm
 
Codeigniter
CodeigniterCodeigniter
Codeigniter
 
Lap around .net 4
Lap around .net 4Lap around .net 4
Lap around .net 4
 
PHP 7 Crash Course - php[world] 2015
PHP 7 Crash Course - php[world] 2015PHP 7 Crash Course - php[world] 2015
PHP 7 Crash Course - php[world] 2015
 
.net Framework
.net Framework.net Framework
.net Framework
 
springtraning-7024840-phpapp01.pdf
springtraning-7024840-phpapp01.pdfspringtraning-7024840-phpapp01.pdf
springtraning-7024840-phpapp01.pdf
 
Spring boot
Spring bootSpring boot
Spring boot
 
Aspect Oriented Programming Through C#.NET
Aspect Oriented Programming Through C#.NETAspect Oriented Programming Through C#.NET
Aspect Oriented Programming Through C#.NET
 
Rifartek Robot Training Course - How to use ClientRobot
Rifartek Robot Training Course - How to use ClientRobotRifartek Robot Training Course - How to use ClientRobot
Rifartek Robot Training Course - How to use ClientRobot
 
LLVM
LLVMLLVM
LLVM
 
.NET Fundamentals and Business Application Development
.NET Fundamentals and Business Application Development.NET Fundamentals and Business Application Development
.NET Fundamentals and Business Application Development
 

Último

H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 

Último (20)

H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 

.NET Profilers and IL Rewriting - DDD Melbourne 2

  • 1. .NET Profilers aren’t scary shaun.wilde@commonvision.com.au shaun_wilde@hotmail.com @scubamunki Email: Email: Twitter:
  • 2. Who am I? Specialize in providing project teams with the necessary frameworks and personnel during the critical early stages of the project. shaun.wilde@commonvision.com.au shaun_wilde@hotmail.com @scubamunki Email: Email: Twitter:
  • 3. 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?
  • 4. 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
  • 5. Profilers: What are they good for?
  • 6. Monitor Load/Unload Events Application Domains Assemblies Modules Classes JIT Compilation Events Monitor threads, remotingand native/managed transitions Monitor GC events Monitor exceptions Monitor method enter/leave Monitor the runtime
  • 7. 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
  • 8. Dynamically create new classes and methods Rewrite the IL of existing methods Allocate memory Work with the GC Interact with the runtime
  • 9. Commercial Redgate ANTS NCover(was originally Open Source) JetBrainsdotCover/dotTrace CLRProfiler4 (Microsoft with Source Code) Commercial and Open Source Profilers* (*Obviously this list is not complete)
  • 10. 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)
  • 11. System.Reflection.Emit .NET Framework Mono.Cecil https://github.com/mono/cecil Other IL (Re)Writing Methods
  • 12. Important Interfaces Implementation and Registration Overview of the Profiler API
  • 13. 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
  • 14.
  • 16. ICorProfilerCallback 69 Methods ICorProfilerInfo 33 Methods IMetaDataImport 64 Methods IMetaDataEmit 49 Methods .NET1
  • 17. ICorProfilerCallback2 8 Methods ICorProfilerInfo2 21 Methods IMetaDataImport2 64 Methods IMetaDataEmit2 49 Methods .NET2
  • 18. ICorProfilerCallback3 3 Methods ICorProfilerInfo3 14 Methods .NET4
  • 20. Register the COM Object Use Environment variables c:>set COR_ENABLE_PROFILING=1 c:>set COR_PROFILER=MyProfiler.Profiler Instantiation
  • 21.
  • 22. Need to be side-by-side CLR awarePick one Pick first Pick all/many RunSxS http://archive.msdn.microsoft.com/RunSxS .NET4
  • 23. Silverlight support CORECLR_ENABLE_PROFILING CORECLR_PROFILER CORECLR_PROFILER_PATH .NET4
  • 24. Creating an ATL COM object with required interfaces Demo 1
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30. Create host and target processes Launch Target with Profiler Simple Target Demo 2
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37. 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
  • 38.
  • 39.
  • 40.
  • 41.
  • 42. Getting assembly and method names Interfaces ICorProfilerInfo3 IMetaDataImport2 Demo 4
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50. What is a Method? Headers Sections Clauses The Method Body Operations Branches The Stack Debug vs. Release Basics of IL Rewriting
  • 51. Tiny and Fat Methods
  • 52.
  • 53.
  • 54. Tiny and Fat Sections
  • 55.
  • 56. Tiny and Fat Clauses
  • 57.
  • 58. 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
  • 59. 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
  • 60. Variation on Try/Catch VB.NET only COR_ILEXCEPTION_CLAUSE_FILTER
  • 61. Try/Finally Code in handler block always called regardless of how the associated try block is exited. COR_ILEXCEPTION_CLAUSE_FINALLY
  • 62. 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
  • 63. A Mystery // duplicated clause.. this clause was duplicated down to a funclet which was pulled out of line COR_ILEXCEPTION_CLAUSE_DUPLICATED
  • 64.
  • 65. The Method Body Operations Branches The Stack Debug vs. Release The Method Body
  • 66. Contains all the information needed to interpret and write IL Canonical Name String Name Stack Behaviour Parameter Size Length Bytes Control Flow OPCODE.DEF
  • 67.
  • 68.
  • 71. Is there a difference? Debug vs. Release
  • 72.
  • 73.
  • 74. Headers Stack size Method Size Clauses Offsets Lengths Branches Size of Jump Considerations when adding IL
  • 75. Make … Tiny headers Fat Tiny sections Fat Tiny clauses Fat Short branches Long Cheat… Use the parser from OpenCover Common approach when adding IL
  • 76. Leverage the OpenCover parser Demo 5
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83. Add a new Type Exception Define Constructor (.ctor) Throw new Type Add extra IL to TargetMethod Adding new classes and methods I
  • 84. Interfaces IMetaDataEmit2 IMetaDataAssemblyEmit Adding New Classes and Methods
  • 85.
  • 86.
  • 87.
  • 89.
  • 90.
  • 91.
  • 92.
  • 93.
  • 94.
  • 95.
  • 96.
  • 98.
  • 99.
  • 100.
  • 101.
  • 102.
  • 103.
  • 104. Sequence Points PDB Files IL Rewriting Points out of sync Debugging
  • 105.
  • 106.
  • 107.
  • 108. The End Demo code https://github.com/sawilde/DDD2011_ProfilerDemo