# Apimon.exe: API Monitor

This tool monitors a running application for all Application Programming Interface (API) calls a process is making. APIMon counts and times the API calls. It also, optionally, monitors page faults caused by the monitored application and reports them by API call.

APIMon is useful as a performance monitor to help tune your application. You can determine the hot spots in an application by examining the APIs with the largest times and/or counts. You can look at which APIs are used, taking special note of calls that cause ring transitions to kernel mode or client/server transitions. Large numbers of these calls can be the cause of a slow application.

APIMon can generate two types of reports.

- A report listing the number of calls made to each API and total time spent in each API.
- A trace file listing the individual calls to all APIs with the calling parameters as they occurred in time.

Files Required

- Apimon.cnt
- Apimon.exe
- Apimon.hlp

APIMon Topics

- Using APIMon
- APIMon Syntax
- APIMon Options

top

## Using APIMon

You can run APIMon from the command line or by double-clicking Apimon.exe in Windows Explorer. After APIMon starts you must open a program for monitoring. When running APIMon from a command line, you can optionally specify the program name as an argument.

To monitor an application in APIMon

1. Start APIMon.
2. Open the application you want to monitor.
3. Start the application by pushing the "Go" traffic light button, or click Tools and then click Start Monitor.

When the application starts, two windows appear. The first counts APIs and displays the time, and the second lists the current DLLs.

top

## APIMon Syntax

apimon [-b] [-g] [-t value] [appname] [-?]

Where:

-b
  breaks into the debugger when APIMon starts.
-g
  goes immediately.
-t value
  sets refresh rate to value.
appname
  is the name of the application to be monitored.
-?
  displays a syntax dialog box.

See APIMon Options for more information on options available on the APIMon Properties page.

top

## APIMon Options

The following options may be specified in the APIMon Options dialog box:

### Miscellaneous Options tab

Enable Tracing

Turns on API tracing. This causes APIMon to create a trace file containing one line of text for each API call made by the monitored application. The trace contains the following information:

1. Return Address

2. First four arguments

3. API Name

Enable Aliasing

Turns on aliasing.

Enable Counters

Turns on API counting and timing.

Pre-Load Symbols

Enabling this option causes APIMon to load the debug symbols for all DLLs while the monitored program is executing. This option is turned on when Monitor Page Faults is turned on.

Disable Heap Checking

When a process is being debugged, NTDLL's heap manager turns on a set of heap-checking flags. This ensures that if the process corrupts its heap, the debugger will catch the error. The heap checking flags also slow down the process and change the characteristics of the heap.

The Disable Heap Checking option disables this behavior and allows the process to run as if it were not being debugged.

Go Immediately

This option causes APIMon to start the monitor for the application as soon as the program is opened by selecting File, and then Open from the menu or when a program name is specified on the APIMon command line.

Don’t Use Fast Counters

On Intel Pentium processors, APIMon can use special instructions to do the API timings. Other processors must use the Win32 API GetPerformanceCounter(). This option disables the use of these instructions if APIMon is running on one of the supported platforms.

Monitor Known DLLs Only

By default, APIMon monitors API calls to all DLLs that the monitored process loads, either statically or dynamically. This option provides for the monitoring of a specific list of DLLs to be monitored. To create the DLL list, see "Known DLLs Options," later in this document.

Monitor Page Faults

Enabling this option causes APIMon to create a new window that displays page fault information. The window displays one entry for each API from all enabled DLLs that has caused a page fault.

Default Counter Sorting

This option specifies the default sort order for the API counter window. The sort order can be changed while the monitor is running.

### File Names Tab

Log File Name

Specify a full path and file name for the APIMon log file. You may specify a file on your local computer or a UNC name to a network path and name. This file is created when the menu command Write Data To Log File is selected from the File menu. The file is overwritten each time the log file is created.

Trace File Name

Specify a full path and file name for the Trace file. You may specify a file on your local computer or a UNC name to a network path and name. This file is created when the Enable Tracing option is turned on. The file is overwritten each time the trace file is created.

Symbol Path

This string is a path or multiple paths separated by semicolons. Each path points to a tree containing debug symbols. The debug symbols can be either .dbg files, .exe files, or .pdb files. This string is necessary if the Pre-Load Symbols option is turned on.

### Known DLLs Tab

This property page is used to specify a list of Known DLLs that are initially monitored by APIMon, which can be useful if you don't want APIMon to clutter the display and log file with irrelevant statistics.

To add a new entry to the list, click an empty entry. In the edit box, enter the DLL name and press enter. The DLL name must not contain a full path, just the DLL name with a .dll extension.

To delete an entry, click the desired entry, delete all of the text, and press enter. The entry is then removed from the list.

In order for this DLL list to take effect, the Monitor Known DLLs Only option must be turned on.