`

Analyzing thread CPU usage on Linux

 
阅读更多

原文地址:http://publib.boulder.ibm.com/infocenter/javasdk/tools/index.jsp?topic=%2Fcom.ibm.java.doc.igaa%2F_1vg0001475cb4a-1190e2e0f74-8000_1007.html

Use top to analyze the CPU usage of each application thread.

Introduction
To investigate the per-thread CPU usage on Linux, the recommended tool is top with the -H option, which provides an additional thread for information not provided by top in the default usage.
Understanding the top -H output
The output of top -H on Linux shows the breakdown of the CPU usage on the machine by individual threads. The top output has the following sections of interest:
 
  top - 16:15:45 up 21 days,  2:27,  3 users,  load   average: 17.94, 12.30, 5.52   
  Tasks: 150 total,  26 running, 124 sleeping,   0   stopped,   0 zombie   
  Cpu(s): 87.3% us,  1.2% sy,  0.0% ni, 27.6% id,  0.0%   wa,  0.0% hi,  0.0% si   
  Mem:   4039848k total,  3999776k used,   40072k free,    92824k buffers   
  Swap:  2097144k total,      224k used, 2096920k free,  1131652k cached   
 

The Cpus(s) row in this header section shows the CPU usage in terms of the following:

us
Percentage of CPU time spent in user space.
sy
Percentage of CPU time spent in kernel space.
ni
Percentage of CPU time spent on low priority processes.
id
Percentage of CPU time spent idle.
wa
Percentage of CPU time spent in wait (on disk).
hi
Percentage of CPU time spent handling hardware interrupts.
si
Percentage of CPU time spent handling software interrupts.

The "us", "sy" and "id" values are useful as the user, system (kernel) and idle CPU time respectively.

The next section shows the per-thread breakdown of the CPU usage.

 
    PID USER    PR  NI  VIRT  RES  SHR S %CPU   %MEM    TIME+  COMMAND   
  31253 user1   16   0 2112m 2.1g 1764 R 37.0   53.2   0:39.89 java   
  31249 user1   16   0 2112m 2.1g 1764 R 15.5   53.2   0:38.29 java   
  31244 user1   16   0 2112m 2.1g 1764 R 13.6   53.2   0:40.05 java   
  31250 user1   16   0 2112m 2.1g 1764 R 13.6   53.2   0:41.23 java   
  31242 user1   16   0 2112m 2.1g 1764 R 12.9   53.2   0:40.56 java   
  31238 user1   16   0 2112m 2.1g 1764 S 12.6   53.2   1:22.21 java   
  31246 user1   16   0 2112m 2.1g 1764 R 12.6   53.2   0:39.62 java   
  31248 user1   16   0 2112m 2.1g 1764 R 12.6   53.2   0:39.40 java   
  31258 user1   16   0 2112m 2.1g 1764 R 12.6   53.2   0:39.98 java   
  31264 user1   17   0 2112m 2.1g 1764 R 12.6   53.2   0:39.54 java   
  31243 user1   16   0 2112m 2.1g 1764 R 12.2   53.2   0:37.43 java   
  31245 user1   16   0 2112m 2.1g 1764 R 12.2   53.2   0:37.53 java   
  31255 user1   16   0 2112m 2.1g 1764 R 11.9   53.2   0:40.84 java   
  31265 user1   16   0 2112m 2.1g 1764 R 11.9   53.2   0:40.46 java   
  31239 user1   16   0 2112m 2.1g 1764 S 11.6   53.2   1:22.79 java   
  31254 user1   16   0 2112m 2.1g 1764 R 11.6   53.2   0:41.12 java   
  31266 user1   16   0 2112m 2.1g 1764 R 11.2   53.2   0:40.47 java   
  31261 user1   16   0 2112m 2.1g 1764 R 10.9   53.2   0:39.31 java   
  31262 user1   16   0 2112m 2.1g 1764 R 10.9   53.2   0:38.50 java   
  .. 
 

This provides the following information, some of which is for the whole process, and other inforamation relevant to the particular thread:

PID
The thread ID. This can be converted into hexadecimal and used to correlate to the "native ID" in a javacore.txt file.
USER
The user ID of the user that started the process.
PR
The priority of the thread.
NI
The "nice" value for the process.
VIRT
The virtual memory (allocated) usage of the process.
RES
The resident memory (committed) usage of the process.
SHR
The shared memory usage of the process.
S
The state of the thread. This can be one of the following:
R
Running
S
Sleeping
D
Uninterruptible sleep
T
Traced
Z
Zombie
%CPU
The percentage of a single CPU usage by the thread.
%MEM
The percentage of the memory used by the process.
TIME+
The amount of CPU time used by the thread.
COMMAND
The name of the process executable.

Note that the "Cpu(s)" line in the header of the output shows the percentage usage across all of the available CPUs, whereas the %CPU column represents the percentage usage of a single CPU. For example, on a four-CPU machine the Cpu(s) row will total 100% and the %CPU column will total 400%.

What to look for from the top -H output
In the per-thread breakdown of the CPU usage shown above, the Java process is taking approximately 75% of the CPU usage. This value is found by totalling the %CPU column for all the Java threads (not all threads are shown above) and dividing by the number of CPUs. The Java process is not limited by other processes, because the CPU there is still approximately 25% idle. You can also see that the CPU usage of the Java process is spread reasonably evenly over all of the threads in the Java process. This spread implies that no one thread has a particular problem. Although the application is allowed to use most of the available CPU, approximately 25% of the total CPU is idle meaning that some points of contention or delay in the Java process can be identified. A report indicating that active processes are using a small percentage of CPU, even though the machine appears idle, means that the performance of the application is probably limited by points of contention or process delay, preventing the application from scaling to use all of the available CPU. If a deadlock is present, the reported CPU usage for the Java process is low or zero. If threads are looping, the Java CPU usage approaches 100%, but a small number of the threads account for all of that CPU time. Where you have threads of interest, note the PID values because you can be convert them to a hexadecimal value and look up the threads in the javacore.txt file to discover if the thread is part of a thread pool. In this way you gain an understanding of the kind of work that the thread does from the thread stack trace in the javacore.txt file. For example, the PID 31253 becomes 7A15 in hexadecimal. This value maps to the "native ID" value in the javacore.txt file.

Use top to analyze the CPU usage of each application thread.

No CPU Usage 
No threads are using any CPU time.

Checking for looping code

Low CPU Usage 
CPU time is being used, but is not at 100% usage.

100% CPU Usage 
All of the available CPU time is being used.

分享到:
评论

相关推荐

    Java Thread Dump Analyzing

    Java Thread Dump Analyzing

    Analyzing_Social_Networks

    Designed to walk beginners through core aspects of collecting, visualizing, analyzing, and interpreting social network data, this book will get you up-to-speed on the theory and skills you need to ...

    Thread_Dump_Analyzing_Tool

    Thread_Dump_Analyzing_Tool通过解析这些转储文件,可以快速识别出可能导致问题的关键线程,从而帮助优化和调试应用程序。 这个项目"Thread_Dump_Analyzing_Tool-master"很可能是一个Git仓库的克隆,其中包含了源...

    Analyzing Neural Time Series Data图书

    This book delves deep into the theory and practice of analyzing neural time series data, particularly focusing on electroencephalography (EEG) and magnetoencephalography (MEG). It covers essential ...

    Baymax: A Mental-Analyzing Mobile App Based on Big Data.pdf

    《Baymax:基于大数据的心理分析移动应用》 随着现代社会生活节奏的加快,人们面临的心理问题日益增多,然而现有的心理健康解决方案,如寻求精神科医生的帮助,往往受到用户的抵触感和隐私顾虑。...

    Processing and Analyzing Financial Data with R

    Processing and Analyzing Financial Data with R by Marcelo S. Perlin English | 1 May 2017 | ASIN: B071DTSCPS | 516 Pages | AZW3 | 3.76 MB This book introduces the reader to the use of R and RStudio as...

    Analyzing Neural Time Series Data Theory and Practice

    "Analyzing Neural Time Series Data: Theory and Practice"这本书及其配套MATLAB代码提供了深入理解这一主题的宝贵资源。MATLAB是一种广泛使用的编程环境,特别适合处理和分析各种类型的数据,包括复杂的时间序列...

    Sybase Performance and Tunning:Monitoring and Analyzing

    - **sp_sysmon**:此命令提供了有关服务器活动的重要信息,如CPU使用率、内存使用情况等。 2. **外部监控工具**: - **Sybase Central**:Sybase Central是一款图形化管理工具,它提供了丰富的界面来查看和管理...

    Analyzing Business Data with Excel

    《Analyzing Business Data with Excel》是一本专注于使用微软Excel进行商业数据分析的著作。该书针对的是那些希望通过Excel的强大功能来挖掘、理解并呈现业务数据的专业人士。Excel是世界上最广泛使用的电子表格...

    Training and Analyzing Deep Recurrent Neural Networks

    focusing on training algorithms rather than on their basic architecture. In this pa- per we study the effect of a hierarchy of recurrent neural networks on processing time series. Here, each layer is ...

    StraceNT v0.8(strace on Windows)

    It provides similar functionality as of strace on Linux. It can trace all the calls made by a process to the imported functions from a DLL. StraceNT can be very useful in debugging and analyzing the...

    Analyzing and Comparing Montgomery Multiplication Algorithms

    “Analyzing and Comparing Montgomery Multiplication Algorithms”(分析与比较蒙哥马利模乘算法)这篇文章旨在深入探讨并对比不同的蒙哥马利模乘算法实现方法。蒙哥马利模乘算法是一种在计算机科学中广泛应用的...

    Multi-modal multimedia big data analyzing architecture and resource allocation on cloud platform

    多模态多媒体大数据分析架构及其在云平台上的资源分配是一项研究多特征分布式计算系统的新兴课题,这些系统包含文本、视觉和音频等多种模态。该研究在Neurocomputing253期上发表,由K.P.N.Jayasena、Lin Li和Qing ...

    Oracle Real World DBA Best Practice

    DBA Best Practices from real world experiences on Rman Backup Restore; Auditting, CPU usage analyzing, User activities and tracing.

    Analyzing Data with Power BI and Power Pivot for Excel

    《使用Power BI和Excel的Power Pivot分析数据》这本书是数据分析领域的一本重要著作,由Alberto Ferrari和Marco Russo合著,由微软出版社出版。该书详细介绍了如何使用Power BI和Power Pivot for Excel工具来构建和...

    Analyzing concerns of people from Weblog articles.pdf

    ### 分析网络日志文章中人们的关注点 #### 摘要与背景 本文提出了一种分析网络日志(Weblog)文章中人们关注点的系统——KANSHIN。该系统通过收集大量的日语、汉语及韩语的网络日志文章来分析不同语言社区的人们对...

Global site tag (gtag.js) - Google Analytics