An xdebug like profiler without xdebug

Coding Critique is the place to post source code for peer review by other members of DevNetwork. Any kind of code can be posted. Code posted does not have to be limited to PHP. All members are invited to contribute constructive criticism with the goal of improving the code. Posted code should include some background information about it and what areas you specifically would like help with.

Popular code excerpts may be moved to "Code Snippets" by the moderators.

Moderator: General Moderators

An xdebug like profiler without xdebug

Postby max529 » Sat Dec 10, 2011 1:43 am

Hi there,

I have made a profiler for a new php framework I am working on. I need to know if a profiler like this already exists for php.

This profiler is a bit like xdebug. But it does not need any extra extensions.

This also does not need you to add any profiling code to your functions.

Here is the framework -ModuleR,

To see a sample of the profilers trace go to

Profiler can Profile and trace your functions without adding a single line of profiling code.

The Profile includes

The time spent in function.
The memory used by the function.
The arguments passed to the functions.
The return values of the function.

To see a sample of the profilers trace go to

You can click on function names to show deeper function calls. You can click on the unserialize link to show arguments and return values.

To try out the profiler it is better if you download the framework. Installtion is as simple as

downloading the tar archive from

renaming config.template.php and routes.template.php in config directory to config.php and routes.php.

Edit config.php to match your file path.

give write permissions to scratch directory.

Thats all...

Now to see the profiler in action,

Open any of the module controller files, say modules/builder/builder.php.

Add a new method test_function to the builder class.
Add some code that creates some delay and take some memory. for eg
Syntax: [ Download ] [ Hide ]
function test_function()
$str = str_repeat('t',1000);

now delete the last dump by going to menu link, profiler->delete last trace.

Then take the page index.php/builder/test_function .

Now if all goes well, profiler should have written a lot of files to the scratch/dump directory. You can see the profile by taking from menu, Profiler=>view last trace.

Now the first level of function calles will be shown. Here the last one will be core::response(). If you click on it it will expand to show function calls from that function. That should include our new function builder::test_function(). Besides the function name will be the time spent inside that function, which should be close to 2 seconds.and a memory use of nearly 2000bytes.Increase the sleep time and string length to try the profileres accuaracy.

Please let me know what you think.

Thank you.
Forum Commoner
Posts: 50
Joined: Sat May 19, 2007 4:10 am

Re: An xdebug like profiler without xdebug

Postby max529 » Mon Dec 26, 2011 5:01 am


any comments ?? :D I am attaching am screen shot of the actual view of a trace produced by the profiler..
Forum Commoner
Posts: 50
Joined: Sat May 19, 2007 4:10 am

Re: An xdebug like profiler without xdebug

Postby Mordred » Fri Jan 06, 2012 6:36 am

Can you give a short description on how this thing works? Would it work without using your framework?
Things need not have happened to be true. Tales and dreams are the shadow-truths that will endure when mere facts are dust and ashes, and forgot.
My security blog. (not updated lately)
The Unexpected SQL Injection (article) (.txt, cause the .html version is broken)
Password hashing howto (and how not to) (article)
Salt strengths (article)
User avatar
DevNet Resident
Posts: 1579
Joined: Sun Sep 03, 2006 5:19 am
Location: Sofia, Bulgaria

Re: An xdebug like profiler without xdebug

Postby max529 » Wed Jan 11, 2012 12:25 am

This is a profiler that does not require xdebug and does not require to add additional profiling code around your functions. This profiler works by modifying included files on the fly to add the profiler function calls and other required statements for profiling. The actual file is untouched. Just the way php sees the file is changed. So it can measure the time spent is every invocation of a function,memory used and arguments passed to and values returned from functions. It can also generate a trace of the program execution. The dump data is written into 50 files( can be configured) and is viewed the trace viewer.

To use this just delete the dump from last trace using the delete last trace menu item from profile menu. The next page you take in browser will be profiled. So after taking a page, if you go back to the view last trace page, you can see the data collected. You can click on the function names to dig down deeper into the execution level/ function calls. You can also track any files included also.

PS: I have searched for ages for something like that SQL injection article in your signature. Its great.
Forum Commoner
Posts: 50
Joined: Sat May 19, 2007 4:10 am

Return to Coding Critique

Who is online

Users browsing this forum: No registered users and 2 guests