How do I get the PC's Processor speed?

K

kyosohma

Hi,

We use a script here at work that runs whenever someone logs into
their machine that logs various bits of information to a database. One
of those bits is the CPU's model and speed. While this works in 95% of
the time, we have some fringe cases where the only thing returned is
the processor name. We use this data to help us decide which PCs need
to be updated, so it would be nice to have the processor speed in all
cases.

Currently, this script is run on Windows boxes only, most of which
have Windows XP on them. Right now I am having Python check the
following registry key for the CPU info: HKEY_LOCAL_MACHINE\HARDWARE\
\DESCRIPTION\\System\\CentralProcessor\\0

I've also used Tim Golden's WMI module like so:

<code>

import wmi
c = wmi.WMI()
for i in c.Win32_Processor ():
cputype = i.Name

</code>

On the problem PCs, both of these methods give me the same information
(i.e. only the processor name). However, if I go to "System
Properties" and look at the "General" tab, it lists the CPU name and
processor speed. Does anyone else know of another way to get at this
information?

Thanks!

Mike
 
C

Chris Mellon

Hi,

We use a script here at work that runs whenever someone logs into
their machine that logs various bits of information to a database. One
of those bits is the CPU's model and speed. While this works in 95% of
the time, we have some fringe cases where the only thing returned is
the processor name. We use this data to help us decide which PCs need
to be updated, so it would be nice to have the processor speed in all
cases.

Currently, this script is run on Windows boxes only, most of which
have Windows XP on them. Right now I am having Python check the
following registry key for the CPU info: HKEY_LOCAL_MACHINE\HARDWARE\
\DESCRIPTION\\System\\CentralProcessor\\0

I've also used Tim Golden's WMI module like so:

<code>

import wmi
c = wmi.WMI()
for i in c.Win32_Processor ():
cputype = i.Name

</code>

On the problem PCs, both of these methods give me the same information
(i.e. only the processor name). However, if I go to "System
Properties" and look at the "General" tab, it lists the CPU name and
processor speed. Does anyone else know of another way to get at this
information?

You'd want the MaxClockSpeed property. There's a few other clock speed
properties as well, see
http://msdn2.microsoft.com/en-us/library/aa394373.aspx.

MSDN should always be your first stop with WMI questions, by the way.
 
K

kyosohma

You'd want the MaxClockSpeed property. There's a few other clock speed
properties as well, seehttp://msdn2.microsoft.com/en-us/library/aa394373.aspx.

MSDN should always be your first stop with WMI questions, by the way.

That's true, but I didn't just use WMI to try to get this information.
I also looked in the registry...although I forgot to mention that I
used the _winreg module to do so.

I did see that when I looked at Microsoft's Python scripts here:
http://www.microsoft.com/technet/scriptcenter/scripts/python/pyindex.mspx?mfr=true

MaxClockSpeed doesn't report the speed the same way MS does in the
System Properties, but I suppose I can work around that. Although this
will make AMD 3800+ procs look much slower (i.e. 2.4 Ghz in this
case).

Mike
 
C

Chris Mellon

That's true, but I didn't just use WMI to try to get this information.
I also looked in the registry...although I forgot to mention that I
used the _winreg module to do so.

I did see that when I looked at Microsoft's Python scripts here:
http://www.microsoft.com/technet/scriptcenter/scripts/python/pyindex.mspx?mfr=true

MaxClockSpeed doesn't report the speed the same way MS does in the
System Properties, but I suppose I can work around that. Although this
will make AMD 3800+ procs look much slower (i.e. 2.4 Ghz in this
case).

System Properties probably uses current clock speed, which will
usually be lower than max clock speed on modern processors, which
scale their speed with load.
 
K

kyosohma

System Properties probably uses current clock speed, which will
usually be lower than max clock speed on modern processors, which
scale their speed with load.

I don't think so. For example, my PC has an "AMD Athlon(tm) 64
Processor 3800+", which is what's reported in System Properties. On
one of the problem PCs, System Properties lists it as "AMD Athlon(tm)
1.73 Ghz".

The 3800+ on my machine is reflected in the registry key I mentioned
and WMI also finds that somewhere. But the 1.73 Ghz is in neither of
these places. However, using MaxClockSpeed and dividing by 1000 along
with some string manipulation gets me closer...although I think this
may cause potential problems.

Thanks for the feedback.

Mike
 
M

Michael Bacarella

On the problem PCs, both of these methods give me the same information
(i.e. only the processor name). However, if I go to "System
Properties" and look at the "General" tab, it lists the CPU name and
processor speed. Does anyone else know of another way to get at this
information?

This information is hardware dependent and probably unreliable.

Why not run a benchmark and report the results instead?
Like bogomips? <URL:http://en.wikipedia.org/wiki/Bogomips>
 
?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

On the problem PCs, both of these methods give me the same information
(i.e. only the processor name). However, if I go to "System
Properties" and look at the "General" tab, it lists the CPU name and
processor speed. Does anyone else know of another way to get at this
information?

I'm not sure whether it is *this* information, but you can use
NtQuerySystemInformation, with a class parameter of
SystemProcessorPowerInformation, and passing
SYSTEM_PROCESSOR_POWER_INFORMATION as the buffer. That gives,
among others, a value CurrentFrequency (along with LastBusyFrequency,
LastC3Frequency, and ThermalLimitFrequency).

This usage of NtQuerySystemInformation is undocumented.

Regards,
Martn
 
K

kyosohma

This information is hardware dependent and probably unreliable.

Why not run a benchmark and report the results instead?
Like bogomips? <URL:http://en.wikipedia.org/wiki/Bogomips>

That's an interesting idea, but this is in a login script, so I can't
exactly run benchmarks while logging in as the users will get
impatient quite quickly. They already think the scripts take too long
as it is.

While this information may be unreliable, it is desired by my boss for
the express purpose of budgeting upgrades in our organization.

Thanks!

Mike
 
K

kyosohma

I'm not sure whether it is *this* information, but you can use
NtQuerySystemInformation, with a class parameter of
SystemProcessorPowerInformation, and passing
SYSTEM_PROCESSOR_POWER_INFORMATION as the buffer. That gives,
among others, a value CurrentFrequency (along with LastBusyFrequency,
LastC3Frequency, and ThermalLimitFrequency).

This usage of NtQuerySystemInformation is undocumented.

Regards,
Martn

Is this a WMI function or a PyWin32 function? I guess I'm not seeing
how to actually implement this in Python. Sounds intriguing though.

Mike
 
C

Chris Mellon

That's an interesting idea, but this is in a login script, so I can't
exactly run benchmarks while logging in as the users will get
impatient quite quickly. They already think the scripts take too long
as it is.

While this information may be unreliable, it is desired by my boss for
the express purpose of budgeting upgrades in our organization.

For this purpose, the make/model of the CPU is probably much more
useful than any measure (maximum or scaled) of the actual clock speed.
Incidentally, it's also faster to gather.
 
M

Michael Bacarella

This information is hardware dependent and probably unreliable.
That's an interesting idea, but this is in a login script, so I can't
exactly run benchmarks while logging in as the users will get
impatient quite quickly. They already think the scripts take too long
as it is.

Bogomips can be easily calculated in 10ms. The Linux kernel calculates it
during
system boot. There's an ANSI C utility floating around that you could
distribute.
Just a thought...
While this information may be unreliable, it is desired by my boss for
the express purpose of budgeting upgrades in our organization.

The information that gets displayed in the System Properties / General tab
is,
I believe, a string copied out of the CPU. I've had systems where it used
to simply say "Pentium" in that box as well. That's why it strikes me as
unreliable.

Executing the CPUID instruction may be helpful if you can figure out how
these guys are using it:
http://www.cpuid.com/cpuz.php
 
K

kyosohma

Bogomips can be easily calculated in 10ms. The Linux kernel calculates it
during
system boot. There's an ANSI C utility floating around that you could
distribute.
Just a thought...


The information that gets displayed in the System Properties / General tab
is,
I believe, a string copied out of the CPU. I've had systems where it used
to simply say "Pentium" in that box as well. That's why it strikes me as
unreliable.

Executing the CPUID instruction may be helpful if you can figure out how
these guys are using it:
http://www.cpuid.com/cpuz.php

Good point. I'm not sure where to start, but I may give it a whack
tomorrow if things stay quiet.

Thanks,

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top