"The Ultimate Guide to CPU Analysis: Boosting Efficiency and Troubleshooting Performance"
In the world of system performance, understanding how the CPU behaves is crucial for identifying bottlenecks, optimising resource usage, and ensuring smooth operation of applications and services. Linux provides a range of powerful tools for analysing CPU performance, each with unique capabilities. This guide will explore key tools and techniques for CPU analysis on Linux
Generating CPU load is a crucial step in performance testing and analysis. It allows you to simulate high load conditions and observe how your system behaves under stress. Here’s a step-by-step guide on how to generate CPU load using a buggy application, a CPU simulator, and the sysbench tool.
Generating CPU Load
1. Using a Buggy Application (Ycrash)
Ycrash is an example of a buggy application that can be used to generate CPU load. While it is not a real-world tool for load generation, we'll simulate its use as a placeholder. If you have a specific application in mind that is known to cause high CPU usage, you can use that instead.
Install or Compile Ycrash: Assuming Ycrash is a dummy application for the example, ensure it’s available for your system. If you don't have a real application, you can use other methods to simulate load.
2. Using a CPU Simulator
A CPU simulator or stress test tool is designed to generate a controlled amount of CPU load. One popular tool for this purpose is stress or stress-ng.
Install stress:
sudo apt-get install stress
Run stress to Generate CPU Load:
stress --cpu 4 --timeout 60s
Alternatively, use stress-ng:
sudo apt-get install stress-ng stress-ng --cpu 4 --timeout 60s
3. Using sysbench Tool
sysbench is a versatile benchmarking tool that can generate CPU load and perform various performance tests.
Install sysbench:
sudo apt-get install sysbench
Generate CPU Load Using sysbench:
sysbench cpu --cpu-max-prime=20000 run
Below are list of tool which helps to analyse CPU usage & find out bottleneck . We are delivering CPU analysis in 3 part
Part 1:
Part 2 :
Part 3:
BCC tools
领英推荐
uptime
top
From the above top output we can see that java process is consuming 300% CPU . This is combination of all 4 CPU available on the system
top -H
With top -H we can find out which specific thread are consuming how much CPU . From above snapshot, java process has almost 20 threads and out of that those mentioned 4 threads are consuming very high CPU
htop
htop is advanced utility which is give combine information of uptime + top + top - H + individual CPU utilisation
htop with filter & tree:
vmstat
from top & htop , we are sure that which process is consuming CPU , now we want to confirm that that CPU utilisation is from user level or system level.
from vmstat observation , we can confirm that here CPU utilisation is from user level and not from system level so later we have to troubleshoot application code
mpstat
from mpstat , we can confirm that out of 4 CPU which CPU is used java process is utilising. here all 4 CPU are being utilised by java
pidstat
At least from above observation , we are sure that which process , thread , how many CPU are responsible for high CPU utilisation
CPU utilisation is happening at user level not at system level
Next challenge is to find out where exactly CPU consumption is happening with Perf tool
Reference: