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:
public static void Disable()
Stops the profiler. Note that this method is not available for memory profiling.
public static void Enable()
Restarts the profiler, if you disabled it. Note that this method is not available for memory profiling.
public static void Reset()
Discards the results collected by the profiler during the current run of the application; all hit counts and timings are set to zero.
public static void TakeSnapshot()
Takes a snapshot and sends it to the ANTS Profiler graphical user interface.
Note the following:
This example shows you how can automate the Mandelbrot Set program in the Worked Example so that only the drawing process is profiled.
By default, the C# project file is located in:
Program Files\Red Gate\ANTS Profiler 3\Tutorials\CS\Mandelbrot
By default, the .dll file is located in:
Program Files\Red Gate\ANTS Profiler 3
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.