首页 > 其他 > 详细

how to debug thread cpu 100%

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

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%

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!