Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I manually say on xdebug profiler to start profiling in specific place?

I already have enabled xDebug profiling in my XAMPP installation and it works fine.

Now I like to ask if there is a way to say from within my source code when to start profiling with xDebug.

More specific, I'd like to create a WordPress plugin, and I'd like to say, start profiling from the start point of the plugin and stop profiling at the end point of the plugin.

Is that possible?

Note: The above is just an example. It can be a CakePHP plugin or a new PHP Class that I may need to profile

like image 440
KodeFor.Me Avatar asked Nov 10 '11 10:11

KodeFor.Me


People also ask

How do I trigger xdebug profiler?

You can also selectively enable the profiler by setting xdebug. start_with_request#trigger to trigger . You can then enable the profiler by using an environment value, a GET/POST parameter, or COOKIE variable of the name XDEBUG_TRIGGER .


2 Answers

Edit: Per How to Turn On/Off Xdebug Profiling at Runtime? you can't actually enable/disable at runtime (for example per function call).

You can selectively enable profiler per request, which is generally better. To achieve this behaviour set those settings:

For xdebug 3 (Upgrade Guide):

xdebug.mode = profile; xdebug.start_with_request = trigger; 

For xdebug 2:

xdebug.profiler_enable_trigger=1 xdebug.profiler_enable=0 

Note that we disable profiler and only enable the trigger. From your browser pass XDEBUG_PROFILE=1

http://example.com/file.php?XDEBUG_PROFILE=1 

You may also pass this parameter in POST or COOKIE. For more info check

  1. http://xdebug.org/docs/profiler#starting
  2. http://xdebug.org/docs/all_settings#profiler_enable_trigger
like image 79
Laith Shadeed Avatar answered Oct 02 '22 14:10

Laith Shadeed


As stated by Laith, you can't choose when you want xDebug to start profiling and when you want him to stop. But, another xDebug feature offers this kind of flexibility: trace.

Profiling and tracing are not exactly the same things but, if you end up here, it may be possible that trace may suits your need.

To start tracing, you have to use this function: xdebug_start_trace()

To stop tracing, you have to use this function: xdebug_stop_trace()

There is quite a lot of settings you can use to change trace's behavior:

http://xdebug.org/docs/execution_trace

like image 20
Tristan CHARBONNIER Avatar answered Oct 02 '22 13:10

Tristan CHARBONNIER