sandeep529 Posted December 14, 2011 Share Posted December 14, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/253152-building-a-profiler-for-php-is-this-a-bad-idea/ Share on other sites More sharing options...
trq Posted December 14, 2011 Share Posted December 14, 2011 From what I have gathered from your brief description it sounds like it would create allot of overhead. What is wrong with XDebug? Quote Link to comment https://forums.phpfreaks.com/topic/253152-building-a-profiler-for-php-is-this-a-bad-idea/#findComment-1297801 Share on other sites More sharing options...
sandeep529 Posted December 14, 2011 Author Share Posted December 14, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/253152-building-a-profiler-for-php-is-this-a-bad-idea/#findComment-1297816 Share on other sites More sharing options...
trq Posted December 14, 2011 Share Posted December 14, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/253152-building-a-profiler-for-php-is-this-a-bad-idea/#findComment-1297956 Share on other sites More sharing options...
sandeep529 Posted December 15, 2011 Author Share Posted December 15, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/253152-building-a-profiler-for-php-is-this-a-bad-idea/#findComment-1297981 Share on other sites More sharing options...
gizmola Posted December 15, 2011 Share Posted December 15, 2011 You can install xdebug with pecl as I described in this article: http://www.flingbits.com/tutorial/view/xdebug-for-developing-debugging-and-profiling-php I don't think there's anything wrong with creating your own profiling solution. No one solution works for all people in all circumstances. Quote Link to comment https://forums.phpfreaks.com/topic/253152-building-a-profiler-for-php-is-this-a-bad-idea/#findComment-1297984 Share on other sites More sharing options...
sandeep529 Posted December 15, 2011 Author Share Posted December 15, 2011 But if I get this to work, can this be useful in a general sense, like useful to a lot of people? Quote Link to comment https://forums.phpfreaks.com/topic/253152-building-a-profiler-for-php-is-this-a-bad-idea/#findComment-1298037 Share on other sites More sharing options...
trq Posted December 15, 2011 Share Posted December 15, 2011 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" Quote Link to comment https://forums.phpfreaks.com/topic/253152-building-a-profiler-for-php-is-this-a-bad-idea/#findComment-1298042 Share on other sites More sharing options...
sandeep529 Posted December 15, 2011 Author Share Posted December 15, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/253152-building-a-profiler-for-php-is-this-a-bad-idea/#findComment-1298075 Share on other sites More sharing options...
sandeep529 Posted December 16, 2011 Author Share Posted December 16, 2011 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.... Quote Link to comment https://forums.phpfreaks.com/topic/253152-building-a-profiler-for-php-is-this-a-bad-idea/#findComment-1298480 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.