Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to log only executions slower than X with xdebug?

I would like xdebug to trace only "jumps" of over X ms or of over Y KB RAM, for instance, every execution that took longer than 100ms or increased memory use by more than 100KB. This would let me ignore thousands of trace lines I don't need to see and would make optimisation much easier - as it is, in ZF2, the bloated framework takes 1 second just to start with the composer autoloader on our enterprise project, which results in thousands of lines I really have no use for. Somewhere along the line I do find the bigger jumps in execution time, but not after a long bout of scrolling.

Is there a default option to disable logging of "faster than X" executions, or if not, do you know of a helper shell/python script that could grep just the slower ones out?

For clarification, I am talking about the contents of the .xt file I get by running xdebug_start_trace() in my app.

like image 664
Swader Avatar asked Nov 13 '22 11:11

Swader


1 Answers

I know nothing about such options, but what I may suggest is to use profile instead of trace.

Here is an article how you can use it. If short, place these lines to your php.ini file:

xdebug.profiler_enable = 0
xdebug.profiler_enable_trigger = 1
xdebug.profiler_output_dir="c:\Projects"

and when you want to start profiler, run url with query parameter ?XDEBUG_PROFILE=1

This will produce a file with name like cachegrind.out.* and place it into profiler_output_dir.

That file could be viewed with CacheGrind viewer for your OS. Link above has a list of apps to view those files for different platforms. I were using wincachegrind (for Windows) to profile ZendFramework app. Very useful tool, as for me. And interface allow to see call tree, execution time, number of calls etc. Well, but I see no option to measure memory usage with it.

like image 139
Viktor S. Avatar answered Nov 15 '22 06:11

Viktor S.