Code Profiling

BlitzMax Forums/BlitzMax Programming/Code Profiling

Brucey(Posted 2015) [#1]
I heartily recommend the Zoom profiler on OS X : http://www.rotateright.com

Although it's not very useful for standard BlitzMax bcc-generated code (since that is all asm), using it in conjunction with bcc ng's C-generated code, makes it very easy to see where your program is spending much of its time...
 -_brl_map_TMap__FindNode                                  5.9sec   (74.6%)     128B                          bcc
 | -_brl_map_TMap_Contains                                 5.7sec   (71.7%)      64B                          bcc
 | | -__type_TModuleDecl_GetDecl                           5.7sec   (71.7%)     848B                          bcc
 | | | -__type_TScopeDecl_FindFuncDecl                     3.4sec   (42.9%)   1.66KB                          bcc
 | | | | -__type_TIdentExpr_SemantFunc                     3.4sec   (42.9%)   1.02KB                          bcc
 | | | | | -__type_TFuncCallExpr_Semant                    3.4sec   (42.9%)     144B                          bcc


And with some extra code-generation options enabled, the profiler can show specific details against the original BlitzMax source...
   72   (1.0%)       72   (6.8%)      285 	Method _FindNode:TNode( key:Object )                     
    7   (0.1%)        7   (0.7%)      286 		Local node:TNode=_root                                  
  256   (3.7%)      256  (24.2%)      287 		While node<>nil                                         
6,194  (89.1%)      299  (28.3%)      288 			Local cmp=key.Compare( node._key )                     
    4   (0.1%)        4   (0.4%)      289 			If cmp>0                                                
  164   (2.4%)      164  (15.5%)      290 				node=node._right                                      
   75   (1.1%)       75   (7.1%)      291 			Else If cmp<0                                          
   95   (1.4%)       95   (9.0%)      292 				node=node._left                                       


This particular profiler is a sampling profiler - in that it doesn't count *every* call to every line of code. It samples, say, every millisecond, gradually building up a picture of your programs' profile.
It does work very well. I've used it to track down a couple of inefficiencies in bcc ng which would have otherwise been difficult to ascertain.

:o)