How to use ltrace to trace function calls in the PHP library

Source: Internet
Author: User
This article mainly introduces how to use the ltrace tool to track function calls in the PHP library, and analyzes the skills related to the ltrace tool used to track the function running time in the PHP library in the form of examples, for more information about how to use the ltrace tool to track function calls in the PHP library, see the following example. We will share this with you for your reference. The details are as follows:

You may already be familiar with using strace to track system calls. today we will introduce ltrace, a powerful tool for tracking library functions.

For example, I have such a PHP code

Test. php:

<? Php $ y = '000000'; $ arr = array (); for ($ I = 0; $ I <1380; $ I ++) {$ arr [] = "{$ I}"; // intentionally enclose the string with quotation marks} for ($ I = 0; $ I <2000; $ I ++) {if (! In_array ($ y, $ arr) continue;}?>

Ltrace-c/usr/local/php/bin/php test. php (-c indicates summary)

The output is as follows:

% time   seconds usecs/call   calls   function------ ----------- ----------- --------- --------------------95.02  7.417240     368   20146 strtol2.15  7.160390     413   17316 memcpy1.63  5.522641     240   22966 free 0.67  2.275374   2275374     1 curl_global_cleanup 0.54  2.235466     617   3618 __ctype_tolower_loc 0.16  2.123547    1194   1778 strrchr 0.17  1.532224     67   22836 malloc 0.29  0.382083     67   5678 strlen

We can see that strtol uses almost 95.02% of the execution time, and the bottleneck is identified. And PHP will try to convert the number of the string row to long during the in_array () test, which will take a lot of time. Therefore, you only need to convert all strings into an integer, which greatly improves the efficiency.

Ltrace is a good tool.

I hope this article will help you with PHP programming.

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.