Sun Studio 12: Performance Analyzer

Running the er_kernel Utility

You can run the er_kernel utility to profile only the kernel or both the kernel and the load you are running. For a complete description of the er_kernel command, see the er_kernel (1) man page.

ProcedureProfiling the Kernel

  1. Collect the experiment by typing:


    % er_kernel -p on
    
  2. Run whatever load you want in a separate shell.

  3. When the load completes, terminate the er_kernel utility by typing Ctrl-C.

  4. Load the resulting experiment, named ktest.1.er by default, into the Performance Analyzer or the er_print utility.

    Kernel clock profiling produces one performance metric, labeled KCPU Cycles. In the Performance Analyzer, it is shown for kernel functions in the Functions Tab, for callers and callees in the Caller-Callee Tab, and for instructions in the Disassembly Tab. The Source Tab does not show data, because kernel modules, as shipped, do not usually contain file and line symbol table information (stabs).

    You can replace the -p on argument to the er_kernel utility with -p high for high-resolution profiling or -p low for low-resolution profiling. If you expect the run of the load to take 2 to 20 minutes, the default clock profiling is appropriate. If you expect the run to take less than 2 minutes, use -p high; if you expect the run to take longer than 20 minutes, use -p low.

    You can add a -t duration argument, which will cause the er_kernel utility to terminate itself according to the time specified by duration.

    The -t duration can be specified as a single number, with an optional m or s suffix, to indicate the time in minutes or seconds at which the experiment should be terminated. By default, the duration is in seconds. The duration can also be specified as two such numbers separated by a hyphen, which causes data collection to pause until the first time elapses, and at that time data collection begins. When the second time is reached, data collection terminates. If the second number is a zero, data will be collected after the initial pause until the end of the program's run. Even if the experiment is terminated, the target process is allowed to run to completion.

    You can add the -v argument if you want more information about the run printed to the screen. The -n argument lets you see a preview of the experiment that would be recorded, without actually recording anything.

    By default, the experiment generated by the er_kernel utility is named ktest.1.er; the number is incremented for successive runs.

ProcedureProfiling Under Load

If you have a single command, either a program or a script, that you wish to use as a load:

  1. Collect the experiment by typing:


    % er_kernel -p on load
    
  2. Analyze the experiment by typing:


    % analyzer ktest.1.er
    

    The er_kernel utility forks a child process and pauses for a quiet period, and then the child process runs the specified load. When the load terminates, the er_kernel utility pauses again for a quiet period and then exits. The experiment shows the behavior of the Solaris OS during the running of the load, and during the quiet periods before and after. You can specify the duration of the quiet period in seconds with the -q argument to the er_kernel command.

ProcedureProfiling the Kernel and Load Together

If you have a single program that you wish to use as a load, and you are interested in seeing its profile in conjunction with the kernel profile:

  1. Collect both a kernel profile and a user profile by typing both the er_kernel command and the collect command:


    % er_kernel collect load
    
  2. Analyze the two profiles together by typing:


    % analyzer ktest.1.er test.1.er
    

    The data displayed by the Analyzer shows both the kernel profile from ktest.1.er and the user profile from test.1.er. The timeline allows you to see correlations between the two experiments.


    Note –

    To use a script as the load, and profile the various parts of it, prepend the collect, command, with the appropriate arguments, to the various commands within the script.


Profiling a Specific Process or Kernel Thread

You can invoke the er_kernel utility with one or more -T arguments to specify profiling for specific processes or threads:

The target threads must have been created before you invoke the er_kernel utility for them.

When you give one or more -T arguments, an additional metric, labeled Kthr Time, is produced. Data is captured for all profiled threads, whether running on a CPU or not. Special single-frame call stacks are used for indicating the process is suspended (the function <SLEEPING>) or waiting for the CPU (the function <STALLED >).

Functions with high Kthr Time metrics, but low KCPU Cycles metrics, are functions that are spending a lot of time for the profiled threads waiting for some other events.