Linuxѧϰ ѰÕÒ³ÌÐòÈȵ㣨һ£©£ºgprof
gprof½éÉÜ
gprofÊÇGNU profiler¹¤¾ß£¬´æÔÚÓÚbinutils¹¤¾ß°ü¡£¿ÉÒÔÏÔʾ³ÌÐòÔËÐеēflat profile”£¬°üÀ¨Ã¿¸öº¯ÊýµÄµ÷ÓôÎÊý£¬Ã¿¸öº¯ÊýÏûºÄµÄ´¦ÀíÆ÷ʱ¼ä¡£Ò²¿ÉÒÔÏÔʾ“µ÷ÓÃͼ”£¬°üÀ¨º¯ÊýµÄµ÷ÓùØÏµ£¬Ã¿¸öº¯Êýµ÷Óû¨·ÑÁ˶àÉÙʱ¼ä¡£»¹¿ÉÒÔÏÔʾ“×¢Ê͵ÄÔ´´úÂ딣¬ÊdzÌÐòÔ´´úÂëµÄÒ»¸ö¸´±¾£¬±ê¼ÇÓгÌÐòÖÐÿÐдúÂëµÄÖ´ÐдÎÊý¡£
gprof ʵÏÖÔÀí£º
gprof²¢²»ÉñÆæ£¬ÔÚ±àÒëºÍÁ´½Ó³ÌÐòµÄʱ ºò£¨Ê¹Óà -pg ±àÒëºÍÁ´½ÓÑ¡Ï£¬gcc ÔÚÄãÓ¦ÓóÌÐòµÄÿ¸öº¯ÊýÖж¼¼ÓÈëÁËÒ»¸öÃûΪmcount£¨or“_mcount”, or“__mcount”£©µÄº¯Êý£¬Ò²¾ÍÊÇ˵-pg±àÒëµÄÓ¦ÓóÌÐòÀïµÄÿһ¸öº¯Êý¶¼»áµ÷ÓÃmcount, ¶ømcount»áÔÚÄÚ´æÖб£´æÒ»Õź¯Êýµ÷ÓÃͼ£¬²¢Í¨¹ýº¯Êýµ÷ÓöÑÕ»µÄÐÎʽ²éÕÒ×Óº¯ÊýºÍ¸¸º¯ÊýµÄµØÖ·¡£ÕâÕŵ÷ÓÃͼҲ±£´æÁËËùÓÐÓ뺯ÊýÏà¹ØµÄµ÷ÓÃʱ¼ä£¬µ÷ÓôÎÊýµÈµÈµÄËùÓÐÐÅÏ¢¡£
GPROFµÄ»ù±¾Ê¹Ó÷½·¨ÈçÏ£º
1£®Ê¹ÓÃGCC¼ÓÉÏ-pgÑ¡Ïî±àÒë³ÌÐò
2£®Ö´ÐгÌÐò£¬»áÉú³Égmon.out
3£®Ê¹ÓÃgprof·ÖÎögmon.outÎļþ£¬µÃ³öͳ¼Æ×ÊÁÏ
4£®GPROF²»Ö§³Ö¶¯Ì¬Á´½Ó¿âºÍ¶àÏß³Ì
·¶Àý£º
#include<stdio.h>
void funca()
{
int i = 0;
int n = 0;
for(i = 0;i < 10000000;i++)
{
n++;
n--;
}
}
void funcb()
{
int i = 0;
int n = 0;
for(i = 0;i < 10000000;i++)
{
n++;
n--;
}
}
int main(int argc,char *argv[])
{
int i = 0;
for(i = 0;i < 10;i++)
{
funca();
}
funcb();
return 0;
}
±àÒ룺
$ gcc hello.c -pg -o hello
ÔËÐУº
$ ./hello
Éú³Égmon.outÎʼþ
ʹÓÃgprof½øÐнâÎö£º
$ gprof hello gmon.out -p
Flat profile:
Each sample counts as 0.01 seconds.
%
Ïà¹ØÎĵµ£º
Ç°ÃæÀûÓÿª·¢°å´øµÄÏֳɵĶ«Î÷step by stepÈÃLinux 2.4.19ÔÚ¿ª·¢°åÉÏÅÜÆðÀ´ÁË£¬¶ÔÓÚ¿ª·¢µÄÁ÷³ÌÒ²ÓÐÁËÒ»¶¨µÄÈÏʶ¡£ÏÖÔÚÏë¶Ôÿһ²½½øÐÐÏêϸÉîÈëµÄ̽ÌÖ£¬ºÃºÃѧϰһÏ£¬°Ñ±Ê¼Ç¼Ç¼ÏÂÀ´£¬Ê¡µÃÍü¼ÇÁË¡£ÓÐЩÄÚÈÝÊÇ´Ó¿´¹ýµÄÊéÖÐÕªÒª¹ýÀ´µÄ£¬´ó²¿·ÖÊÇ×Ô¼ºÊµ¼ùºóµÄÐĵá£ÎÒÏë¼ÇµÃÏêϸµã£¬Ò²ºÃΪºóÃæ×ܽá´òºÃ»ù´¡¡£
------- ......
»¶Ó»Øµ½KernelÖÐ……
¼ÌÐøËµ__vet_atagsº¯Êý£¬Õâ¸öº¯ÊýÈԾɶ¨ÒåÔÚarch\arm\kernel\head-common.sÎļþÖУº
/* Determine validity of the r2 atags pointer. The heuristic requires
* that the pointer be aligned, in the first 16k of physical RAM and
* that the ATAG_CORE marker ......
<!--
/* Font Definitions */
@font-face
{font-family:ËÎÌå;
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-alt:SimSun;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
@font-face
{font-family:"\@ËÎÌå" ......
¼Ç¼ÔÚlinuxÏ¿ª·¢Óöµ½µÄ¸÷ÖÖÎÊÌ⣬·½±ãÒÔºó²éÕÒ¡£
1.¹ØÓÚshellÖнű¾µÄÖ´Ðз½Ê½£ºÔÚµ±Ç°½Å±¾Ö´Ðл¹ÊÇÆô¶¯Ò»¸öеÄshell½ø³ÌÀ´Ö´Ðнű¾¡£
¼ÙÉ赱ǰĿ¼ÏÂÓнű¾script.sh¡£
Æô¶¯Ò»¸öеÄshell½ø³ÌÀ´Ö´ÐУº
ÕâÊÇshellÖÐĬÈϵÄÖ´Ðз½Ê½ÊÇÆô¶¯Ò»¸öеÄshell½ø³Ì£¨×Ó½ø³Ì£©À´Ö´Ðнű¾£¬¼´sh script.sh»òÕ߸³Ó ......
×ªÔØ
£¨1£©ÈíÁ¬½Ó¿ÉÒÔ ¿çÎļþϵͳ £¬Ó²Á¬½Ó²»¿ÉÒÔ ¡£Êµ¼ùµÄ·½·¨¾ÍÊÇÓù²ÏíÎļþ°ÑwindowsÏ嵀 aa.txtÎı¾ÎĵµÁ¬½Óµ½linuxÏÂ/rootĿ¼ Ï bb,cc . ln -s aa.txt /root/bb Á¬½Ó³É¹¦ ¡£ln aa.txt /root/bb ʧ°Ü ¡£
£¨2£©¹ØÓÚ I½ÚµãµÄÎÊÌâ ¡£Ó²Á¬½Ó²»¹ÜÓжàÉÙ¸ö£¬¶¼Ö¸ÏòµÄÊÇͬһ¸öI½Úµã£¬»á°Ñ ½áµãÁ¬½ÓÊýÔö¼Ó £¬Ö»Òª½áµãµÄÁ¬½Ó ......