ANTS Performance Profiler 7

Help for older versions available.

These pages cover ANTS Performance Profiler 7, which is not the latest version. Help for other versions is also available.

Worked example - Profiling from the command line

This worked example demonstrates how you can use ANTS Performance Profiler from the command line.

Profiling from the command line is useful if you want to integrate performance profiling into your usual testing or build processes. The profiler results can be output to CSV, XML or HTML, which means that you can easily check the results for abnormal values as part of your automated routines.

This example uses the following simple C# Console Application (called SimpleApp.exe) which prints '.' to the console 100 times:

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. namespace SimpleApp
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. Console.WriteLine("The application has started");
  12. // Count from 0-99
  13. int i = 0;
  14. while (i < 100)
  15. {
  16. Console.Write('.');
  17. i++;
  18. }
  19. Console.WriteLine("The application is exiting");
  20. }
  21. }
  22. }

Another simple C# Console Application can read the results CSV file created by ANTS Performance Profiler, to check that Write() is called exactly 100 times, thereby verifying that SimpleApp is performing correctly:

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.IO;
  6.  
  7.  
  8. namespace ReadOutput
  9. {
  10. class TextFileReader
  11. {
  12. static void Main(string[] args)
  13. {
  14. StreamReader sr = new StreamReader(new FileStream("C:\testing\results.csv", FileMode.Open, FileAccess.Read));
  15. string line;
  16. int ok = 1;
  17. // Read file line-by-line
  18. while ((line = sr.ReadLine()) != null)
  19. {
  20. char separator = ',';
  21. string[] linedata = new string[10];
  22. linedata = line.Split(separator);
  23. // Try to cast linedata[3] as int, not string
  24. int i;
  25. try
  26. {
  27. i = (int)int.Parse(linedata[3]);
  28. // Check the number of times that Write(char value) is run
  29. if ((linedata[2] == "Write(char value)") && (i != 100))
  30. {
  31. Console.WriteLine("Test failed");
  32. ok = 0;
  33. }
  34. }
  35. catch
  36. {
  37. // Do nothing
  38. }
  39. }
  40. sr.Close();
  41. if (ok == 1)
  42. {
  43. Console.WriteLine("Test passed OK");
  44. }
  45. }
  46. }
  47. }

Finally, an MS-DOS batch file can be written to profile SimpleApp in ANTS Performance Profiler and, when this is complete, to check that the test passed:

  1. C:
  2. CD /
  3. CD "Program Files\Red Gate\ANTS Performance Profiler 7\"
  4. Profile.exe /e:"C:\testing\SimpleApp.exe" /ll /csv:"C:\testing\results.csv"
  5. C:
  6. CD testing
  7. ReadOutput.exe

The console shows:

  1. C:\testing>ReadOutput.exe
  2. Test passed OK

This confirms that SimpleApp is performing correctly.

For a list of all available command line arguments, see Profiling from the command line (API).

For a more complex example describing how to integrate ANTS Performance Profiler results with an NUnit test, see Integrating Performance Profiling into the Build Process.


Didn't find what you were looking for?