How to code profile.

Started by
15 comments, last by Rockoon1 17 years, 1 month ago
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?
Advertisement
A good free profiler is AMD Codeanalyst. Although it's from AMD, it also works on Intel processors.
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 codeint 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.
Of course if you use Dev-C++ you can use the simple built in profiler.
_______________ Play my Game at neonswarm.com
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.
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!
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.
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 expensiveGet 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.

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

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.
....[size="1"]Brent Gunning
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.

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

This topic is closed to new replies.

Advertisement