DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Analyzing run-time behavior

Profiling C++ programs with lprof

As mentioned previously, the C++ compiler also accepts the -ql option to generate a profiled executable.

When producing a source listing using lprof, all symbol names will appear as they are in the C++ source program, that is in their unencoded form. However, when producing a summary report, lprof will print the symbol name as it appears in the program's symbol name, that is, in its encoded form produced by the C++ compiler. To obtain decoded symbol names for a summary report, the -C option to lprof should be used.

Using a C++ program similar to overload.C that was described in ``C and C++ compilation system'', a sample session to compile, run and obtain line profiling information would be as follows:

   #include <stdio.h>
   

void foo(void) { printf("in foo(void)\n"); }

void foo(int i) { printf("in foo(int i), i = %d\n", i); }

void foo(const char *s){ printf("in foo(const char *s), s = %s\n", s); }

main() { int i = 1; const char * pchar = ("string....."); foo(); foo(i); foo(pchar); foo(pchar); } $ CC -ql -o overload2 overload2.C $ overload2

in foo(void) in foo(int i), i = 1 in foo(const char *s), s = string..... in foo(const char *s), s = string..... INFO: Dumping profiling data from process 'overload2' . . . INFO: CNTFILE `overload2.cnt' created

Now run lprof to obtain a source listing:
   

$ lprof -c overload2.cnt

SOURCE FILE: overload2.C

#include <stdio.h> void foo(void) 1 [4] { 1 [5] printf("in foo(void)\n"); 1 [6] } void foo(int i) 1 [9] { 1 [10] printf("in foo(int i), i = %d\n", i); 1 [11] } 2 [13] void foo(const char *s){ 2 [14] printf("in foo(const char *s), s = %s\n", s); 2 [15] } main() 1 [18] { int i = 1; 1 [19] const char * pchar = ("string....."); 1 [20] foo(); 1 [21] foo(i); 1 [22] foo(pchar); 1 [23] foo(pchar); 1 [24] }

If you obtain a summary listing using the -s option without also specifying -C, the symbol names will be displayed in their mangled form:
   $ lprof -c overload2.cnt -s
   

Coverage Data Source: overload2.cnt Date of Coverage Data Source: Thu Apr 28 10:49:08 1994 Object: ./overload2

percent lines total function covered covered lines name

100.0 3 3 foo__FPCc 100.0 3 3 foo__Fi 100.0 3 3 foo__Fv 100.0 7 7 main

100.0 16 16 TOTAL

Using the -C option causes the symbol names to appear in a format that resembles the function definitions in the source file.

   $ lprof -c overload2.cnt -s -C
   Coverage Data Source: overload2.cnt
   Date of Coverage Data Source: Thu Apr 28 10:49:08 1994
   Object: ./overload2
   

percent lines total function covered covered lines name

100.0 3 3 foo(const char*) 100.0 3 3 foo(int) 100.0 3 3 foo(void) 100.0 7 7 main


Next topic: Technical tips
Previous topic: Profiling archive or shared object library code with lprof

© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 27 April 2004