Jump to content

Building a profiler for php-Is this a bad idea ?


sandeep529

Recommended Posts

Hi all,

 

I have created a profiler as a part of a framework I am developing.

 

The profiler, when enabled,  works by intercepting include calls and modifying/patching functions present in the  included files on the fly to adds calls to the profiler class methods to log data required for profiling.

 

Please note that actual files are untouched. Just when they are included , this class stands in between php and the file so that php will see the patched version of the file , while

 

the actual file is untouched .

 

Is this a bad thing, or a bad idea? I mean to patch code on the fly. Can you think of any cases where this would not work?

 

And Are there any profilers that I can use without adding extra profiling code, other than Xdebug?

 

Regards,

Sandeep.

 

 

Link to comment
Share on other sites

From what I have gathered from your brief description it sounds like it would create allot of overhead.

 

I believe any kind of profiling will create overhead .But the important thing is , it should not use up all the memory.  Other kind of overheads, like causing more execution time can be accomodated by increasing max execeution time, which can be increased indefinitely.  In this case I have removed that possibility  by NOT keeping the profile data in memory.

But it is written to disk, to multiple files.

 

What is wrong with XDebug?

 

Nothing wrong.Xdebug is just a very powerful tool. so powerful that it may be an overkill to use it just for profiling.

 

But it also requires an extensions. In windows environment enabling xdebug is straight forward. But in linux i believe it requires recompiling php wih xdebug enabled.It also generates huge  dump files  which can only be viewed by another application.

 

I know these are not xdebugs limitations but its very power and these are no big deals if you really want to use xdebug...

 

But if there is something that you can just click to cause all of your functions to be profiled, and you can view a nice trace of execution..wouldn't that be nice?

 

Regards,

sandeep.

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

In windows environment enabling xdebug is straight forward. But in linux i believe it requires recompiling php wih xdebug enabled.

 

There is no need to compile php from source in Linux distributions and each extension is simply another package.

 

For example, in Debian you would simply execute something like:

 

apt-get install xdebug

Link to comment
Share on other sites

an apt-install can install xdebug. I agree. But there may be some people, including myself, who will rather put little microtime calls in their functions they need to profile than install a new extension.

 

But Do you think something like this cannot possibly work reliably enough to be useful? I am using php parser tokenizer library for parsing the include files. so all parsing is done by php.

 

It seems to be working ok. But can you think of any situation where this might fail. It wont profile functions defined by eval() at present. But something can be done about that.

 

Thing I want to know is if this can be made into something useful. That would make profiling a little , just a little bit more accessible to the php programmer.

Link to comment
Share on other sites

Nothing wrong.Xdebug is just a very powerful tool. so powerful that it may be an overkill to use it just for profiling.

 

I don't understand how it could be too powerful to use just for profiling, it is a profiler.

 

But if I get this to work, can this be useful in a general sense, like useful to a lot of people?

 

It has the potential to be useful and I agree with gizmola that "No one solution works for all people"

Link to comment
Share on other sites

I don't understand how it could be too powerful to use just for profiling, it is a profiler.

 

What i meant was, when something is  powerful, it has a lot of features, a lot of configuration options, and  a little difficult to  get it to work as you wish.

 

Regarding xdebug, it is not only a profiler, but a debugger too. One can stop the execution of the script  check varible values, step into,step over function and all stuff like that...

 

Suppose you want to know the time spent is just one invocation of a function.

Surely for a simple requirement like this  one would not use xdebug. Because it can be done much easily using microtime calls at the begining and end of the function.

 

So using xdebug for this would be an overkill, even though it is very capable of producing that information.

No one solution works for all people

 

This is exactly my point. For the hardcore programmers  there is xdebug. There should be something simpler for the rest of us. Right?

Link to comment
Share on other sites

hi guys,

 

I tried to install xdebug. It worked.

 

But I am not able to install KCachegrind....I am on a fedora 13 machine.

 

Cmake terminates with error....ERROR: cmake/modules/FindKDE4Internal.cmake not found in...

 

May be I am doing something stupid...  But it goes to show why xdebug may not work for everyone....

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.