ANTS Profiler 3   

Using the ANTS Profiler API

See Also

If you have purchased a Pro edition of ANTS Profiler, you can use the Application Program Interface to automate profiling in ANTS Profiler.

The ANTS Profiler API enables you to profile specific parts of your application. You can make calls to the API to take snapshots on demand.

The API is provided by the file RedGate.Profiler.Api.dll which is located in the folder where you installed ANTS Profiler, by default:

Program Files\Red Gate\ANTS Profiler 3

When you add references in your project to RedGate.Profiler.Api.dll, the class RedGate.Profiler.Api will be available to you.

You can use the following methods:

Note the following:

Example

This example shows you how can automate the Mandelbrot Set program in the Worked Example so that only the drawing process is profiled.

  1. Open the Mandelbrot project file.

    By default, the C# project file is located in:

    Program Files\Red Gate\ANTS Profiler 3\Tutorials\CS\Mandelbrot

  2. Add references to RedGate.Profiler.Api.dll

    By default, the .dll file is located in:

    Program Files\Red Gate\ANTS Profiler 3

  3. In Form1.Main( ), modify the DrawMandelbrot method as shown below, and then build the project.
    • Call RedGate.Profiler.Api.Reset( ) to discard all the results gathered up to the point when the program starts drawing the fractal.
    • Call RedGate.Profiler.Api.TakeSnapshot( ) so that when the program has finished drawing the fractal, you capture the profiling results up to that point.
private void DrawMandelbrot()
		{

			RedGate.Profiler.Api.Reset();

			double dx = m_Settings.Width / m_MandelbrotImage.Width;
			double dy = m_Settings.Height / m_MandelbrotImage.Height;

			double x = m_Settings.XMin;
			double y = m_Settings.YMin;

			for(int i = 0; i < m_MandelbrotImage.Width; i++)
			{
				for( int j = 0; j < m_MandelbrotImage.Height; j++)
				{
					int iterations = m_Algorithm.Evaluate(x, y);
					m_MandelbrotImage.SetPixelColor(i, j, iterations);
					y += dy;
				}

				if(!m_Running)
					return;

				y = m_Settings.YMin;
				x += dx;

				// redraw the picture box every 10 pixels
				if ((i % 10)==0)
				{
					m_PictureBox1.Refresh();
					Application.DoEvents();
				}

			}

			m_PictureBox1.Refresh();

			RedGate.Profiler.Api.TakeSnapshot();
		}

In ANTS Profiler, use the Profiler Project Wizard to set up a project to profile the application, and then run the application in ANTS Profiler.

 

 

 


© Red Gate Software Ltd 2007. All Rights Reserved.