Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

cc(1)

prof(1)

fork(2)

tmpnam(3S)



          LPROF(1)             INTERACTIVE UNIX System             LPROF(1)



          NAME
               lprof - display line-by-line execution count profile data

          SYNOPSIS
               lprof [-p] [-s] [-x] [[-I incdir]] [[-r srcfile]] [-c
               cntfile] [-o prog]
               lprof -m file1.cnt file2.cnt [[filen.cnt]] [-T] -d
               destfile.cnt

          DESCRIPTION
               lprof is a tool for dynamic analysis; that is, the analysis
               of a program at run time.  Specifically, lprof identifies
               the most frequently executed parts of source code and parts
               of code that are never executed.

               lprof interprets a profile file (prog.cnt by default) pro-
               duced by the profiled program prog (a.out by default) that
               has been compiled with the -ql option of cc(1).  This cc
               command option arranges for code to be inserted to record
               run-time behavior and for data to be written to a file at
               the end of execution.

               By default, lprof prints a listing of source files (the
               names of which are stored in the symbol table of the execut-
               able file), each line preceded by its line number (in the
               file) and the number of times it was executed.

               The following options may appear singly or be combined in
               any order:

               -p   Print listing, each line preceded by the line number
                    and the number of times it was executed (default).
                    This option can be used together with the -s option to
                    print both the source listing and summary information.

               -s   Print summary information of percentage of lines of
                    code executed per function.

               -x   Instead of printing the execution count numbers for
                    each line, print each line preceded by its line number
                    and a [U] if the line was not executed.  If the line
                    was executed, print only the line number.

               -I incdir
                    Look for source or header files in the directory incdir
                    in addition to the current directory and the standard
                    place for #include files (usually /usr/include).  You
                    can specify more than one directory with -I on one com-
                    mand line.

               -r srcfile
                    Instead of printing all source files, print only those
                    files named in -r options (to be used with the -p


          Rev. C Software Development Set                            Page 1





          LPROF(1)             INTERACTIVE UNIX System             LPROF(1)



                    option only).  You can specify multiple files with -r
                    on one command line.

               -c cntfile
                    Use the file cntfile instead of prog.cnt as the input
                    profile file.

               -o prog
                    Use the name of the program prog instead of the name
                    used when creating the profile file.  Because the pro-
                    gram name stored in the profile file contains the rela-
                    tive path, this option is necessary if the executable
                    file or profile file has been moved.

             Merging Data Files
               lprof can also be used to merge data files.  The -m option
               must be accompanied with the -d option:

               -m file1.cnt file2.cnt [filen.cnt] -d destfile.cnt
                    Merge the data files file1.cnt through filen.cnt by
                    summing the execution counts per line, so that data
                    from several runs can be accumulated.  The result is
                    written to destfile.cnt.  The data files must contain
                    profiling data for the same prog (see the -T option
                    below).

               -T   Time stamp override.  Normally, the time stamps of the
                    executable files being profiled are checked, and data
                    files will not be merged if the time stamps do not
                    match.  If -T is specified, this check is skipped.

             Controlling the Run Time Profiling Environment
               The environment variable PROFOPTS provides run time control
               over profiling.  When a profiled program is about to ter-
               minate, it examines the value of PROFOPTS to determine how
               the profiling data is to be handled.

               The environment variable PROFOPTS is a comma-separated list
               of options interpreted by the program being profiled.  If
               PROFOPTS is not defined in the environment, then the default
               action is taken:  the profiling data is saved in a file
               (with the default name, prog.cnt) in the current directory.
               If PROFOPTS is set to the null string, no profiling data is
               saved.  The following are the available options:

               msg=[y|n]
                    If msg=y is specified, a message stating that profile
                    data is being saved is printed to stderr.  If msg=n is
                    specified, print only profiling error messages.  The
                    default is msg=y.

               merge=[y|n]
                    If merge=n is specified, do not merge data files after


          Rev. C Software Development Set                            Page 2





          LPROF(1)             INTERACTIVE UNIX System             LPROF(1)



                    successive runs.  The data file is overwritten after
                    each execution.  If merge=y is specified, the data will
                    be merged.  The merge will fail if the program has been
                    recompiled; the data file will be left in TMPDIR.  The
                    default is merge=n.

               pid=[y|n]
                    If pid=y is specified, the name of the data file will
                    include the process ID of the profiled program.  This
                    allows the creation of different data files for pro-
                    grams calling fork(2).  If pid=n is specified, the
                    default name is used.  The default is pid=n.

               dir=dirname
                    Place the data file in the directory dirname if this
                    option is specified.  Otherwise, the data file is
                    created in the directory that is current at the end of
                    execution.

               file=filename
                    Use filename as the name of the data file in dir
                    created by the profiled program if this option is
                    specified.  Otherwise, the default name is used.

          FILES
               prog.cnt    for profile data
               TMPDIR/*    temporary files

               TMPDIR is usually /usr/tmp, but can be redefined by setting
               the environment variable TMPDIR [see tempnam() in
               tmpnam(3S)].

          SEE ALSO
               cc(1), prof(1), fork(2), tmpnam(3S).

          WARNINGS
               For the -m option, if destfile.cnt exists, its previous con-
               tents are destroyed.

               Optimizing functions may result in the loss of some line
               number information and may result in code motions, both of
               which may make lprof information unreliable.

               Different parts of one line of a source file may be executed
               different numbers of times (e.g., the for loop below); the
               count corresponds to the first part of the line.  For exam-
               ple, in the following for loop
                    1 [8]  for (j = 0; j < 5; j++)
                    5 [9]     sub(j);
               line 8 consists of three parts.  The line count listed, how-
               ever, is for the initialization part, i.e., j = 0.

               lprof incorrectly handles the statement immediately


          Rev. C Software Development Set                            Page 3





          LPROF(1)             INTERACTIVE UNIX System             LPROF(1)



               following a for loop containing a single if statement.  In
               the following example, line 8 is executed only once.
                    1 [5]  for (i = 0; i < 3; i++)
                    3 [6]     if (i > 3)
                    0 [7]        x = i;
                    3 [8]  i = 0;
               This problem can be solved by adding curly braces, as fol-
               lows:
                    1 [5]  for (i = 0; i < 3; i++) {
                    3 [6]     if (i > 3)
                    0 [7]        x = i;
                    3 [8]  }
                    1 [9]  i = 0;
               lprof then handles the statement following the for loop
               correctly.

               lprof does not provide execution information about case
               statements containing only a break statement, or about
               return statements without a value.
                    1 [4]  switch (i) {
                              case 0:
                                break;
                              default:
                    0 [8]       i = 0;
                           }
                    1 [11] if (i != 0)
                              return;




























          Rev. C Software Development Set                            Page 4



Typewritten Software • bear@typewritten.org • Edmonds, WA 98026