profile

profile — collects statistics on function usage and run time.

Syntax

profile (on_p, tick_nanosecs?)

		

Arguments

on_p

If non-nil, start profiling, else stop profiling.

tick_nanosecs

Reset the QNX 4 tick size to this many nanoseconds before beginning to profile.

Returns

The previous state of profiling.

Description

This function starts (or stops) collecting statistics on the usage and run time of all functions in the system. The profile mechanism uses an interrupt on the QNX 4 tick clock, and so must run with root permissions. If the optional tick_nanosecs argument is provided, this function will reset the tick size. Otherwise, it will profile using the current tick size. The smaller the tick size, the more precise is the profile result.

Example

The following program gives the output shown below.

#!/usr/cogent/bin/gamma

require_lisp("Profile.lsp");

e_list = list();
j = 0;

function print_reverse()
{
  with i in cdr(argv) do
    {
      e_list = cons(i, e_list); 
      j++;
    }
  princ("The numbers in reverse order are:\n", e_list, "\n");
}

function main()
{
  profile(t);
  print_reverse();
  profile(nil);
  
  profiled_functions();
  princ("Function calls: ", function_calls(cons),"\n");
  princ("Function runtime: ", function_runtime(cons),"\n");
}

Entered on command line:

[sh]$ ex_profile.g 1 2 3 4 5

Output:

The numbers in reverse order are:
(5 4 3 2 1)
                 Function     Calls  Total Time
                      +++         5  4e-06
                      cdr         1  0
                     cons         5  2e-06
                      for         1  2.3e-05
                  profile         1  1e-06
                     setq         5  3e-06
                    princ         1  0.006502
            print_reverse         1  0.006534
                    progn         6  0.006546
Function calls: 5
Function runtime: 1.9999999999999999095e-06

See Also

function_calls, function_runtime