Home arrow Software arrow .NET Profiler & Tracer arrow Support / Information arrow Callback-API Samples

Samples for using the Callback API

SpeedTrace Pro allows you to perform user-defined codes during the profiling and tracing of your dotnet application. This enables you to start or stop the recording process depending on the internal state of the application. You can query the actual parameters, return parameters of the functions called by the application, and query the respective function names. This allows you to perform your own sophisticated analyses and responses.


Below, you will find code samples demonstrating certain features of the callback mechanism. All samples are provided in the manner of Visual Studio 2005 projects. For details regarding the Callback API, refer to SpeedTrace Pro Help. The terms "method" and "function" are used in the same sense.


toggle CallbackPerformanceTest

Demonstration goals:


  • Querying function names

  • Querying actual parameters

  • Querying return values

This sample delivers information about the sample application "Sort". With "Sort", you can create an array of random values. Just type in the number of elements and press the "Create" button. To sort the array, press the "Sort" button. Sorting is performed by the function SortArray(int elements). The sample demonstrates how the callback mechanism can be applied to measure the performance of certain functions (here SortArray()). When tracing is started, a notice is written to the DOS box and a text file called "test.txt" is opened in the working directory. This text file is used for storing the performance data.

At any time when the SortArray() function is called, the time needed for sorting and the number of elements is shown in the DOS box. These values are also written to the text file and can be easily imported, for example, into Excel to be visualized. When the tracer is stopped, the text file is closed.

Download: CallbackPerformanceTest

Also necessary (if not already installed): Common Modules

 

toggle CallbackTest

Demonstration goals:

  • Querying function names

  • Querying actual parameters

  • Querying return values


This sample delivers information about the sample application "Computation". With "Computation", you can calculate a value z based on the values x and y. The calculation is performed by the function "Computation.Form1.Compute" (or in short "Compute").

In this sample the actual parameters of "Compute" (x, y) are printed in a DOS box. The return value of the function (the result of the computation) is printed as well. The values are printed (together with the number of calls) in a new line every time the function "Compute" is performed. Note: When "Compute" is called for the first time then the name of this function is printed in a headline. When tracings start or stop, a short remark is written to the DOS box (initial and final operations are done).

Several settings must be configured in SpeedTrace Pro: "Access Arguments" and "Access Return Value" must be enabled. For "Method Enter Callback" and "Method Leave Callback" functions, the functions "EnterCallbackTest" and "LeaveCallbackTest" must be declared. The functions "StartTraceCallbackTest" and "StopTraceCallbackTest" must be declared in the section "Trace Function Callback". "Start Trigger" and "Stop Trigger Callback" functions are of no importance for this example.

Download: CallbackTest

Also necessary (if not already installed): Common Modules


toggle CallbackTriggerTest

Demonstration goals:

  • Set up additional conditions for Start and Stop Triggers

This sample shows how the Start and Stop trigger functions can be used to extend the trigger functionality offered by the SpeedTrace Pro UI. We recommend using "WinTest" together with this example, although the code may be applied to any application.

The first thing to do is to set up Start and Stop trigger functions in SpeedTrace Pro. When the Start trigger function is reached, you will be informed the first time, but the tracing is not started yet. Once the application has been running for one minute, the extended start trigger fires, and the tracing is started. The extended stop trigger is fired when the stop trigger condition is met and the application has been running for at least two minutes. Here the time limit is used as an extended stop trigger condition. When the extended stop trigger fires, tracing is finally stopped.

The example only uses the StartTriggerCallbackTest and the StopTriggerCallbackTest functions. These functions must be set in the Callback API tab of SpeedTrace Pro. Optionally, the functions StartTraceCallbackTest and StopTestCallbackTest can be activated. In this case you will get additional messages at the beginning and termination of the tracing.

Download: CallbackTriggerTest

Also necessary (if not already installed): Common Modules


toggle ValueAccess

Demonstration goals:

  • Querying function names

  • Querying actual parameters as values its original type (not as strings)

  • Querying return values as values with its original type (not as strings)


This sample works like the sample "CallbackTest". In "CallbackTest", data values of the investigated program (similarly to the function arguments) are queried generally as strings, which may be easier to handle, whereas in "ValueAccess" the data values keep their original data type.

The sample delivers information about the sample application "Computation". With "Computation", you can calculate a value z based on the values x and y. The calculation is performed using the function "Computation.Form1.Compute" (or in short "Compute").

In the sample code the actual parameters of "Compute" (x, y) are printed in a DOS box. The return value of the function (the result of the computation) is printed as well. The values are printed (together with the number of calls) in a new line every time the function "Compute" is activated.
Furthermore: The first time "Compute" is called, the name of this function is printed in a headline. When tracings start or stop, a short note is written to the DOS box (initial and final operations are performed).


Several settings must be configured in SpeedTrace Pro: "Access Arguments" and "Access Return Value" must be enabled. For "Method Enter Callback" and "Method Leave Callback" functions, the functions "EnterCallbackTest" and "LeaveCallbackTest" must be declared. The functions "StartTraceCallbackTest" and "StopTraceCallbackTest" must be declared in the section "Trace Function Callback".

"Start Trigger" and "Stop Trigger Callback" functions are of no importance in this example.

Download: ValueTest

Also necessary (if not already installed): Common Modules



  Common

  This refers to files necessary for all sample projects.

 Download: Common

<<
↑


ipcas GmbH is a member of Data Respons Group


Copyright 1988 - 2010 ipcas GmbH

Gundstrasse 15 D-91056 Erlangen Tel.: +49 (0)9131/ 7677-0 Fax: +49 (0)9131/ 7677-78 E-Mail: info@ipcas.de