Chapter 10: Managed Exception Monitoring

Slides:



Advertisements
Similar presentations
Advanced Troubleshooting with Debug Diagnostics on IIS 6
Advertisements

COS 461 Fall 1997 Network Objects u first good implementation: DEC SRC Network Objects for Modula-3 u recent implementation: Java RMI (Remote Method Invocation)
Chapter 7: User-Defined Functions II Instructor: Mohammad Mojaddam.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 15: Exception Handling.
Chapter 16: Exception Handling C++ Programming: From Problem Analysis to Program Design, Fifth Edition.
Backup and Recovery Part 1.
Introduction to .Net Framework
CIS 270—Application Development II Chapter 13—Exception Handling.
COMPUTER PROGRAMMING 2 Exceptions. What are Exceptions? Unexpected events that happen when the code is executing (during runtime). Exceptions are types.
Understanding Events and Exceptions Lesson 3. Objective Domain Matrix Skills/ConceptsMTA Exam Objectives Understand events and event handling Understand.
Chapter 3.5 Memory and I/O Systems. 2 Memory Management Memory problems are one of the leading causes of bugs in programs (60-80%) MUCH worse in languages.
Introduction to Exception Handling and Defensive Programming.
tom perkins1 XML Web Services -.NET FRAMEWORK – Part 1 CHAPTER 1.1 – 1.3.
Chapter 14: Exception Handling. Objectives In this chapter, you will: – Learn what an exception is – Learn how to handle exceptions within a program –
1 C++ Classes and Data Structures Jeffrey S. Childs Chapter 4 Pointers and Dynamic Arrays Jeffrey S. Childs Clarion University of PA © 2008, Prentice Hall.
Writing a Run Time DLL The application loads the DLL using LoadLibrary() or LoadLibraryEx(). The standard search sequence is used by the operating system.
CSCI Rational Purify 1 Rational Purify Overview Michel Izygon - Jim Helm.
PRIOR TO WEB SERVICES THE OTHER TECHNOLOGIES ARE:.
Garbage Collection and Classloading Java Garbage Collectors  Eden Space  Surviver Space  Tenured Gen  Perm Gen  Garbage Collection Notes Classloading.
Processes and Virtual Memory
CSE 332: C++ Statements C++ Statements In C++ statements are basic units of execution –Each ends with ; (can use expressions to compute values) –Statements.
Memory Management in Java Computer Science 3 Gerb Objective: Understand references to composite types in Java.
Chapter 15: Exception Handling C++ Programming: Program Design Including Data Structures, Fifth Edition.
Common Language Runtime Introduction  The common language runtime is one of the most essential component of the.Net Framework.  It acts.
Win32 Programming Lesson 19: Introduction to DLLs.
Internet Computing Module II. Syllabus Creating & Using classes in Java – Methods and Classes – Inheritance – Super Class – Method Overriding – Packages.
Introduction to Exceptions in Java CS201, SW Development Methods.
Improve Embedded System Stability and Performance through Memory Analysis Tools Bill Graham, Product Line Manager Development Tools November 14, 2006.
CSE 332: C++ Exceptions Motivation for C++ Exceptions Void Number:: operator/= (const double denom) { if (denom == 0.0) { // what to do here? } m_value.
Java Thread Programming
Introduction to Operating Systems Concepts
Computer System Structures
Dynamic Allocation in C
C++ Exceptions.
Java Interview Questions
Processes and threads.
Jim Fawcett CSE681 – SW Modeling & Analysis Fall 2014
Using Application Domains Effectively
Hands-On Microsoft Windows Server 2008
Java Programming Language
Scheduler activations
Multithreaded Programming in Java
Chapter 4: Multithreaded Programming
Implementing Processes and Threads
Coding Defensively Coding Defensively
Writing Highly Available .Net Framework Applications
JAVA Introduction ការណែនាំពី Java
CLR MD A New Swiss Army Knife tool for Advanced Debugging
Fall 2017 CISC124 9/21/2018 CISC124 First onQ quiz this week – write in lab. More details in last Wednesday’s lecture. Repeated: The quiz availability.
Chapter 14: Exception Handling
Auditing in SQL Server 2008 DBA-364-M
EE422C Software Implementation II
Software Construction
.NET Debugging for the Production Environment
Exceptions with Functions
Jihyun Park, Changsun Park, Byoungju Choi, Gihun Chang
Cancellation.
Programming and Debugging
Structuring Of Systems Using Upcalls - By David D. Clark
Implementing Processes and Threads
Introduction to Programming
Exceptions 10-May-19.
Following Malware Execution in IDA
CS703 – Advanced Operating Systems
Jim Fawcett CSE681 – SW Modeling & Analysis Fall 2018
CMSC 202 Exceptions 2nd Lecture.
Introduction to AppDomains
Exception Handling.
Software Construction
IS 135 Business Programming
Presentation transcript:

Chapter 10: Managed Exception Monitoring Testing Seminar 05 March 2004.

The Dilemma  Win32 and COM programming benefits came with support costs. Limited ability to peek inside a process to investigate runtime problems. Crashes, hangs, heap corruption. Memory leaks, mismatched reference counts. Build your own instrumentation. Detours technology, many, many printf calls, custom crash handlers.

The Remedy  MS .NET CLR profiling interface. Create one COM object to profile and .NET managed application. CLR provides dozens of built in metrics about runtime behavior.

Agenda Introduction to Profiling. Details about the profiling interface. Inside a profiling object. Details of profiling managed code. PROFILELIB & EXCEPTIONMON The FOUR checks.

Introduction to Profiling. The idea of watching someone’s moves. Types of Profiling Sampling. The profiler peeks at the profilee at a specific time interval and checks what’s running. Non-Sampling. The profiler monitors every call of the profilee and returns synchronously so that it can track everything that occurs in the profilee.

What all can be profiled? Runtime AppDomain Assembly Module Class Function Thread Remoting Transitions Runtime suspension Garbage Collection Exception.

The Profiling Interface

Development problem ! WHY????? Though we have profiling API defined….we cannot write profilers in Managed Code WHY?????

Answer The profiler runs in the address space of the managed application that is being profiled. Using managed code to profile managed code would lead into dirty problems.

Answer (cont’d) Example: If we were notified of the Garbage Collector being called, and we need to allocate managed memory to store the items being collected, you would end up a triggering a recursive call to the garbage collector.

BUT THIS WOULD SLOW DOWN THE PROFILEE An alternative (phew) To support managed profilers, all the notifications would have to occur cross process. BUT THIS WOULD SLOW DOWN THE PROFILEE

Most of the profilers are A Secret Most of the profilers are COM DLL’s !

It’s COM…so where is the CATCH? The profiler COM code is called in a completely free threaded model. So, all the work needed to protect data structures from multi-threaded corruption needs to be taken care of.

ICorProfilerCallback 2 methods sure to be called … ALWAYS Initialize The first method to be called. Shutdown The last method to be called.

Initialize method Functionality Communication is via ID’s. Use the QueryInterface of the IUnknown interface and query for ICorProfileInfo. Interface. Stores the returned interface to request info about the profilee. Communication is via ID’s. Appropriate functions are present that take in the ID and give out the method details.

Example ICorProfileCallback :: ModuleLoadFinished(ModuleID) ICorProfileCallback :: GetModuleInfo(ModuleID) Gives module name, load address and assembly ID.

What does the initialize do? Inform to the CLR the notifications that we are interested in. to minimize resource usage. Done using ::SetEventMask(…) Some modifications need to be set via the Initialize method itself. Non immutable ones can be toggled during run time.

Shutdown method For managed applications SHUTDOWN is always called. For application starts running as a native application, it loads the CLR (eg. VS.NET IDE), the shut down method will never be called. => the profiler WILL NOT STOP.

The Execute method (cont’d) Only way is to process the DLL_PROCESS_DETACH in the DllMain() and check whether the shutdown has been called. If not called, the clean up is manually done (via code).

Passing of ID’s

Getting the profiler started. Set up environment variables: Cor_Enable_Profiling Tells the CLR that it needs to turn on profiling. COR_PROFILER Set the CLSID or the ProgID of the profiler.

BUT WHAT ABT ASP.NET applications? Application Range Setting up of environment variables is good for Windows Forms and ConsoleApplications. BUT WHAT ABT ASP.NET applications?

Profiling for ASP.NET applications ASPNET_WP.EXE / W3WP.EXE Set up the system environment variables. Restart IIS after running this.

The BAD part All process that load the CLR will automatically be profiled. It’s ok for a few processes, but trouble comes when more processes are loaded ….eventually clogging resources.

The way around it…. Pass the Environment variables to check such that: The environment variable is not set, which assumes that you want to profile all the processes. The value of the environment variable matches the current process drive path and name completely. It matches just the file name of the current process.

PROFILELIB

EXCEPTIONMON To be started after PROFILELIB is up and running. STDMETHOD (ExceptionThrown) (ObjectID thrownObjID) STDMETHOD (ExceptionUnwindFinallyEnter) (FunctionID fID) STDMETHOD (ExceptionCatchEnter) (FunctionID fID, ObjectID oID)

EXCEPTIONMON To start the EXCEPTIONMON along with the profilee, use EXPMONBREAK in the environment variables. EXPMONFLUSH : flushes all the writes immediately. EXPMONFILENAME : output file for EXPMONFLUSH writes.

BAD PROGRAMMING Exception Handling IS NOT TO BE USED INSTEAD OF switch-case. Basic reason for using exception blocks: Developers don’t check for method return values. (FIRE THEM)

The FINAL FOUR Rules FINALLY blocks are not HANDLES to base resources. Catch{…} are actually doing a throw. Rethrows should never happen. Else information of the origin of the exception is lost. In C#.NET, “using” expands into the same IL code as try…finally block and calls Dispose method.