Perf profiling analysis program performance

Source: Internet
Author: User

Perf profiling analysis program performance
Perf profiling analysis program performance Program Performance Analysis

Perf collects call stacks of a program at a certain frequency and performs statistical analysis on the call stacks. If a code path appears more ordinary in the collection result, it means that the program consumes more time on the code path. In this way, we can quickly find the code path with the most frequent program calls.

Perf command

Perf record-F 99-p $ (pidof test1)-g -- sleep 300 this command is used to collect call stacks related to the test1 program. The sampling frequency is 99Hz, -g indicates that the call stack is printed, and -- sleep 30 indicates that the sampling time is 300 seconds.

Perf report-g -- stdio command is used to view the result

Example Analysis

To understand the role of this tool, I specially wrote a program for analysis.

#includeint functiona(void){    int c = 0;    int count = 0;    for(c = 1; c < 20000; c++)    {        count++;    }    return;}int functionb(void){    int c = 0;    int count = 0;    for(c = 1; c < 40000; c++)    {        count++;    }    return;}int main(int argc, char * argv[]){    for(;;)    {        functiona();        printf("call function a\n");        functionb();        printf("call function b\n");    }    return;}

Compile the command gcc-g-o test1 test1.c

Test process
  1. Test1>/de v/null &
  2. Perf record-F 99-p $ (pidof test1)-g -- sleep 300
  3. Perf script> out. perf
  4. ./Stackcollapse-perf.pl out. perf> out. folded
  5. ./Flamegraph. pl out. folded> out. svg
Test Result Analysis

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.