1. 云栖社区>
  2. PHP教程>
  3. 正文

Xdebug 2.3: Improvements to Tracing - Derick Rethans

作者:用户 来源:互联网 时间:2017-12-01 12:06:44

Xdebug 2.3: Improvements to Tracing - Derick Rethans - 摘要: 本文讲的是Xdebug 2.3: Improvements to Tracing - Derick Rethans, This is the fifth article in a series about new features inXdebug2.3, which was firstreleasedon February 22nd. In this

This is the fifth article in a series about new features inXdebug2.3, which was firstreleasedon February 22nd.

In this instalment we are going to have a look at the additions to the trace file functionality. Trace files are a way to document every function call, and if you enable it, variable assignment and function's return values — including when these functions were called, and how much memory PHP was using at the moment of function entry (and exit).

Xdebug 2.3 adds a new type of parameter rendering for stack traces and function traces through thexdebug.collect_paramssetting. Existing options are/for just the variable type,for a string description, andfor a string description and a variable name. Xdebug 2.3 now also features a base64 encoded serialized representation of the variable's contents (option). Which means that the following lines:

$a = array(1, "foo", M_PI);var_dump($a);

show up in the following 5 ways with different variations of thexdebug.collect_paramssetting:

  1. var_dump(array(3))

  2. var_dump(array(3))

  3. var_dump(array (0 => 1, 1 => 'foo', 2 => 3.1415926535898))

  4. var_dump(array (0 => 1, 1 => 'foo', 2 => 3.1415926535898))

  5. var_dump(YTozOntpOjA7aToxO2k6MTtzOjM6ImZvbyI7aToyO2Q6My4xNDE1OTI2NTM1ODk3OTMxO30=)

This is probably more useful with thecomputerizedtrace files that are easier to parse.

In Xdebug 2.3, normal (human readable) trace files now also show the time index and memory usage for function exit lines. Function exit lines are generated whenxdebug.collect_returnis set to. Which means that with with Xdebug 2.2 you would see:

TRACE START [2015-03-28 18:48:39]0.0008 275928 -> test1() …/closure-trace.phpt:270.0008 276848 -> {closure:…/closure-trace.phpt:20-22}() …/closure-trace.phpt:240.0009 277168 -> strlen() …/closure-trace.phpt:21 >=> 3 >=> 3 >=> NULL0.0010 276056 -> xdebug_stop_trace() …/closure-trace.phpt:280.0010 276184TRACE END [2015-03-28 18:48:39]

But in Xdebug 2.3 you instead see:

TRACE START [2015-03-28 18:48:45]0.0008 269144 -> test1() …/closure-trace.phpt:270.0009 270096 -> {closure:…/closure-trace.phpt:20-22}() …/closure-trace.phpt:240.0009 270336 -> strlen() …/closure-trace.phpt:210.0010 270504>=> 30.0010 270216>=> 30.0010 269264>=> NULL0.0011 269264 -> xdebug_stop_trace() …/closure-trace.phpt:280.0011 269384TRACE END [2015-03-28 18:48:45]

This makes it easier to see how much time and memory a specific function call took, similarly to what already was shown for "computerized" trace files.

And lastly, thecomputerizedformat (xdebug.trace_format=1), has now support for showing return values as well. The return value is part of a new "frame" for a function.

Take the following invocation of PHP:

php -dxdebug.collect_params=0 -dxdebug.collect_return=1 /-dxdebug.trace_format=1 /-r '$a = array(1, "foo", M_PI); xdebug_start_trace("/tmp/trace"); echoserialize($a);' />/dev/null && cat /tmp/trace.xt

In Xdebug 2.2 this shows:

TRACE START [2015-03-29 00:08:34]2110.0004172671922200.000547266848serialize 0 Command line code 1 1 array (0 => 1, 1 => 'foo', 2 => 3.1415926535898)2210.0006262670241010.000695266968 0.0009258536TRACE END [2015-03-29 00:08:34]

But Xdebug 2.3 has an extra "return frame" with the return value:

TRACE START [2015-03-29 00:10:11]2110.0004622631522200.000520262928serialize 0 Command line code 1 1 array (0 => 1, 1 => 'foo', 2 => 3.1415926535898)2210.00059426309622R'a:3:{i:0;i:1;i:1;s:3:"foo";i:2;d:3.1415926535897931;}'1010.000676263040 0.0008818512TRACE END [2015-03-29 00:10:11]

Function(the call toserialize) now has an entry frame () and exit frame () showing the time index and memory usage, as well as the newRframe showing the return value. Unlikehuman readabletraces it is not on the same line as the exit frame because of backwards compatibility reasons.

Other parts in this series:

以上是云栖社区小编为您精心准备的的内容,在云栖社区的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索,以便于您获取更多的相关知识。