Performance query command under linux

  
        

(1) View the usage of each CPU core

sudo top -d 1

After entering, press 1, the following CPU usage will appear, where the us column reflects each The use of the CPU core, a large percentage indicates that the core is in a tight task.


(2) See which process is running on which CPU core

sudo top -d 1

After entering, press f, j and Spaces, will appear as follows (where the P column indicates the most recently used CPU core of the process, such as the P column of the process mencoder is 7, it means that the mencoder has recently run on the core 7, for multi-threaded or even single-threaded processes, different Different CPU Cores will be used at all times:


(3) vmstat to view overall CPU usage

sudo vmstat 2 3

Parameter 2 indicates The result is displayed every 2 seconds, and 3 indicates the number of results displayed.


The cs column indicates the number of context switches per second, and us indicates the user CPU time.

(4) Intel Tools powertop

sudo powertop

will show the percentage of use of each CPU core.

(5) gprof analyzes a program

Suppose the program source file is speedup-example.cpp

gcc speedup-example.cpp -o speedup-example -pg (note -pg)

Executing the program ./speedup-example will generate gmon.out in the current directory. This file is the source of our view of the program, and then use the gprof command to view it:

gprof -b speedup-example gmon.out > Results.txt

The running information for this program is in Results.txt.


(6) pidstat real-time view of a process's CPU usage and context switching

First install

sudo apt-get install sysstat

Next, use pidstat (the following -p is used in conjunction with the process number to display performance information for a particular process, and can be specified to display every few seconds, for a total of a few):
pidstat 5 - p 15488 (the pid of the process you want to track)

This will display the CPU usage of the 15488 process in real time:


pidstat -w —— show each process Context switch case pidstat -w -p 15488 2 —— Displays the context switch status of the 15488 process every 2 seconds: cswch/s —— The total number of volume context switches generated by the process per second. The voluntary context switches appear to access an already occupied resource and thus have to hang (ie, we usually say Synchronization Context Switches). nvcswch/s —— The total number of involuntary context switches generated by the process per second. Involuntary context switches occur when their own time slice runs out or is preempted by a higher priority (including Preemption Context Switches)

Copyright © Windows knowledge All Rights Reserved