20
Advanced .NET Debugging Kamran Bilgrami WindowsDebugging.com

Advanced .NET Debugging€¦ · References •Video: Advanced .NET Debugging Kamran Bilgrami @Techdays 2010 •Blogs: Easy to follow Labs Tess Ferrandez @ MSDN •PDF: Production

  • Upload
    others

  • View
    6

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Advanced .NET Debugging€¦ · References •Video: Advanced .NET Debugging Kamran Bilgrami @Techdays 2010 •Blogs: Easy to follow Labs Tess Ferrandez @ MSDN •PDF: Production

Advanced .NET

Debugging

Kamran Bilgrami WindowsDebugging.com

Page 2: Advanced .NET Debugging€¦ · References •Video: Advanced .NET Debugging Kamran Bilgrami @Techdays 2010 •Blogs: Easy to follow Labs Tess Ferrandez @ MSDN •PDF: Production

Agenda

• Challenges

• Debugging Approaches

• Conventional

• Best Practices

• Tools of the Trade

• Demo

• Contention Problem

• Reality Check

• Q & A

Page 3: Advanced .NET Debugging€¦ · References •Video: Advanced .NET Debugging Kamran Bilgrami @Techdays 2010 •Blogs: Easy to follow Labs Tess Ferrandez @ MSDN •PDF: Production

What is the Challenge?

Page 4: Advanced .NET Debugging€¦ · References •Video: Advanced .NET Debugging Kamran Bilgrami @Techdays 2010 •Blogs: Easy to follow Labs Tess Ferrandez @ MSDN •PDF: Production

Production Issues

• ONLY seen in live environment

• Cannot reproduced in house

Page 5: Advanced .NET Debugging€¦ · References •Video: Advanced .NET Debugging Kamran Bilgrami @Techdays 2010 •Blogs: Easy to follow Labs Tess Ferrandez @ MSDN •PDF: Production

Production Debugging Constraints

• Minimize Service interruptions

• Restricted Actions

• No code changes

• No tools Installation

• Limited Physical Access

• High Stress Situation

Page 6: Advanced .NET Debugging€¦ · References •Video: Advanced .NET Debugging Kamran Bilgrami @Techdays 2010 •Blogs: Easy to follow Labs Tess Ferrandez @ MSDN •PDF: Production

Conventional Approaches

• Gather information via Logs

• Code Profiling

• Get Repro Steps

Page 7: Advanced .NET Debugging€¦ · References •Video: Advanced .NET Debugging Kamran Bilgrami @Techdays 2010 •Blogs: Easy to follow Labs Tess Ferrandez @ MSDN •PDF: Production

Post-Mortem approach

Capture Memory Dump

Analyze Dump File

Page 8: Advanced .NET Debugging€¦ · References •Video: Advanced .NET Debugging Kamran Bilgrami @Techdays 2010 •Blogs: Easy to follow Labs Tess Ferrandez @ MSDN •PDF: Production

Post-Mortem approach Contd.

• Proven techniques

Page 9: Advanced .NET Debugging€¦ · References •Video: Advanced .NET Debugging Kamran Bilgrami @Techdays 2010 •Blogs: Easy to follow Labs Tess Ferrandez @ MSDN •PDF: Production

Process/Tools

Capture Dump

Task Manager

ADPlus

Analyze Dump

Windbg

Page 10: Advanced .NET Debugging€¦ · References •Video: Advanced .NET Debugging Kamran Bilgrami @Techdays 2010 •Blogs: Easy to follow Labs Tess Ferrandez @ MSDN •PDF: Production

Supporting Tools/Data

• OS Symbols

• SOS

Page 11: Advanced .NET Debugging€¦ · References •Video: Advanced .NET Debugging Kamran Bilgrami @Techdays 2010 •Blogs: Easy to follow Labs Tess Ferrandez @ MSDN •PDF: Production

• Capturing dump

Page 12: Advanced .NET Debugging€¦ · References •Video: Advanced .NET Debugging Kamran Bilgrami @Techdays 2010 •Blogs: Easy to follow Labs Tess Ferrandez @ MSDN •PDF: Production

Contention

Problems

Locks

Critical Section

Wait handles

External resources

Infinite Loop

High CPU in GC

Busy Server

Find which thread(s) are taking CPU.

Investigate why thread is busyFind threads that are waiting or sleeping

Investigate what these theads are doing

Page 13: Advanced .NET Debugging€¦ · References •Video: Advanced .NET Debugging Kamran Bilgrami @Techdays 2010 •Blogs: Easy to follow Labs Tess Ferrandez @ MSDN •PDF: Production

• Contention Problem

Page 14: Advanced .NET Debugging€¦ · References •Video: Advanced .NET Debugging Kamran Bilgrami @Techdays 2010 •Blogs: Easy to follow Labs Tess Ferrandez @ MSDN •PDF: Production

.loadby sos mscorwks

!ThreadPool

!runaway

.time

~12s

!CLRStack

!threads -special

!dumpheap -stat

!SyncBlk

~* e !CLRStack

Recap - Commands

Page 15: Advanced .NET Debugging€¦ · References •Video: Advanced .NET Debugging Kamran Bilgrami @Techdays 2010 •Blogs: Easy to follow Labs Tess Ferrandez @ MSDN •PDF: Production

Limitations

• Windbg not Visual Studio replacement

• Process dump is just a snapshot

• No trends

• Snapshot Timing

• Learning curve

Page 16: Advanced .NET Debugging€¦ · References •Video: Advanced .NET Debugging Kamran Bilgrami @Techdays 2010 •Blogs: Easy to follow Labs Tess Ferrandez @ MSDN •PDF: Production

Reality Check

• Development/QA process

• Test Driven Development

• Automate QA Tests

Page 17: Advanced .NET Debugging€¦ · References •Video: Advanced .NET Debugging Kamran Bilgrami @Techdays 2010 •Blogs: Easy to follow Labs Tess Ferrandez @ MSDN •PDF: Production

References

• Video: Advanced .NET Debugging Kamran Bilgrami @Techdays 2010

• Blogs: Easy to follow Labs Tess Ferrandez @ MSDN

• PDF: Production Debugging for .NET Applications Best Practices Document (Old but still useful)

Page 18: Advanced .NET Debugging€¦ · References •Video: Advanced .NET Debugging Kamran Bilgrami @Techdays 2010 •Blogs: Easy to follow Labs Tess Ferrandez @ MSDN •PDF: Production

Resources

Page 19: Advanced .NET Debugging€¦ · References •Video: Advanced .NET Debugging Kamran Bilgrami @Techdays 2010 •Blogs: Easy to follow Labs Tess Ferrandez @ MSDN •PDF: Production