Raster timing bars

Member
Posts: 117
Joined: 2010.09
Post: #1
Hi all,

In the good old days (showing my age here!LOL) on platforms like psx,dreamcast,saturn etc. etc. I use to set up raster colored timing bars.
This basically meant changing the background color (therefore visible in the border) before and after any code you wish to time on the intended platform and real-time.
It was well useful!!

i.e.

set_border(BLUE);

do_ai();

set_border(RED);

Therefore the size of the blue border would indicate how much cpu time the do_ai function was taking.

I know we have instruments which I've only briefly looked at; but that uses sampling anyway.
Perhaps I am not using instruments correctly but can anyone see if the timing bar method can be done or at least a reason why it might be pointless???? Wink

Cheers
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #2
Don't use instruments for profiling, you want to use Shark.

On the other hand, the timing information that you are talking about can be very useful. (That's a pretty cool trick actually) If you just need a high resolution, sub millisecond timer, you can do something like this:

Code:
#include "time.h"

#include <mach/mach.h>
#include <mach/mach_time.h>

double getDoubleTime(void)
{
    mach_timebase_info_data_t base;
    mach_timebase_info(&base);

    uint64_t nanos = (mach_absolute_time()*base.numer)/base.denom;
    return (double)nanos*1.0e-9;
}

I suppose you could sum the times up and print them out only every other second or so to prevent the log from exploding.

I'm guessing that the reason why that method worked on the analog displays is because the border color was changed instantaneously instead of being saved as part of the framebuffer. Correct? You can't really do this on computer displays as everything goes through a buffer anyway.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Member
Posts: 117
Joined: 2010.09
Post: #3
Hey Skorche,

Is shark great then?, why is it not supplied with the iphone SDK by default?
Still like to do my timing bars on the iphone; because it's SO much easier to profile where all those cpu cycles are going.
How can I change the 'border' (I guess background) color though in an opengl enviroment?; can it even be done????

Cheers
Quote this message in a reply
Moderator
Posts: 3,571
Joined: 2003.06
Post: #4
Shark *is* included in the iOS SDK by default: /Developer/Applications/Performance Tools/Shark

You're idea is pretty neat, but I'd still use Shark instead.

One thing about it though, waiting for Shark to process on the iDevice can take a looong time -- several minutes before the profile is displayed. It's arguably worth it though, considering the fidelity of the info returned.
Quote this message in a reply
Member
Posts: 117
Joined: 2010.09
Post: #5
Hmmmmmm!
I read that Apple are dropping shark and want us all to use instruments; which suggests it's heading for the bin :-)

I was thinking about my raster timer and it *should* be possible. Of course with no 'border' to colourize we'd have to make do with opengl rectangles. Hmmmmmmm; it's either gonna work great or be complete pants.

Surely someone else must of thought of this and perhaps (here's hoping) implemented it? :-))))

Cheers

Mark

p.s. will look at shark.
Quote this message in a reply
Moderator
Posts: 3,571
Joined: 2003.06
Post: #6
(Sep 27, 2010 09:57 AM)markhula Wrote:  I read that Apple are dropping shark and want us all to use instruments; which suggests it's heading for the bin :-)

This is the first time I've heard that.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #7
Apparently Shark is gone from iOS4 Sad

If Instruments is not filling some role Shark did for you, you should file a bug report at http://bugreport.apple.com/

I can't think of any way to do this hack on Mac OS X or iOS, but then, neither can I think of a reason to. Just use mach_absolute_time or whatever to capture your timing data, and draw your timing bars normally however you wish.
Quote this message in a reply
Member
Posts: 117
Joined: 2010.09
Post: #8
Yeah OneSadCookie, perhaps you are right!!!

Just collect my timings around the functions I wish to test and then draw a set of rectangles afterwards via opengl with their height relative of course to the time taken.
I will try that and report back; it sounds like a good plan!!

Cheers

Mark

p.s. Shark is definitely dead I can report :-(
Quote this message in a reply
Moderator
Posts: 3,571
Joined: 2003.06
Post: #9
OneSadCookie Wrote:Apparently Shark is gone from iOS4 Sad

markhula Wrote:p.s. Shark is definitely dead I can report :-(

Oh my gosh, that sucks! Sad Is there some new profiling tool in Instruments that I haven't seen yet? If not, then it definitely sounds like bug report time.
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #10
(Sep 27, 2010 03:13 AM)markhula Wrote:  In the good old days

This was indeed a good method for visualizing time, on hardware that supported direct framebuffer writes (or had a border color register, like the Apple ][gs.)

MacOS/iOS don't allow you to write directly to the framebuffer, so you'll need to measure clock time instead, as others have pointed out.
Quote this message in a reply
Moderator
Posts: 3,571
Joined: 2003.06
Post: #11
Heh... great timing on this thread I guess. I was trying to figure out why I was only getting like 20 FPS for hardly drawing anything on iPod Touch 4G and so I ran with the OpenGL ES Instrument. In there, under CPU Sampler, it listed memcpy as 99% of the running count. I was inadvertently copying like 360 MB per second or something ridiculous like that. Turns out I accidentally had the scene set to handle 64k entities... whoops!

So I guess I didn't read the docs about Instruments closely enough. I never use CPU Sampler, as Leaks and Activity Monitor were the main ones I was interested in. I'll have to go back and RTFM, but it appears that CPU Sampler might be one of the tools you can use instead of Shark.
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #12
Bwa? I used shark like a month ago... Which is probably about the same time I upgraded to the 4.0 SDK.

Is Instruments really suitable to replace Shark? Granted this was a year or two ago, but I got the impression that Instruments was not really a good replacement for Shark. Something about the sampling frequency wasn't very high or the overhead was. Am I crazy/making this up?

edit: After spending 2 minutes with Instruments, I think I have my answer... No source/disassembly view with per line and per instruction costs. So no, Instruments does not seem to be a good substitute.

edit2: Ooooh. I probably did use Shark after upgrading to the 4.0 SDK. It still supports iPhone profiling on my 1G running 3.x, but not on the 4G running 4.x. Suck. :-\

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Moderator
Posts: 3,571
Joined: 2003.06
Post: #13
I upgraded to the iOS 4.1 SDK just the day before yesterday and Shark is in it; that's why I posted above that it *is* included. I'm guessing this won't be true for >= 4.2, according to the conversation here.

I'm in the same boat as you, not knowing if Instruments could be a suitable replacement. I think those of us who've been using Shark for so long haven't bothered focusing on any new replacements for profiling tools in Instruments, so we're unfamiliar with them... or if we did play with something similar before in Instruments it was too poor in performance or lacking information (as you just pointed out), so we ignored it/them. Plus, I have no idea what's in the 4.2 SDK, and that's NDA anyway. I guess we should prolly take a look to see what's coming down the pipeline! Surely they don't intend on cutting off one of our most powerful performance analysis tools. I mean, really?
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #14
I would venture to guess that Shark is still installed as part of the Mac SDK, just not usable from the iOS SDK.

Digging deeper, CPU sampler does have disassembly breakdowns for most functions. Though sometimes they inexplicably are blank. This even differs between clear builds. I get (the far more useful) source breakdowns for about 1 out of 100 random functions, and only when building as debug. I didn't see any mention in the documentation that this feature exists at all.

On the Mac, the minimum sampling rate is 10 microseconds, which works pretty well for realtime stuff, though at a small but measurable performance hit. On iOS, the minimum sampling rate is 1ms with a large performance hit. 1ms is utterly worthless when each game loop is less than 16ms long. :-/

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Member
Posts: 23
Joined: 2010.08
Post: #15
I guess you have already tested out Deferred Display found under File/Record Options for minimal performance hit during sampling.

I found session 309 - Advanced Performance Analysis with Instruments from WWDC10 useful for getting started with Instruments.

The Monkey Hustle - Now available on the App Store!
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Timing issues markhula 8 4,693 Sep 29, 2010 07:56 AM
Last Post: mariocaprino
  Accurate Physics timing bmantzey 29 11,380 Oct 29, 2008 01:13 PM
Last Post: bmantzey