Python Module for Determining CPU Freq. and Memory?

Discussion in 'Python' started by efrat, Apr 6, 2006.

  1. efrat

    efrat Guest

    Hello,

    I'd like to determine at runtime the computer's CPU frequency and
    memory.

    Is there a module for these types of queries? platform.platform returns
    the computer's CPU name and type, but not its frequency; nor does it
    report how much memory the computer has. In the python help(), I
    searched for moudles cpu, but non were found.
    (Please note: I'm interested in hardware stuff, like how much memory the
    machine has; not how much free memory is available.)

    Many Thanks,

    Efrat
     
    efrat, Apr 6, 2006
    #1
    1. Advertising

  2. efrat

    Ron Adam Guest

    efrat wrote:
    > Hello,
    >
    > I'd like to determine at runtime the computer's CPU frequency and memory.
    >
    > Is there a module for these types of queries? platform.platform returns
    > the computer's CPU name and type, but not its frequency; nor does it
    > report how much memory the computer has. In the python help(), I
    > searched for moudles cpu, but non were found.
    > (Please note: I'm interested in hardware stuff, like how much memory the
    > machine has; not how much free memory is available.)
    >
    > Many Thanks,
    >
    > Efrat



    For looking at memory on windows you might be able to make improvements
    to this class I wrote. I was going to add memget() methods for getting
    individual items, but it wasn't as useful as I was hoping it would be
    in checking my python memory use. For that I need info on individual
    tasks, but this might be better for your use.

    Cheers,
    Ron



    from ctypes import *
    from ctypes.wintypes import DWORD

    SIZE_T = c_ulong

    class MemStat(Structure):
    _fields_ = [ ("dwLength", DWORD),
    ("dwMemoryLength", DWORD),
    ("dwTotalPhys", SIZE_T),
    ("dwAvailPhys", SIZE_T),
    ("dwTotalPageFile", SIZE_T),
    ("dwAvailPageFile", SIZE_T),
    ("dwTotalVirtual", SIZE_T),
    ("dwAvailVirtualPhys", SIZE_T) ]
    def update(self):
    windll.kernel32.GlobalMemoryStatus(byref(self))
    def show(self):
    self.update()
    result = []
    for field_name, field_type in self._fields_:
    result.append("%s, %s\n" \
    % (field_name, getattr(self, field_name)))
    return ''.join(result)
    memstat = MemStat()


    if __name__ == '__main__':
    print memstat.show()
     
    Ron Adam, Apr 6, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tim Golden
    Replies:
    1
    Views:
    923
    Michele Petrazzo
    Apr 6, 2006
  2. noroi
    Replies:
    0
    Views:
    563
    noroi
    Oct 18, 2007
  3. pavunkumar

    How , system cpu and user cpu times calculates

    pavunkumar, Feb 27, 2009, in forum: C Programming
    Replies:
    1
    Views:
    376
  4. Dirk Nachbar

    freq function

    Dirk Nachbar, Aug 22, 2010, in forum: Python
    Replies:
    2
    Views:
    555
    Peter Otten
    Aug 22, 2010
  5. nivparsons

    Sync high freq to 100Hz?

    nivparsons, Feb 16, 2012, in forum: VHDL
    Replies:
    2
    Views:
    742
Loading...

Share This Page