Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Finding CPU stats on Win32?

by sh1tn (Priest)
on Apr 15, 2005 at 18:47 UTC ( [id://448310]=note: print w/replies, xml ) Need Help??


in reply to Finding CPU stats on Win32?

You may want to take a look at Scriptomatic 2.0 which is script generator:
use strict; use Win32::OLE('in'); use constant wbemFlagReturnImmediately => 0x10; use constant wbemFlagForwardOnly => 0x20; my @computers = ("localhost"); foreach my $computer (@computers) { print "\n"; print "==========================================\n"; print "Computer: $computer\n"; print "==========================================\n"; my $objWMIService = Win32::OLE->GetObject("winmgmts:\\\\$computer\\ +root\\CIMV2") or die "WMI connection failed.\n"; my $colItems = $objWMIService->ExecQuery("SELECT * FROM Win32_Proce +ssor", "WQL", wbemFlagReturnImmediately | wbemFlagForwardOnly); foreach my $objItem (in $colItems) { print "AddressWidth: $objItem->{AddressWidth}\n"; print "Architecture: $objItem->{Architecture}\n"; print "Availability: $objItem->{Availability}\n"; print "Caption: $objItem->{Caption}\n"; print "ConfigManagerErrorCode: $objItem->{ConfigManagerErrorCode +}\n"; print "ConfigManagerUserConfig: $objItem->{ConfigManagerUserConf +ig}\n"; print "CpuStatus: $objItem->{CpuStatus}\n"; print "CreationClassName: $objItem->{CreationClassName}\n"; print "CurrentClockSpeed: $objItem->{CurrentClockSpeed}\n"; print "CurrentVoltage: $objItem->{CurrentVoltage}\n"; print "DataWidth: $objItem->{DataWidth}\n"; print "Description: $objItem->{Description}\n"; print "DeviceID: $objItem->{DeviceID}\n"; print "ErrorCleared: $objItem->{ErrorCleared}\n"; print "ErrorDescription: $objItem->{ErrorDescription}\n"; print "ExtClock: $objItem->{ExtClock}\n"; print "Family: $objItem->{Family}\n"; print "InstallDate: $objItem->{InstallDate}\n"; print "L2CacheSize: $objItem->{L2CacheSize}\n"; print "L2CacheSpeed: $objItem->{L2CacheSpeed}\n"; print "LastErrorCode: $objItem->{LastErrorCode}\n"; print "Level: $objItem->{Level}\n"; print "LoadPercentage: $objItem->{LoadPercentage}\n"; print "Manufacturer: $objItem->{Manufacturer}\n"; print "MaxClockSpeed: $objItem->{MaxClockSpeed}\n"; print "Name: $objItem->{Name}\n"; print "OtherFamilyDescription: $objItem->{OtherFamilyDescription +}\n"; print "PNPDeviceID: $objItem->{PNPDeviceID}\n"; print "PowerManagementCapabilities: " . join(",", (in $objItem-> +{PowerManagementCapabilities})) . "\n"; print "PowerManagementSupported: $objItem->{PowerManagementSuppo +rted}\n"; print "ProcessorId: $objItem->{ProcessorId}\n"; print "ProcessorType: $objItem->{ProcessorType}\n"; print "Revision: $objItem->{Revision}\n"; print "Role: $objItem->{Role}\n"; print "SocketDesignation: $objItem->{SocketDesignation}\n"; print "Status: $objItem->{Status}\n"; print "StatusInfo: $objItem->{StatusInfo}\n"; print "Stepping: $objItem->{Stepping}\n"; print "SystemCreationClassName: $objItem->{SystemCreationClassNa +me}\n"; print "SystemName: $objItem->{SystemName}\n"; print "UniqueId: $objItem->{UniqueId}\n"; print "UpgradeMethod: $objItem->{UpgradeMethod}\n"; print "Version: $objItem->{Version}\n"; print "VoltageCaps: $objItem->{VoltageCaps}\n"; print "\n"; } }sub WMIDateStringToDate(strDate) { return "blah"; } __END__ STDOUT: C:\scripts>t.pl ========================================== Computer: localhost ========================================== AddressWidth: 32 Architecture: 0 Availability: 3 Caption: x86 Family 6 Model 6 Stepping 2 ConfigManagerErrorCode: ConfigManagerUserConfig: CpuStatus: 1 CreationClassName: Win32_Processor CurrentClockSpeed: 1607 CurrentVoltage: 18 DataWidth: 32 Description: x86 Family 6 Model 6 Stepping 2 DeviceID: CPU0 ErrorCleared: ErrorDescription: ExtClock: 133 Family: 29 InstallDate: L2CacheSize: 256 L2CacheSpeed: 535 LastErrorCode: Level: 6 LoadPercentage: 4 Manufacturer: AuthenticAMD MaxClockSpeed: 1607 Name: AMD Athlon(tm) XP 1900+ OtherFamilyDescription: PNPDeviceID: PowerManagementCapabilities: PowerManagementSupported: 0 ProcessorId: 0383FBFF00000662 ProcessorType: 3 Revision: 1538 Role: CPU SocketDesignation: Socket A Status: OK StatusInfo: 3 Stepping: 2 SystemCreationClassName: Win32_ComputerSystem SystemName: MOMULECHE UniqueId: UpgradeMethod: 14 Version: Model 6, Stepping 2 VoltageCaps:


Replies are listed 'Best First'.
Re^2: Finding CPU stats on Win32?
by guice (Scribe) on Apr 15, 2005 at 20:13 UTC
    Wow nice! Now if I can only find out if there's a way to view if Hyperthreading it turned on/off or possible...

    -- philip
    We put the 'K' in kwality!

      Detecting hyperthreading has to be done from assembler, and I'm not aware of any Win32 API that provides that information. There is an article on the Intel website that explains the intracacies.

      Update: Here's an implementation in D. It should be trivial to convert to C.

      import std.stream; import std.stdio; void main ( ) { int ht_supported = 0; int cores_per_socket = 1; asm{ mov EAX, 0; cpuid; test EAX, 0x10000000; jz NO_HYPER; mov ht_supported, 1; mov EAX, 4; cpuid; and EAX, 0xfc000000; shr EAX, 26; add EAX, 1; mov cores_per_socket, EAX; NO_HYPER:; }; if( ht_supported ) { printf( "Hyperthreading is supported and there are %d cores pe +r cpu\n", cores_per_socket ); } else { printf( "Hyperthreading is not supported on this processor\n" +); } }

      Update2: I also turned up this quite comprehensive cpu features detector sample on MSDN


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco.
      Rule 1 has a caveat! -- Who broke the cabal?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://448310]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-03-29 01:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found