Home > php教程 > php手册 > body text

使用ltrace工具跟踪PHP库函数调用的方法,ltrace库函数

WBOY
Release: 2016-06-13 08:40:52
Original
930 people have browsed it

使用ltrace工具跟踪PHP库函数调用的方法,ltrace库函数

本文实例讲述了使用ltrace工具跟踪PHP库函数调用的方法。分享给大家供大家参考,具体如下:

可能大家已经很熟悉使用strace来跟踪系统调用,今天介绍一个跟踪库函数的利器ltrace

比如我有这么一段PHP代码

test.php:

<&#63;php
 $y = '1380';
 $arr = array();
 for($i = 0; $i < 2000; $i ++){
   $arr[] = "{$i}"; //故意用引号包起来设成字符串
 }
 for($i = 0; $i < 2000; $i ++){
   if(!in_array($y, $arr)) continue;
 }
&#63;>

Copy after login

ltrace -c /usr/local/php/bin/php test.php (-c表示汇总)

会看到输出如下:

% time   seconds usecs/call   calls   function
------ ----------- ----------- --------- --------------------
95.02  7.417240     368   20146 strtol
2.15  7.160390     413   17316 memcpy
1.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

Copy after login

可以看到 strtol几乎用去了执行时间的95.02%,瓶颈就找出来了。及PHP会在in_array()测试时试图将字符串行数字转换为long,这会耗费大量时间。所以只要将字符串都转换为整形即可大幅度提高效率。

ltrace真心是个好工具

希望本文所述对大家PHP程序设计有所帮助。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!