码迷,mamicode.com
首页 > 其他好文 > 详细

how to debug thread cpu 100%

时间:2014-11-18 00:11:38      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   ar   sp   for   div   on   log   

when we write a program, cpu and memory usages are very important to indicate the stability of the program. Once the cpu usage reached 90%, there are some bugs in your program, and you must find the problem. Here is a simply guide to debug with cpu 100%. For example:

void *first_routine (void * args)
{
    while(1)
    {
        int a = 1;
        usleep(1);
    }

    return NULL;
}

int main()
{
    pthread_t thread_first, thread_second;
    pthread_create(&thread_first, NULL, &first_routine, NULL);

    while(1)
    {
        sleep(4);
    }
    return 0;
}

then complile it : gcc debug.c -o debug -lpthread , and run it .  

iii) use top tool find the bug thread,  top -p $pid -H

iv) use pstack : pstack $tid(bug thread), to look the stack of the bug thread. but pstack can‘t see the paraments. if you still can‘t determine the bug line, user gcore to get the program core.  (gcore $pid)

v)  gdb -c  $core.file  ./exe , and the use  command  bt(back trace), then use the paraments to determine the bug code.

 

how to debug thread cpu 100%

标签:style   blog   color   ar   sp   for   div   on   log   

原文地址:http://www.cnblogs.com/memoryh/p/4104590.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!