Understanding How Visual Studio Analyzer Works

   

In order to customize your component for Visual Studio Analyzer, you need to understand the parts of Visual Studio Analyzer and how they work together.

The following figure illustrates the basic parts of Visual Studio Analyzer.

Visual Studio Analyzer consists of several parts: the framework, the event monitor, the event log, and the views. All of Visual Studio Analyzer is hosted in the Visual Studio environment. All Visual Studio Analyzer parts can exist on the same machine, as well as on multiple machines.

Part Purpose
Visual Studio Analyzer Event Monitor The Visual Studio Analyzer Event Monitor knows about the components on a particular machine and collects the events generated by each component, then evaluates the events against the active filter. Events that do not pass the active filter are ignored; events that fit the active filter criteria are passed on to the Visual Studio Analyzer Framework.
Visual Studio Analyzer Framework The Visual Studio Analyzer Framework collects the events passed from each Visual Studio Analyzer Event Monitor and populates the current Visual Studio Analyzer Event Log and Visual Studio Analyzer Displays.
Visual Studio Analyzer Event Log The Visual Studio Analyzer Event Log contains all the events collected by the Visual Studio Analyzer Framework for a given session. A Visual Studio Analyzer session consists of all Visual Studio Analyzer activity taking place between the creating or opening of a Visual Studio Analyzer project and the closing of that project.
Visual Studio Analyzer Views The Visual Studio Analyzer Views present the collected events to the Visual Studio Analyzer user. Only events in the event log are displayed. Filtered events might be temporarily removed from view.

Registration Process

Before you can generate events from your component, your component must be registered. The registration process identifies your component to the Event Monitor, as well as identifying the events you plan to generate. The registration process is shown in the following illustration:

Your components interact with Visual Studio Analyzer throughout their lifecycles through code you write. The registration process and the parts you have to perform are summarized in the following list — please see the related topics for more information on how you can enable your components to perform each step.

  1. Create a unique instance of the Visual Studio Analyzer Event Source Installer object.

    The Visual Studio Analyzer Event Source Installer object is a COM object that provides methods for registering your component with the Visual Studio Analyzer framework.

  2. Register your component with the Visual Studio Analyzer framework.

    Visual Studio Analyzer components are registered on the machine or machines where they are running. Doing so allows the Visual Studio Analyzer user to view not only the events generated by your component but the machine on which the events were generated. Knowing the identity of the machine can be useful when trying to analyze performance or isolate faults.

    Components are either normal or dynamic. Dynamic components generate events at defined intervals. Performance Monitor is a good example, as is a network traffic monitor. Both of these components provide information about the status of measurable items at a particular point in time. The danger is that dynamic components can generate large amounts of data, which will most likely affect system performance, so you need to use them carefully.

    Normally you register your component with the Visual Studio Analyzer framework at the time your component is installed or at the time your component starts up. See Registering New Components with Visual Studio Analyzer for information on how to register your component with the Visual Studio Analyzer framework.

  3. Register any new Visual Studio Analyzer event categories your component will use (optional).

    Event categories allow you to group the events your component generates in a logical fashion. You are not required to use categories, but if your component generates many events, event categories can help the Visual Studio Analyzer user find the events of interest. Visual Studio Analyzer ships with several predefined event categories, or you can define custom event categories. See Registering New Event Categories with Visual Studio Analyzer for a list of the predefined event categories and for information on how to register event categories for your application.

  4. Register the Visual Studio Analyzer events your component will generate.

    A Visual Studio Analyzer event is an occurrence in the life cycle of a component, such as starting, stopping, calling a function, or querying a database. Visual Studio Analyzer ships with several predefined events, or you can define custom events. See System-defined Visual Studio Analyzer Events for a list of the predefined events, and Registering New Events with Visual Studio Analyzer for information on how to register events for your component.

After you complete the registration process, you can continue with the event generation process.

Event Generation Process

The Visual Studio Analyzer event generation process is illustrated in the following figure:

The event generation process and the parts your component must perform are summarized in the following list.

  1. Create a unique instance of the Visual Studio Analyzer Inprocess Event Creator object.

    The Inprocess Event Creator object is a COM object that provides methods for uniquely identifying a given instance of your component and for actually generating events. Make sure you create this object after any calls to DllMain.

  2. Uniquely identify this session of your component to the Visual Studio Analyzer event monitor.

    The unique identifier is important because your component might be running on several machines at the same time. If each component is generating Visual Studio Analyzer events, a unique identifier is necessary to distinguish between events generated by each instance of the component.

  3. Generate events.

    You can generate events at any point in your code. The FireEvent method allows you to pass the event name and any relevant event data. You can generate as many events as you need; keep in mind, however, that generating very large numbers of events will impact the performance of your system.

  4. Notify Visual Studio Analyzer that this instance of your component is finished generating events.

  5. Destroy the unique instance of the Visual Studio Analyzer Inprocess Event Creator object.

Visual Studio Analyzer includes one pre-registered component for generating events, DEBUG_EVENT_SOURCE_USER. You can use this component to fire unregistered events. For production applications, it is better to register one of the actual components and the events it generates, but the pre-registered component does allow for quick high-level debugging and may be useful during development or testing of an application.

For More Information   For more detailed information on language-specific code to generate events, see Generating Visual Studio Analyzer Events.