Google Open source C + + Performance analysis tool-Gperftools

Source: Internet
Author: User

Gperftools is a set of tools provided by Google, one of which is CPU Profiler, used to analyze program performance and find program performance bottlenecks.installationgperftools:http://code.google.com/p/gperftools/downloads/listlibunwind:http://download.savannah.gnu.org/ RELEASES/LIBUNWIND/64-bit operating system needs to install Libunwind, the official recommended version is the Libunwind-0.99-beta installation process:./configure [--disable-shared] && Make && make Installgraphviz is an open source toolkit launched by the T lab to draw graphs of the dot language script description, Gperftools relies on this tool to generate graphical analysis results. Install command: Yum install Graphviz1. Compiling the Libunwind libraryBecause you are using a x86_64 Linux system, you need to install the Libunwind library. The installation method is very simple, the common Configure,make,make installs the routine. wget HTTP://DOWNLOAD.SAVANNAH.GNU.ORG/RELEASES/LIBUNWIND/LIBUNWIND-0.99-BETA.TAR.GZTARXVZF LIBUNWIND-0.99-BETA.TAR.GZCD Libunwind-0.99-beta./configuremakemakeinstall because the default libunwind is installed in the/usr/local/lib directory, This directory needs to be added to the system dynamic library cache.echo "/usr/local/lib" >/etc/ld.so.conf.d/usr_local_lib.conf
/sbin/ldconfig The latest version of Libunwind is 1.0.1, so why not choose the latest version? The instructions are given in the install file of Google Perftools. Libunwind with a version lower than 0.99-beta may not work with Preftools, but a version higher than 0.99-beta may contain code that is incompatible with perftools (because Libunwind calls malloc, May cause a deadlock). Libunwind has a lot of problems on the x86_64 platform and Perftools, but does not affect the core Tcmalloc library, but it affects the tools in Perftools, such as Cpu-profiler,heap-checker, Heap-profiler.2. Compiling Google-perftoolsBecause we only need tcmalloc functionality, we do not compile other tools in the Google-perftools. wget Http://gperftools.googlecode.com/files/google-perftools-1.9.1.tar.gztarxvzf GOOGLE-PERFTOOLS-1.9.1.TAR.GZCD google-perftools-1.9.1./configure--disable-cpu-profiler--disable-heap-profiler--disable-heap-checker-- Enable-minimal--disable-dependency-trackingMakemakeinstall/sbin/ldconfig usage1. The target program introduced the header file <google/profiler.h>, Link Libprofiler library, 64-bit operating system simultaneously link Libunwind Library, call Profilerstart () at the beginning and end of the code to be parsed Functions and Profilerstop () functions 2. Compile the link, run the programAnalysis OutputThe Pprof script parses the profile and outputs the results, including both text and graphics output styles. For example: Demo is the target program, My.prof is the profile generated text style result: Pprof--text./demo my.prof >profile.txt generate graphic style results: Pprof--pdf./demo my.prof > profile.pdf The CPU time analysis for a function is divided into two parts: 1. The CPU time consumed by the entire function, including the CPU time consumed by other function calls within the function 2. Does not include CPU time consumed by internal other function calls (except inline functions)about Text style output results
      description
1 Analyze the number of samples (other function calls are not included)
2 Analysis sample percentage (no other function calls)
3 Percentage of analysis samples so far (not including other function calls)
4 Analyze the number of samples (including other function calls)
5 Analyze sample percentage (contains other function calls)
6 Name of function
about graphic style output results1. Nodes each node represents a function, node data format:
Class Name  Method Name  Local (percentage) of Cumulative (percentage)
The local time is the CPU time (including inline functions) consumed by the instruction executed directly by the function; profiling is done by sampling method, default is 1 seconds 100 samples, one sample is 10 milliseconds, that is, the time unit is 10 milliseconds The cumulative time is the sum of the local time and other function calls, and if the cumulative time is the same as the local time, the cumulative time item is not printed. 2. A directed-edge caller points to the callee, and the time on the edge indicates the CPU time consumed by the calleeExampleThe code below, as you can see,CpuConsumption is concentrated inFunc1 ()AndFunc2 () Two functions, func2 () consumption time is about < Span style= "Word-wrap:break-word; font-size:6.5pt; " >FUNC1 () #include <google/profiler.h> #include <iostream>using namespace std;void func1 () {int i = 0;   while (I < 100000) {++i;   }}void Func2 () {int i = 0;   while (I < 200000) {++i;       }}void func3 () {for (int i = 0; i <; ++i) {func1 ();   Func2 (); }}int Main () {Profilerstart ("my.prof");Specifies the generated profile file name Func3 (); Profilerstop (); //End Profilingreturn 0;} Then compile the link to run, using PPROF to generate the analysis resultsG++-o Demo Demo.cpp-lprofiler-lunwindpprof--text./demo my.prof > Output.txtpprof--pdf./demo my.prof > Output.pdfTo view the results of the analysis, the program is a 122-time sample, where Func1 () is 40 time samples, about 400 milliseconds, and Func2 () is 82 time samples, about 820 milliseconds.

total:122 Samples

67.2% 67.2% 67.2% func2

32.8% 100.0% 32.8% func1

0 0.0% 100.0% 122 100.0% __libc_start_main

0 0.0% 100.0% 122 100.0% _start

0 0.0% 100.0% 122 100.0% func3

0 0.0% 100.0% 122 100.0% main

Google Open source C + + Performance analysis tool-Gperftools

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.