dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 14 of 14

Thread: Processor Speed

  1. #1
    Join Date
    Oct 2003
    Posts
    133

    Processor Speed

    Is there a function to get the Proc. speed? I know where the reg key is stored, but it's not always there on every machine. However 98% of the time I see in the MSINFO32 tool, so they must be getting it from somewhere...

  2. #2
    Join Date
    Sep 2002
    Location
    Belarus - Tirol, Austria
    Posts
    647
    What platform do U mean?
    For NT-based, U can look at PDH library. It provides access for a lot of information exported by the kernel.
    The same access is provided with the hiden registry hive (I cannot recollect its name now).
    U can read about it in MSDN. Some samples have place in SDK too.
    "UNIX is simple; it just takes a genius to understand its simplicity!"

  3. #3
    Join Date
    Sep 2002
    Location
    Maryland - Fear The Turtle!
    Posts
    7,537
    you can use WMI... Win32_Processor class

    http://msdn.microsoft.com/library/de..._processor.asp

    Code:
    instance of Win32_Processor
    {
    	AddressWidth = 32;
    	Architecture = 0;
    	Availability = 3;
    	Caption = "x86 Family 15 Model 2 Stepping 9";
    	CpuStatus = 1;
    	CreationClassName = "Win32_Processor";
    	CurrentClockSpeed = 2392;
    	CurrentVoltage = 33;
    	DataWidth = 32;
    	Description = "x86 Family 15 Model 2 Stepping 9";
    	DeviceID = "CPU0";
    	ExtClock = 133;
    	Family = 2;
    	L2CacheSize = 0;
    	Level = 15;
    	LoadPercentage = 9;
    	Manufacturer = "GenuineIntel";
    	MaxClockSpeed = 2392;
    	Name = "              Intel(R) Pentium(R) 4 CPU 2.40GHz";
    	PowerManagementSupported = FALSE;
    	ProcessorId = "BFEBF9FF00000F29";
    	ProcessorType = 3;
    	Revision = 521;
    	Role = "CPU";
    	SocketDesignation = "Microprocessor";
    	Status = "OK";
    	StatusInfo = 3;
    	Stepping = "9";
    	SystemCreationClassName = "Win32_ComputerSystem";
    	SystemName = "FOOBAR";
    	UpgradeMethod = 6;
    	Version = "Model 2, Stepping 9";
    	VoltageCaps = 2;
    };

  4. #4
    Join Date
    Oct 2003
    Posts
    133
    My problem seems to be with 9x based machines, there doesn't seem to be any way to get the speed except for looking at the BIOS on a reboot. That wouldn't be a problem except I can't reboot these machines The msinfo32 tool usually just reports something generic like "Genuine Intel Step 2", never the clock speed

  5. #5
    Join Date
    Jun 2003
    Location
    Heck-:D-Hokkaido.
    Posts
    47
    Originally posted by High_D
    My problem seems to be with 9x based machines, there doesn't seem to be any way to get the speed except for looking at the BIOS on a reboot. That wouldn't be a problem except I can't reboot these machines The msinfo32 tool usually just reports something generic like "Genuine Intel Step 2", never the clock speed
    You might be correct
    Honestly before you posted your post I quote, I thought of posting http://xaxxon.slackworks.com/rsapi/ for you to reference and to run after those so that I think I can have them feel something for my competition,
    sigh- That's really like how easy it is to let people see such a stupid psychological reaction of mine.

    Regards,

    -Vu
    Last edited by VuQ_Le; January 22nd, 2004 at 08:49 AM.

  6. #6
    Join Date
    Jun 2002
    Location
    Germany
    Posts
    1,557
    Well,

    I actually wrote the following attatched file recently for educational purposes. It is really fresh off the press. For Win2k, NT, XP it reads the registry. Whereas for Win9x it simply times the clock straight out in a repeated loop using the Windows tick. The complete testing, especially for Win9x platforms, is still in progress, so there is no guarantee here.

    There is a whole bunch of stuff related to the CPU identification and the clock.

    It is compatible with VC6, VC.NET and GCC. There are similar samples scattered all over the net but you rarely find parallel support for VC and GCC within the same file.

    Take a look at the methods within the project.

    Sincerely, Chris.

    Attached Files Attached Files
    You're gonna go blind staring into that box all day.

  7. #7
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266
    Did you try Mick's suggestion? Note that you can use a scripting language such as JavaScript to do a quick test to see what you would get using WMI.
    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

  8. #8
    Join Date
    Sep 2002
    Location
    Maryland - Fear The Turtle!
    Posts
    7,537
    I don't recall if win9x returns the processor info, when you install WMI on it. Some of the WIN32 classes under win9x don't return information. Don't have a 9x system to test on. But someone who has WMI installed on a win9x machine could just issue WBEMTEST.exe, enum the root\cimv2 namespace and see if it does...

  9. #9
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266
    I have seen WBEMTEST.exe mentioned in my odler version of MSDN but I can't find it to download and I think it is not mentioned in the current MSDN. I assume there is a replacement but I can't find anything saying what the replacement is.
    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

  10. #10
    Join Date
    Sep 2002
    Location
    Maryland - Fear The Turtle!
    Posts
    7,537
    Originally posted by Sam Hobbs
    I have seen WBEMTEST.exe mentioned in my odler version of MSDN but I can't find it to download and I think it is not mentioned in the current MSDN. I assume there is a replacement but I can't find anything saying what the replacement is.
    it's shipped with all system??? (well maybe not 9x until you install the WMI subsystem)

    %systemroot%\system32\wbem\wbemtest.exe

  11. #11
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266
    Yes, it is there. I did search everywhere for it, so I don't know why I could not find it. Maybe a poltergeist in my system.
    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

  12. #12
    Join Date
    May 2000
    Location
    Washington DC, USA
    Posts
    715

    there is a better way

    just count the number of clock cycles in a second and devide by 1,000,000.. of if you want to get fancy you can use mod...

    Ahhhh assemble code.. finally...

    Code:
    #define WIN32_LEAN_AND_MEAN
    #include <windows.h>
    #include <tchar.h>
    #include <stdio.h>
    #include <string.h>
    
    
    #pragma once
    #pragma warning(disable : 4035)
    
    inline unsigned __int64 GetCycleCount(void)
    {
        _asm    _emit 0x0F
        _asm    _emit 0x31
    }
    
    class MyTimer
    {
        unsigned __int64  m_startcycle;
    
    public:
    
        unsigned __int64  m_overhead;
    
        MyTimer(void)
        {
            m_overhead = 0;
            Start();
            m_overhead = Stop();
        }
        
        void Start(void)
        {
            m_startcycle = GetCycleCount();
        }
    
        unsigned __int64 Stop(void)
        {
            return GetCycleCount() - m_startcycle-m_overhead;
        }
    };
    
    
    int main()
    {
        MyTimer timer;
    
        timer.Start();                // take initial reading
        Sleep(1000);                // wait a second 
        unsigned cpuspeed10 = (unsigned)(timer.Stop()/100000);
                                            // take the elapsed # of cycles and
                                            // divide by 100,000...
    
        printf("CPU speed       %d.%d mhz\n",
            cpuspeed10 / 10,  cpuspeed10 % 10 );
    
                                           // divide by 10 more gives you mhz
                                           // the mode gives you the decimal..
    
    	return 0;
    
    }

    output :
    CPU speed 2324.33 mhz

    what could be simpler..

  13. #13
    Join Date
    Sep 2002
    Location
    Maryland - Fear The Turtle!
    Posts
    7,537

    Re: there is a better way

    Originally posted by JMS

    what could be simpler..
    Since there was a reference to MSINFO.....
    it depends on what context you place it in, for system management information in a local or distruibuted enviroment, cimv2 (WMI) is simpler.

  14. #14
    Join Date
    May 2000
    Location
    Washington DC, USA
    Posts
    715
    Is there a function to get the Proc. speed?
    Mick, why the sour grapes?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)