Using the top Method

The following procedure summarizes the steps for using the top method:

  1. Run the top tool with the specified options to measure the CPU utilization.

    For example,

    #!/bin/bash
     
    # -b (batch mode): useful for sending top output to a file. Allows top to execute for the given iteration count and then exit
    # -d <duration>: run for <duration> seconds
    # -n 2: capture two snapshots (in the given duration)
    # -H: collect thread level stats.
    # -i: hide idle processes
    # -w 200: Set line width to 200; to get non-truncated thread names
     
    top -b -i -d <duration> -n 2 -H -w 200 &> top_output.txt &
  2. Run the workload.

    Note: See the Guidelines section for considerations regarding running the workload.
  3. Collect another report for an idle system using the same top command.
  4. View the files containing the output of the top command to see the CPU utilization for the idle system and with workload.
    1. To determine the overall CPU utilization from the top output, use the second occurrence of the line that starts with %Cpu(s) as follows:

    2. The following three values are the important numbers for measuring CPU utilization:

      • %Cpu(s): 0.4 us, 0.1 sy, 0.0 ni, 99.6 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
        us – %User time, sy – %Sys time, id – %Idle time
      • Total CPU utilization to be derived from %idle time by subtracting it from 100. This is the percentage of the total system.
      • Get the CPU utilization in terms of percentage of cores by multiplying the preceding value with the number of cores in the system. For example,

        CPU util: (100 - 99.6) * 11 = 4.4%  (assuming 11 cores in the system)