MAN.9FRONT.ORG RTFM


     PROF(1)                                                   PROF(1)

     NAME
          prof, tprof, kprof - display profiling data

     SYNOPSIS
          prof [ -dr ] program profile

          flambe program profile

          tprof pid

          kprof kernel kpdata

     DESCRIPTION
          Prof interprets files produced automatically by programs
          loaded using the -p option of 2l(1) or other loader.  The
          symbol table in the named program file is read and corre-
          lated with the profile file.  For each symbol, the percent-
          age of time (in seconds) spent executing between that symbol
          and the next is printed (in decreasing order), together with
          the time spent there and the number of times that routine
          was called.

          Under option -d, prof prints the dynamic call graph of the
          target program, annotating the calls with the time spent in
          each routine and those it calls, recursively.  The output is
          indented two spaces for each call, and is formatted as

               symbol:time/ncall

          where symbol is the entry point of the call, time is in sec-
          onds, and ncall is the number of times that entry point was
          called at that point in the call graph.  If ncall is one,
          the /ncall is elided.  Normally recursive calls are com-
          pressed to keep the output brief; option -r prints the full
          call graph.

          The size of the buffer in program used to hold the profiling
          data, by default 256k entries, may be controlled by setting
          the environment variable profsize before running program. If
          the buffer fills, subsequent function calls may not be
          recorded.

          The profiling code provided by the linker initializes itself
          to profile the current pid, producing a file called
          prof.pid. If a process forks, only the parent will continue
          to be profiled.  Forked children can cause themselves to be
          profile by calling

               prof(fn, arg, entries, what)

     PROF(1)                                                   PROF(1)

          which causes the function fn(arg) to be profiled.  When fn
          returns prof.pid is produced for the current process pid.

          The environment variable proftype can be set to one of user,
          kernel, elapsed, or sample, to profile time measured spent
          in user mode, time spent in user+kernel mode, or elapsed
          time, using the cycle counter, or the time in user mode
          using the kernel's HZ clock.  The cycle counter is currently
          only available on modern PCs and on the PowerPC.  Default
          profiling measures user time, using the cycle counter if it
          is available.

          Flambe presents an interactive flame graph using information
          gathered by prof. The graph is presented as a series of
          rows, each row representing a level in the call stack.  Each
          row is split up among all the siblings of the respective
          call stack level, their width representative of the portion
          of their parent's time they occupied.  Hovering the mouse
          over any block shows its full name, the total time spent in
          the function, and the number of calls made to it in the top
          left hand side of the window.  Clicking a block reroots the
          the graph with the selected block as the base.  The escape
          key can be used to return to the real root of the graph.

          Tprof is similar to prof, but is intended for profiling mul-
          tiprocess programs.  It uses the /proc/pid/profile file to
          collect instruction frequency counts for the text image
          associated with the process, for all processes that share
          that text.  It must be run while the program is still
          active, since the data is stored with the running program.
          To enable tprof profiling for a given process,

               echo profile > /proc/pid/ctl

          and then, after the program has run for a while, execute

               tprof pid

          Since the data collected for tprof is based on interrupt-
          time sampling of the program counter, tprof has no -d or -r
          options.

          Kprof is similar to prof, but presents the data accumulated
          by the kernel profiling device, kprof(3).  The symbol table
          file, that of the operating system kernel, and the data
          file, typically /dev/kpdata, must be provided.  Kprof has no
          options and cannot present dynamic data.

     SOURCE
          /sys/src/cmd/prof.c
          /sys/src/cmd/kprof.c

     PROF(1)                                                   PROF(1)

     SEE ALSO
          2l(1), exec(2), kprof(3)