a_bertrand Posted November 25, 2010 Share Posted November 25, 2010 What is code profiling? Imagine your code / script or whatever you want to call it, is composed of a multitude of files / class / functions. Yet at some point some actions start to be really slow or use a lot of memory. How would you start trying to see where is the bottleneck? This is exactly what a profiler job is. Example: I create a game, at after a while the game frame per sec (FPS) is going down... for some unknown reasons. I start the profiler and the tool tell me that this function uses X percent of the CPU time. I know then where to go to find the issue. Yes but can I use it? Profiler tools exists for most languages, and there is even some tools for PHP. How easy those tools are is another question. Some tools are however not free, but many offers a free trial. What can a profiler do? A profiler can check which function uses most CPU or even check if you have memory leaks... and point you to what is going wrong. It is not useful in every day scenario, but it can be the tool to solve issues when you have no clues what is going on. How does that look like? For PHP: http://www.php-debugger.com/dbg/sshot.php For C#: http://www.jetbrains.com/profiler/index.html For Java: http://www.yourkit.com/overview/index.jsp For Python: http://docs.python.org/library/profile.html Etc... those are just examples and you may find more. However profiling scripts is normally harder than others. Also profilers features and easy of use are not all the same. Nor the price ;) When to use one? You should use one when you start to hit a bottleneck and wonder if you can't improve the speed or try to squash a memory leak. For PHP memory leaks are normally not an issue, for the speed you will not have issues if your code doesn't do much beside getting data from the database and showing it back to the browser. If you start to create some calculation or crunch your data... then it may help. Can I survive without? Sure! You can work without it, as well as without a debugger. Profiling scripts or code can be done by timing functions runs and store how much each function took to execute. You may then try to improve those specific codes. Quote Link to comment Share on other sites More sharing options...
Jordan Palmer Posted November 25, 2010 Share Posted November 25, 2010 This looks pretty interesting... exactly what game owners would need if they want to be successful.. I may look at getting this and see how i'm doing =P Quote Link to comment Share on other sites More sharing options...
Dave Posted November 25, 2010 Share Posted November 25, 2010 Seems like a helpful thing so people can detect which bits of their scripts are slowing down their site. Could definitely help performance and speed on people's games. Quote Link to comment Share on other sites More sharing options...
Nickson Posted November 25, 2010 Share Posted November 25, 2010 Pretty informative post, I'm wondering though, how far or how extended can these profilers go? I have never used one myself, but it leaves me with questions... to how it will present the results exactly. But I guess I'll find out when I really need them. Quote Link to comment Share on other sites More sharing options...
a_bertrand Posted November 26, 2010 Author Share Posted November 26, 2010 Well with my over 80'000 lines of code project, it pointed out directly to the functions which was using most of the CPU. I clicked on "hot spots" and voila you got them on the top of the list. In less than 1 hour I shaved about 40% of those CPU usage. For the memory profiler, it shows which objects use the memory and therefor you may find some oddies, it shows also which objects tend to increase over time. Honestly those tasks are nearly impossible when the project grows without such tools. If you are interested I will make screenshoots of my profiling. Quote Link to comment Share on other sites More sharing options...
a_bertrand Posted November 26, 2010 Author Share Posted November 26, 2010 That's an actual true usage for my Silverlight game. So I was checking it within IE ! (FF or Chrome would have been the same) First view you have a tree of function calls from top to down... with all the % of CPU usage. Before optimization (you see the Handle cockpit takes 27% of the time) After optimization you see that I removed that weight on the cockpit. The last icon sorts functions call by CPU usage. I can show memory optimizer too but not for Silverlight. Quote Link to comment Share on other sites More sharing options...
Nickson Posted November 26, 2010 Share Posted November 26, 2010 Thanks for the screenshots, seems like a pretty impressive tool to use! I really need to keep this in mind, great tip! Quote Link to comment Share on other sites More sharing options...
a_bertrand Posted November 26, 2010 Author Share Posted November 26, 2010 It is indeed an impressive tool (and that's one reason why I posted ;) ) specially if you know what this means under, to check all the functions and keep all the call stacks without yet hurting too much the performances of the application. I really like the way things are presented (showing which are your functions which are the one from the library), and showing you the "hot path" (red triangles) to show you things that may need some optimization. Again, I would not have been able to pin out the issue without such tool. For example getting back the width of the canvas where I was drawing was slow... so caching the width inside a double simply nearly double the speed of a function. How could you find that without WAY too much trials? Quote Link to comment 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.