Jump to content
  • Advertisement
Sign in to follow this  
Ultimape

How to code profile.

This topic is 4215 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've searched all over the forums for how to profile code, but I always end up with just the suggestions TO profile, nothing else. Is this a functionality of some IDE, or a utility kinda like the gnudebugger? How do you profile your code?

Share this post


Link to post
Share on other sites
Advertisement
Depends really on 3 things:
1. How much money you want to spend
2. What platform you are on
3. What language you are developing in.

The poorman's profiler is to just do:


int start = GetTickCount();

.. run code

int end = GetTickCount();

int totalTime = end - start



This works, but is a pain to use. So you can take the time to write your own full featured profiler like this.

Compuware gives out a toned down freeware (or is it just trial now?) version of its fantastic code profiler. You can find it here.

If you don't have the time or skills for that, then shelling out some cash might be best. There are a few alternatives so look at Wikipedia which has a huge link selection, so peruse them.

If you are on Linux there is one built into the system (I can't remember the name though..).

Hope this helps somewhat.

Share this post


Link to post
Share on other sites
If you use Linux/gcc:

- compile using -pg.
- run the executable
- do $ gprof executablenamehere > resultsfilehere

Maybe there is a windowsport of gprof, I don't really know.

Share this post


Link to post
Share on other sites
Quote:
Original post by hydroo
If you use Linux/gcc:

- compile using -pg.
- run the executable
- do $ gprof executablenamehere > resultsfilehere

Maybe there is a windowsport of gprof, I don't really know.


Ah thats right. =) Can't believe I'd forgotten that, considering I was using that in my last sem's class!

Share this post


Link to post
Share on other sites
Don't use GetTickCount. It has a resolution in the millisecond range. Unless your code is really slow, or you're timing entire frames, you need a higher resolution such as from QueryPerformanceCounter.

Share this post


Link to post
Share on other sites
Quote:
Original post by Deyja
Don't use GetTickCount. It has a resolution in the millisecond range. Unless your code is really slow, or you're timing entire frames, you need a higher resolution such as from QueryPerformanceCounter.

It's more than that though, arbitrary profiling like that tends to produce results that are baised either for or against the code in question. Your code needs to be profiled in the usage domain that is applicable to the situation. The standard method of
Get start time
Do something that is expensive
Get end time

Has several problems in that it doesn't actually mimic a real world usage pattern. For instance, profiling dot product code where you perform a dot product many thousands of times linearly likely isn't a very good benchmark, because you will usually be performing something with the results of the dot product that could introduce more overhead, or that could cause events like cache flushes that could end up being more expensive than your dot product was.

Share this post


Link to post
Share on other sites
Quote:
Original post by Deyja
Don't use GetTickCount. It has a resolution in the millisecond range. Unless your code is really slow, or you're timing entire frames, you need a higher resolution such as from QueryPerformanceCounter.


A lot of people have noticed QPC is buggy on modern processors. timeGetTime with 1ms granularity is probably a safer option. Anyway, continue.

Share this post


Link to post
Share on other sites
Quote:
Original post by skittleo
Quote:
Original post by Deyja
Don't use GetTickCount. It has a resolution in the millisecond range. Unless your code is really slow, or you're timing entire frames, you need a higher resolution such as from QueryPerformanceCounter.

A lot of people have noticed QPC is buggy on modern processors. timeGetTime with 1ms granularity is probably a safer option. Anyway, continue.

Actually, its not buggy, its just that if you do not set the processor affinity, your QPC results will be dependent upon the core that your thread executes on. Windows will attempt to keep your threads localized to a single core, but...not always. As such, due to different execution speeds of the various cores (since clock rates will vary per core), you may end up with different values being returned by QPC. To fix this is simply a matter of setting your processor affinity.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!