Skip to main content
GameDev.net gamedev.net
🔒 Locked

Profiling Multithreaded Code (How to get CPU time per thread?)

Started by Telamon Mar 30, 2007 at 1:01 PM 4 replies 2.2k views
Original Post
Telamon
Telamon
I have two threads in my game, one for network and one for physics. I want to profile them both so that I know what percentage of the CPU is being used by each. I want to count CPU time (or CPU cycles, if you like), but ignore wall time (like when a thread is sleeping). So for example:

StartCounting();
sleep(2500);
double time = StopCounting();
time would equal something close to 0 instead of close to 2500. Can the Win XP performance counters be used for this? How would I do that? This is C++ (I suppose it might be easier in .Net?) Many thanks!
Agony
Agony
I believe you'll find the Win32 API functions GetThreadTimes() and GetProcessTimes() useful.
"We should have a great fewer disputes in the world if words were taken for what they are, the signs of our ideas nly, and not for things themselves." - John Locke o
ApochPiQ
ApochPiQ
I highly recommend a full profiler like AMD's CodeAnalyst, which directly supports many ways of investigating performance in threaded applications. The main advantage over just looking at raw thread runtimes is that it can show you exactly where your code is spending its time, which makes it invaluable for optimizing your locking strategies and so on.
l0calh05t
l0calh05t
Will code analyst work correctly on Intel machines? (APL does which is great)
ApochPiQ
ApochPiQ
Runs on my Core Duo and Core 2 Duo just fine. There's some low-level, CPU-based options which aren't available, but I've never had cause to use them so I don't miss them - to be perfectly honest I don't even recall what they are [smile]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.