Created
September 22, 2012 10:37
-
-
Save takehiko/3765789 to your computer and use it in GitHub Desktop.
Get processor name, number of processors and clock speed using Win32OLE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# -*- coding: utf-8 -*- | |
# cpuinfo.rb : get processor name, number of processors and clock speed | |
# using Win32OLE | |
require "win32ole" | |
wmi = WIN32OLE.connect("winmgmts://") | |
query = wmi.ExecQuery("select * from Win32_Processor") | |
cpuinfo = nil | |
query.each {|obj| cpuinfo = obj; break} | |
name = cpuinfo.name | |
name_str = name.gsub(/\s{2,}/, " ") | |
core = cpuinfo.NumberOfLogicalProcessors | |
core_str = core > 1 ? " x #{core}" : "" | |
clock = cpuinfo.CurrentClockSpeed | |
clock_str = " (#{clock}MHz)" | |
puts [name_str, core_str, clock_str].join | |
# http://www.tech-notes.dyndns.org/wmi/ | |
# http://www.wmifun.net/library/win32_processor.html | |
# http://q.hatena.ne.jp/1269364904 | |
# grep model.name /proc/cpuinfo | sed -e 's/.*: //' | uniq -c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment