Embedded how to locate dead loops or high CPU usage (Linux)

Source: Internet
Author: User
Tags cpu usage high cpu usage

How to locate a dead loop or high CPU usage (Linux)

determine if the CPU is too high

Use top to see if there is high CPU usage

Find a thread

Sort all threads for processes with high CPU usage

PS h-e-o pid,tid,pcpu,cmd--sort=pcpu |grep xxx Obtains the following results, where thread 2909 uses 7.8% of the cpu.2907 2913 0.0./xxx2907 2909 7.8./xxx can also be viewed/ The information in the proc to determine the high CPU thread. 4 columns printed, thread ID, thread name, user time and kernel time (not in the order of precedence) awk ' {print $1,$2,$14,$15} '/proc/2907/task/*/stat Find the call stack

Using the process of GDB attach nmsagent, use info threads in GDB to show all threads

GDB Gdb>attach 2907gdb>info Threads

You can find that the number of 2909 threads is 12, as shown below.

Thread 0xad5f2b70 (LWP 2908) 0x004ef0d7 in mq_timedreceive () from/lib/tls/i686/cmov/librt.so.112 thread 0xad58eb70 (L WP 2909) 0x006e0422 in __kernel_vsyscall () one thread 0xad52ab70 (LWP 2910) 0x006e0422 in __kernel_vsyscall () thread 0xa D4f8b70 (LWP 2911) 0x006e0422 in __kernel_vsyscall () 9 Thread 0xad4c6b70 (LWP 2912) 0x006e0422 in __kernel_vsyscall () 8 Th Read 0xad3feb70 (LWP 2913) 0x004ef0d7 in mq_timedreceive () from/lib/tls/i686/cmov/librt.so.17 Thread 0xace08b70 (LWP 291 4) 0x004ef0d7 in mq_timedreceive () from/lib/tls/i686/cmov/librt.so.16 Thread 0xac607b70 (LWP 2915) 0x006e0422 in __kerne L_vsyscall () 5 thread 0xac5e6b70 (LWP 2916) 0x006e0422 in __kernel_vsyscall () 4 Thread 0xac361b70 (LWP 2917) 0x006e0422 in __kernel_vsyscall () 3 thread 0xac2fdb70 (LWP 2918) 0x006e0422 in __kernel_vsyscall () 2 Thread 0xac1fcb70 (LWP 2919) 0x004 Ef0d7 in Mq_timedreceive () From/lib/tls/i686/cmov/librt.so.1* 1 Thread 0xb78496d0 (LWP 2907) 0x006e0422 in __kernel_vsys Call ()

Use thread to switch threads, use BT to display thread stacks

Gdb>thread GDB>BT

Get the following thread stack

#0 0x006e0422 in __kernel_vsyscall () #1 0x001cca26 in Nanosleep () from/lib/tls/i686/cmov/libc.so.6#2 0X001FC2DC in Uslee P () from/lib/tls/i686/cmov/libc.so.6#3 0x0806b510 in Osptaskdelay () #4 0x0805c710 in Cdispatchtask::nodemsgsendtosock ( ) () #5 0x0805cc74 in Dispatchtaskentry () #6 0x0806a8e9 in Osptasktemplatefunc (void*) () #7 0x00d4780e in Start_thread () fr Om/lib/tls/i686/cmov/libpthread.so.0#8 0x002027ee in Clone () from/lib/tls/i686/cmov/libc.so.6PS + strace Get process ID 21465 ps-e |grep CMU 4996? 00:00:25 cmu_fjga_sp3 21465 pts/5 00:08:10 CMU gets thread time, which accounts for the most CPU epollrecvtask 21581ps-el |grep 2146521465 21579 pts/5 00: 00:00 CamApp21465 21580 pts/5 00:00:00 timerman Task21465 21581 pts/5 00:09:02 EpollRecvTask21465 21582 pts/5 00:00:00 use s Trace-p 21581 getting thread stacks

Embedded how to locate dead loops or high CPU usage (Linux)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.