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

Post Reply
max529
Forum Commoner
Posts: 50
Joined: Sat May 19, 2007 4:10 am

An xdebug like profiler without xdebug

Post by max529 »

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,

http://moduler.pagodabox.com

To see a sample of the profilers trace go to

http://moduler.pagodabox.com/index.php/trace/lastTrace

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

http://moduler.pagodabox.com/index.php/trace/lastTrace

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 http://moduler.pagodabox.com/moduleR.tar

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

Code: Select all

function test_function()
{
sleep(2);
$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.
Sandeep.
max529
Forum Commoner
Posts: 50
Joined: Sat May 19, 2007 4:10 am

Re: An xdebug like profiler without xdebug

Post by max529 »

hi,

any comments ?? :D I am attaching am screen shot of the actual view of a trace produced by the profiler..
Attachments
profiler-ss.png
User avatar
Mordred
DevNet Resident
Posts: 1579
Joined: Sun Sep 03, 2006 5:19 am
Location: Sofia, Bulgaria

Re: An xdebug like profiler without xdebug

Post by Mordred »

Can you give a short description on how this thing works? Would it work without using your framework?
max529
Forum Commoner
Posts: 50
Joined: Sat May 19, 2007 4:10 am

Re: An xdebug like profiler without xdebug

Post by max529 »

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.
Post Reply