Introduction to a gadget PHP-Valgrind

Source: Internet
Author: User
Tags valgrind apple mac pro
Author: Laruence () address of this article: www.laruence.com201308142899.html record the source. First, I will not update the blog for too long. I always thought that people would always write blogs out of time, but now it seems that I am wrong. the blog is not updated for a long time. It does not mean that there is no content to share. but this year is true.

Author: Laruence () address of this article: http://www.laruence.com/2013/08/14/2899.html reprint please indicate the source first, too long don't update the blog, let me first speak a few words. I always thought that people would always write blogs out of time, but now it seems that I am wrong. the blog is not updated for a long time. It does not mean that there is no content to share. but this year is true.

  • Author: Laruence ()
  • Address: http://www.laruence.com/2013/08/14/2899.html
  • Reprinted please indicate the source

First, I will not update my blog for too long.

I always thought that people would always write blogs out of time, but now it seems that I am wrong. the blog is not updated for a long time. It does not mean that there is no content to share. however, this year has indeed been a lot of busy, and there have been a lot of work tasks. In my spare time, it has also been filled up by PHP projects and Zend tasks. in addition, some small sentiments are all complained on Weibo... So ....

Anyway, I am very grateful to all of you who often come to my blog. However, I suggest you do not leave a message if you ask a question. Sometimes the blog may be used as a SPAM, but there are some minor problems, you can go to Weibo At me @ laruence

Let's get down to the point. Today we share a little tool we just made the day before yesterday. The code can be found on my github: php-valgrind. this tool provides the Profile capability for enabling Valgrind (Callgrind strictly) in PHP scripts.

In general, when we use Callgrind, if we want to analyze a function, we can use toggle-collect = "function name" to tell Callgrind to start Profile when entering this function. but there is no way to analyze a specific piece of code ..

In fact, Callgrind provides a mechanism that allows us to control when to enable in code: CALLGRIND_TOGGLE_COLLECT

For example:

#include 
 
  #include 
  
   void foo(int a[100]) {    int i = 0;}int main (int argc, char **argv) {    int i, a[100];    CALLGRIND_START_INSTRUMENTATION;    CALLGRIND_TOGGLE_COLLECT;    for (i=0; i<100; i++) {        a[i] = 2;    }    CALLGRIND_TOGGLE_COLLECT;    CALLGRIND_STOP_INSTRUMENTATION;    return;}
  
 

Then, after compilation into a. out, we can analyze the specific Profile information of this loop code disconnection:

$ valgrind --tool=callgrind --collect-atstart=no --instr-atstart=no ./a.out

The generated callgrind. out can be analyzed by tools such as callgrind_annotate and kcachegrind.

$callgrind_annotate callgrind.out.27538//OUTPUT:-------------------------------------------------------------------------------- Ir---------------------------------------617  PROGRAM TOTALS--------------------------------------- Ir  file:function---------------------------------------617  test.c:main [***dev/a.out]

Is it convenient?

However, sometimes, for example, we do expansion or other internal performance analysis. this can also be triggered in PHP scripts. there is no way. so I wrote this little tool php-valgrind. After installing this extension, let's look at an example:

 

Then we start to analyze:

$valgrind --tool=callgrind --collect-atstart=no --instr-atstart=no php /tmp/1.php

Then we analyze the output:

------------------------- Ir ------------------------ 2,361,260 program totals // The following is omitted

Then let's use qcachegrind (callgrind analysis tool with gui) to look at it:

It can be seen that PHP requires N times more code than C to implement the same function (so of course it is slower than C .. hey, I declare again: "C language is the best language, not one! ")

After the introduction of the tool is complete, you can play with it if you are interested. This tool can also be used to let us know that one of our PHP code will trigger calls to the underlying functions, or system calls, etc. Enjoy ~

Comments
  • , Qiu Feng writes: Updated. Try it!
  • , Night, snow writes: front row name, ad space rent C language is the best language, none!
  • , Pakey writes: No sofa grabbed
  • , Micro-history writes: it is important to keep updates
  • Writes: PHP is the best language ~~~
  • 2013/08/14, php230 writes: V5
  • On February 14, my name is Zhang Da Xiong writes. I asked you a question on Weibo's private message, but I still have no answer yet.
  • On February 14, my name is Zhang Da Xiong writes. I asked you a question on Weibo's private message, but I still have no answer yet.
  • , Eagle writes: Do I need to install Callgrind separately?
  • , Eagle writes: Do I need to install Callgrind separately?
  • , Wclssdn writes: I also asked Daniel several questions on Weibo .. just ignore me... khan... and. this tool similar to Daniel can use xhprof .. there are image display methods... too intuitive... more data tables...
  • , Goodboy writes: "C language is the best language "......
  • 2014/02/19, Winona writes: I was curious if you ever thought of changing the page layout of your website? Its very well written; I love what youve got to say. but maybe you coshould a little more in the way of content so people coshould connect with it better. youve got an awful lot of text for only having one or two pictures. maybe you cocould space it out better?
  • 2014/02/27, real estate preview writes :? E're? Roup? F volunteers and starting a brand new scheme in? Ur community. Your web site provided us with u? Every ful information to work on. You have done a formidable job and ou should whole gro? P can be thankful to you .? Ere I? My blog: real estate preview
  • , Computer repairs, apple mac pro reviews, cell phone repair, computer support, mercadolibre writes: Its 23-inch screen is already written on Apple's website because "Discontinued. as a result, the smaller sized or thinner the notebook, the lesser the capabilities in view that they are pressured to go out some ports. feel free to visit my web blog: computer repairs, apple mac pro reviews, cell phone repair, computer support, mercadolibre
  • , Nigel writes: Template experts ~~~~~
Related posts:
  • Note: PHP increment operations on strings
  • A "problem" caused by GCC Optimization"
Copyright©2010 All Rights Reserved. this Feed is for personal use only. reposted or commercial applications that are not specified are prohibited. if the application is illegal, all legal consequences shall be borne by you. if you have any questions, you can send an email to my at laruence.com. (Digital Fingerprint: 73540ba0a1738d7d07d4b6038d5615e2)

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.