如何诊断在linux中咀嚼CPU的python进程 [英] How to diagnose a python process chewing CPU in linux

查看:180
本文介绍了如何诊断在linux中咀嚼CPU的python进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的python进程在自动化脚本中的特定位置开始咀嚼基于Linux的System(Ubuntu)上的CPU。
我试图在GDB中调试这个问题。我对GDB相当陌生。
是否有任何GDB命令可以提供哪些线程正在使用大部分cpu的信息。
看着线程堆栈并没有真正放弃。



在windows windbg世界中,命令'!runaway'确实给出了进程中每个线程所消耗的时间信息。
我们在这里有相同的命令吗?
任何其他的调试问题建议?

解决方案

只是澄清诊断此问题所需的所有步骤。 (感谢所有人发帖):



以下命令用CPU /内存使用情况显示进程列表:


ps auxf


以下命令给出了按CPU使用排序的进程的所有线程的列表。


top -H -p [PID]

PID USER PR NI VIRT RES SHR S%CPU%MEM TIME + COMMAND

1654根20 0 1416m 1.2g 24m t 100 36.8 21:26.23 python

1687根20 0 1416m 1.2g 24m t 0 36.8 0:05.07 python
blockquote>

线程 1654 正在咀嚼CPU。将gdb附加到进程中
$ b


gdb / path / of / process [pid]


使用gdb中的命令获取线程列表


(gdb)info threads



线程0xa7bffb40(LWP 20736)python0xb7736424 in __kernel_vsyscall()

1线程0xb73a56c0(LWP 1654在gdb中的__kernel_vsyscall()中使用python0xb7736424

切换到线程以检查其堆栈。


(gdb)线程1



(gdb)bt



My python process at certain point in automated scripts starts chewing CPU on Linux based System (Ubuntu). I’m trying to debug this issue in GDB. I'm fairly new to GDB. Are there any GDB commands to give information on which thread is using most of the cpu. Looking at the thread stack doesn't really give that away.

On windows windbg world the command '!runaway' did give the info on time consumed by each thread in a process. Do we've an equivalent command here ? Any other suggestions to debug issue ?

解决方案

Just to clarify all the steps required to diagnose this issue. (thanks everyone for postings) :

Following command shows the list of process with their CPU / Memory usage :

ps auxf

Following command gives the list of all threads of a process sorted with CPU usage.

top -H -p [PID]

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND

1654 root 20 0 1416m 1.2g 24m t 100 36.8 21:26.23 python

1687 root 20 0 1416m 1.2g 24m t 0 36.8 0:05.07 python

Thread 1654 is chewing CPU. Attach gdb to the process

gdb /path/of/process [pid]

Following command in gdb to get list of threads

(gdb) info threads

2 Thread 0xa7bffb40 (LWP 20736) "python" 0xb7736424 in __kernel_vsyscall ()

1 Thread 0xb73a56c0 (LWP 1654) "python" 0xb7736424 in __kernel_vsyscall ()

in gdb switch to the thread to check its stack.

(gdb) thread 1

(gdb) bt

这篇关于如何诊断在linux中咀嚼CPU的python进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆