Hi,
We are developing a race game, and writing the AI slowly zaps the FPS rate (no surprise here).
What I would like to know is, if there is a way to profile the execution of the game.
Something that outputs something similar to this (example found on the net):
Flat profile:
Each sample counts as 0.01 seconds.
% cumulative self self total
time seconds seconds calls Ts/call Ts/call name
50.00 0.75 0.75 matrix_mult_
11.33 0.92 0.17 pdaxpy_
8.67 1.05 0.13 pddot_
8.00 1.17 0.12 set_fv2d_equations_
6.67 1.27 0.10 calc_residual_
4.00 1.33 0.06 pdcopy_
4.00 1.39 0.06 precon_solve_
3.33 1.44 0.05 calc_mat_norm_
2.00 1.47 0.03 solv_fix_bounds_
0.67 1.48 0.01 conjgrad_sub_
0.67 1.49 0.01 dlamc4_
0.67 1.50 0.01 z_wnew
Being fairly new to .net, Unity and to Macs in general there might be an obvious tool already right in front of my nose. Or there is something build into Unity that I havent found yet.
But in that case I hope you can help me spot it 
Thanks a bunch!
/Thomas
If you install the dev tools on OS X (on one of your install discs), there’s a tool called Shark that does this. Make sure you profile a build that hasn’t had debug symbols stripped.
–Eric
Hi Thomas,
you might want to have a look at a little profiler tool I wrote a while back: JCsProfiler.
If you want to profile your own code, that’s probably a solution that might work for you. I haven’t found time to test this with JavaScript, but it works smoothly with C#, and I think it should also work with JS (just haven’t tested it, and have no examples of how to use it).
The major “limitation” is that you need to put calls to the profiler into your code. On the other hand, that gives you nice control over what you want to profile, and what not. The code can be “deactivated” so it shouldn’t consume a lot of performance unless you activate it. However, to keep things clean I would recommend using a “comment-code-out-by-replacing”-pattern:
Keep the calls to the profiler in single lines, and prefix them with “/P/”. Then, if you want to completely “remove” all profiling code, all you need to do is a global search and replace, which replaces “/P/” with “/P///” which will comment out those calls to the profiler 
Sunny regards,
Jashan
Hi Eric,
cool - thanks for that pointer!
If I read the results this just gave me correctly, the script code only takes 0.2% of the time in my game… is that possible? The only “reference” to my script code I could find was MonoBehavior::Update(), which I guess should be all the calls to Update(). Ah, ok, now I found “Coroutine::Run()” which takes 0.3% 
This is interesting because I control everything via script code (in particular all movement), and also have some “not-too-optimized” AI in there…
It also tells me that my particles consume a lot of time 
Sunny regards,
Jashan
Cool stuff guys - thanks a bunch. Will give it a run tonight at home.
(Almost all code in C#, so wont test the js stuff still left in there - hehe)
/Thomas
Shark won’t help to profile scripting. It’s great to profile your game overall but you won’t be able to gather more than how much time is spent in Update, FixedUpdate or Coroutines. There’s no way to find out what classes or methods cause the load.
In case you want to profile your scripts, jashan’s script-based profiler is what’ll give you the info.