DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
C programmer's productivity tools

Viewing the profiled source listing

Along with profiling information, lprof produces a source listing by default. Once you have executed your profiled program and the data file has been created, you can view the profile data by entering the following command:

   $ lprof
The lprof output consists of a source listing with profiling information in the left margin, as shown in the following example:
             	#include <stdio.h>
             	main()
        1 [3]	{
             		/* Note that declarations are not executable and
             		   therefore have no line-number or execution
             		   status associated with them. */

int i;

10 [10] for (i=0; i < 10; i++) 10 [11] sub1(); 1 [12] }

sub1() 10 [15] {

/* The following declaration *is* an executable statement. */ 10 [20] int i = 0;

10 [22] if (i > 0) { /* The next line is never executed. */ 0 [25] sub2(); 0 [26] } 0 [27] else { 10 [28] sub3(); 10 [29] } 10 [30] } sub2() 0 [33] { /* do nothing */ 0 [35] } sub3() 10 [38] { /* do same as sub2() */ 10 [40] }

The square brackets enclose line numbers for the file. Each number to the left of a line number shows how many times the corresponding source line was executed.

Showing unexecuted lines

If you use the -x option to lprof, the output highlights the lines that have not been executed. Lines that have been executed are marked only by line numbers. Lines that have not been executed are marked with a line number preceded by a [U]. The following example shows an example of output produced by the -x option:

             	#include <stdio.h>
             	main()
          [3]	{
             		/* Note that declarations are not executable and
             		   therefore have no line-number or execution
             		   status associated with them. */

int i;

[10] for (i=0; i < 10; i++) [11] sub1(); [12] } sub1() [15] { /* The following declaration *is* an executable statement. */ [20] int i = 0; [22] if (i > 0) { /* The next line is never executed. */ [U] [25] sub2(); [U] [26] } [U] [27] else { [28] sub3(); [29] } [30] } sub2() [U] [33] { /* do nothing */ [U] [35] } sub3() [38] { /* do same as sub2() */ [40] }

In any lprof output, certain lines (such as declarations, comments, and blank lines) do not have line numbers associated with them. This allows you to distinguish between lines that were not executed during a particular run from those that are not executable. In the previous example, neither line 24 nor line 25 in sub1 was executed, but line 25 is marked with a line number while line 24 is not. This is because line 24 is not executable; line 25 is executable but was not executed in the run that produced this output.


Next topic: Specifying program and data files to lprof
Previous topic: Interpreting profiling output

© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003