Jump to content
  • Advertisement
Sign in to follow this  
Toolmaker

[.net] HighPerformanceCounters and .NET

This topic is 4253 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'm currently moving my old codebase from a single core system to a dual-core system, and I ran into the dual-core issues where most people have ran into. I did some research, and I know I have to set the ProcessorAffinity before querying the performance counter. HOWEVER, even when I call Thread.BeginThreadAffinity(), I still see no change. Any idea on how I can fix this? Or does .NET come with a built-in HighPerformanceCounter? Toolmaker

Share this post


Link to post
Share on other sites
Advertisement
I just use DateTime.Now, which supposedly has a resolution of 10ms.

For sound, however, that needs to be a bit tighter so I've also used the multimedia timers via P/Invoke.

Share this post


Link to post
Share on other sites
Quote:
Original post by benryves
I just use DateTime.Now, which supposedly has a resolution of 10ms.

For sound, however, that needs to be a bit tighter so I've also used the multimedia timers via P/Invoke.


Which timers do you use? Right now, I use QueryHighPerformanceCounter, but that doesn't work really well on a dual-core system. Perhaps I should just P/Invoke the SetThreadAffinityMask and use that before calling QHPC.

Toolmaker

Share this post


Link to post
Share on other sites
Quote:
Original post by Toolmaker
Which timers do you use?
These ones, which go down to 1ms resolution. I was using these timers to schedule events (ie, call a callback in 12ms time) rather than extract the precise system time, which is not quite what you want.

Quote:
Right now, I use QueryHighPerformanceCounter, but that doesn't work really well on a dual-core system.
Have you tried manually setting the affinity of the process in Task Manager to see if that resolves the issue? I'm afraid I'm rather old fashioned and as such don't have a multiple-CPU machine to test on.

Share this post


Link to post
Share on other sites
It's probably a bug in my code I'm afraid. I just updated my timers and right now, I'm usign this:

FpsCounter.StartFrame();
System.Threading.Thread.Sleep(800);
double d = FpsCounter.EndFrame();


And d contains a value around 0.8, which is correct. So it's probably a bug in my codebase, which I haven't touched in a few months.

Toolmaker

Share this post


Link to post
Share on other sites
If you're looking for a managed wrapper around QueryPerformanceCounter, .NET 2.0 introduced the System.Diagnostics.StopWatch class.

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!