关于linux的进程中的各个线程cpu占用情况进行分析和查看
CPU是电脑的重要组成部分,是不可缺少的角色。下面是小编带来的关于关于linux的进程中的各个线程cpu占用情况进行分析和查看的内容,欢迎阅读!
关于linux的进程中的各个线程cpu占用情况进行分析和查看:
我们经常会在新开的服搭建一个游戏的服务器,有时候要进行压力测试,那么如何来看呢,一般我们会通过top命令查看各个进程的cpu和内存占用情况,获得到了我们的进程id,然后我们也许会通过pstack命令查看里边的各个线程id以及对应的线程现在正在做什么事情,分析多组数据就可以获得哪些线程里有慢操作影响了服务器的性能,从而得到解决方案。比如这样的以组数据:
[root@AY130816144542124256Z bin]# pstack 30222
Thread 9 (Thread 0x7f729adc1700 (LWP 30251)):
#0 0x00007f72a429b720 in sem_wait () from /lib64/libpthread.so.0
#1 0x0000000000ac5eb6 in Semaphore::down() ()
#2 0x0000000000ac5cac in Queue::get() ()
#3 0x00000000009a583f in DBManager::processUpdate(Queue*) ()
#4 0x00000000009a4bfb in dbUpdateThread(void*) ()
#5 0x00007f72a4295851 in start_thread () from /lib64/libpthread.so.0
#6 0x00007f72a459267d in clone () from /lib64/libc.so.6
Thread 8 (Thread 0x7f727c579700 (LWP 30252)):
#0 0x00007f72a429b720 in sem_wait () from /lib64/libpthread.so.0
#1 0x0000000000ac5eb6 in Semaphore::down() ()
#2 0x0000000000ac5cac in Queue::get() ()
#3 0x00000000009a5799 in DBManager::processQuery(Queue*) ()
#4 0x00000000009a4c3a in dbQueryThread(void*) ()
#5 0x00007f72a4295851 in start_thread () from /lib64/libpthread.so.0
#6 0x00007f72a459267d in clone () from /lib64/libc.so.6
Thread 7 (Thread 0x7f7257fff700 (LWP 30253)):
#0 0x00007f72a42997bb in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
#1 0x00007f72a549ee08 in utils::thread::condition_impl::timed_wait(int) () from /usr/local/utils-0.0.1/lib/libutils.so.0.0.1
#2 0x00007f72a549ebd3 in utils::thread::Condition::timed_wait(int) () from /usr/local/utils-0.0.1/lib/libutils.so.0.0.1
#3 0x00000000009d5f57 in utils::MessageQueue::pop() ()
#4 0x00000000009d5557 in FightReport::svc() ()
#5 0x00007f72a5494b45 in utils::Task_Base::thread_proc(void*) () from /usr/local/utils-0.0.1/lib/libutils.so.0.0.1
#6 0x00007f72a4295851 in start_thread () from /lib64/libpthread.so.0
#7 0x00007f72a459267d in clone () from /lib64/libc.so.6
Thread 6 (Thread 0x7f72397b7700 (LWP 30254)):
#0 0x00007f72a4588fc3 in poll () from /lib64/libc.so.6
#1 0x00007f72a0fbded4 in __libc_res_nsend () from /lib64/libresolv.so.2
#2 0x00007f72a0fba76a in __libc_res_nquery () from /lib64/libresolv.so.2
#3 0x00007f72a0fbad29 in __libc_res_nquerydomain () from /lib64/libresolv.so.2
#4 0x00007f72a0fbb9cf in __libc_res_nsearch () from /lib64/libresolv.so.2
#5 0x00007f729adc37a7 in _nss_dns_gethostbyname4_r () from /lib64/libnss_dns.so.2
#6 0x00007f72a457a4c3 in gaih_inet () from /lib64/libc.so.6
#7 0x00007f72a457cb20 in getaddrinfo () from /lib64/libc.so.6
#8 0x00007f72a56fc782 in Curl_getaddrinfo_ex () from /usr/lib64/libcurl.so.4
#9 0x00007f72a56f1d42 in Curl_getaddrinfo () from /usr/lib64/libcurl.so.4
#10 0x00007f72a56c9e77 in Curl_resolv () from /usr/lib64/libcurl.so.4
#11 0x00007f72a56ca138 in Curl_resolv_timeout () from /usr/lib64/libcurl.so.4
#12 0x00007f72a56d8d88 in ?? () from /usr/lib64/libcurl.so.4
#13 0x00007f72a56ddb79 in ?? () from /usr/lib64/libcurl.so.4
#14 0x00007f72a56de76e in Curl_connect () from /usr/lib64/libcurl.so.4
#15 0x00007f72a56e69b0 in Curl_perform () from /usr/lib64/libcurl.so.4
#16 0x0000000000ae6e3d in HttpClient::svc() ()
#17 0x00007f72a5494b45 in utils::Task_Base::thread_proc(void*) () from /usr/local/utils-0.0.1/lib/libutils.so.0.0.1
#18 0x00007f72a4295851 in start_thread () from /lib64/libpthread.so.0
#19 0x00007f72a459267d in clone () from /lib64/libc.so.6
Thread 5 (Thread 0x7f721af6f700 (LWP 30255)):
#0 0x00007f72a455691d in nanosleep () from /lib64/libc.so.6
#1 0x000000000098cb8a in Sleep(unsigned long) ()
#2 0x000000000098b87d in DynResource::svc() ()
#3 0x00007f72a5494b45 in utils::Task_Base::thread_proc(void*) () from /usr/local/utils-0.0.1/lib/libutils.so.0.0.1
#4 0x00007f72a4295851 in start_thread () from /lib64/libpthread.so.0
#5 0x00007f72a459267d in clone () from /lib64/libc.so.6
Thread 4 (Thread 0x7f71fc727700 (LWP 30256)):
#0 0x00007f72a455691d in nanosleep () from /lib64/libc.so.6
#1 0x000000000098cb8a in Sleep(unsigned long) ()
#2 0x0000000000a61516 in PlayerOpLogThread::svc() ()
#3 0x00007f72a5494b45 in utils::Task_Base::thread_proc(void*) () from /usr/local/utils-0.0.1/lib/libutils.so.0.0.1
#4 0x00007f72a4295851 in start_thread () from /lib64/libpthread.so.0
#5 0x00007f72a459267d in clone () from /lib64/libc.so.6
Thread 3 (Thread 0x7f71ddedf700 (LWP 30257)):
#0 0x00007f72a4592c73 in epoll_wait () from /lib64/libc.so.6
#1 0x00007f72a51f334f in Epoll_Reactor::run_reactor_event_loop() () from /usr/local/net_manager-0.0.2/lib/libnet_manager.so.0.0.2
#2 0x00007f72a51f2523 in Net_Thread::svc() () from /usr/local/net_manager-0.0.2/lib/libnet_manager.so.0.0.2
#3 0x00007f72a5494b45 in utils::Task_Base::thread_proc(void*) () from /usr/local/utils-0.0.1/lib/libutils.so.0.0.1
#4 0x00007f72a4295851 in start_thread () from /lib64/libpthread.so.0
#5 0x00007f72a459267d in clone () from /lib64/libc.so.6
Thread 2 (Thread 0x7f71bf697700 (LWP 30258)):
#0 0x00007f72a4592c73 in epoll_wait () from /lib64/libc.so.6
#1 0x00007f72a51f334f in Epoll_Reactor::run_reactor_event_loop() () from /usr/local/net_manager-0.0.2/lib/libnet_manager.so.0.0.2
#2 0x00007f72a51f2523 in Net_Thread::svc() () from /usr/local/net_manager-0.0.2/lib/libnet_manager.so.0.0.2
#3 0x00007f72a5494b45 in utils::Task_Base::thread_proc(void*) () from /usr/local/utils-0.0.1/lib/libutils.so.0.0.1
#4 0x00007f72a4295851 in start_thread () from /lib64/libpthread.so.0
#5 0x00007f72a459267d in clone () from /lib64/libc.so.6
Thread 1 (Thread 0x7f72a60ae7e0 (LWP 30222)):
#0 0x00007f72a4584c95 in _xstat () from /lib64/libc.so.6
#1 0x00007f72a45483e0 in __tzfile_read () from /lib64/libc.so.6
#2 0x00007f72a4547864 in tzset_internal () from /lib64/libc.so.6
#3 0x00007f72a4547b20 in tzset () from /lib64/libc.so.6
#4 0x00007f72a4546699 in timelocal () from /lib64/libc.so.6
#5 0x0000000000b0b08d in Achieve::GetRemainTime(AchieveTemplate*) ()
#6 0x0000000000b115ca in Achieve::update() ()
#7 0x0000000000a197ce in Player::update() ()
#8 0x0000000000b1b272 in PlayerMng::Tick() ()
#9 0x0000000000a73105 in GameServer::FrameTick(unsigned int) ()
#10 0x0000000000a6ff80 in GameServer::run() ()
#11 0x0000000000a773a1 in main ()
[root@AY130816144542124256Z gameserver]# ps -eLo pid,lwp,pcpu | grep 30222
30222 30222 31.4
30222 30251 0.0
30222 30252 0.0
30222 30253 0.0
30222 30254 0.0
30222 30255 0.0
30222 30256 1.2
30222 30257 1.2
30222 30258 1.0
多组数据显示表明我们的主逻辑线程的确占用的cpu很高,发现其实在Achieve::update() 的时候做了太多没有用的判断,并且可以减少循环进入的次数的,所以我在这里进行了优化
后来用了一下iptraf命令查
关于linux的进程中的各个线程cpu占用情况进行分析和查看的评论条评论