File Exchange

image thumbnail

CPU Info

version 1.1.0.1 (3.2 KB) by Ben Tordoff
Read various bits of information about the CPU and operating system.

10 Downloads

Updated 01 Sep 2016

View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

This function reads various bits of information about the CPU and operating
system, including:

* CPU name

* CPU clock speed

* CPU Cache size (L2)

* Number of physical CPU cores

* Operating system name & version

These are provided by /proc/cpu (Unix), sysctl (Mac) or WMIC (Windows).

Requires MATLAB R2010a or above.

Comments and Ratings (7)

Great function! I've modified it for the machines I use which have multiple CPUs, where this only detects the first CPU.

Multi Socket motherboards in Linux can be added in the following way :

function info = parseCPUInfoText( txt )
% Now parse the fields
lookup = {
'model name', 'Name'
'cpu Mhz', 'Clock'
'cpu cores', 'NumCores'
'cache size', 'Cache'
'physical id', 'NumCPUs'};
info = struct( ...
'Name', {''}, ...
'Clock', {''}, ...
'Cache', {''} );
for ii=1:numel( txt )
if isempty( txt{ii} )
continue;
end
% Look for the colon that separates the property name from the value
colon = find( txt{ii}==':', 1, 'first' );
if isempty( colon ) || colon==1 || colon==length( txt{ii} )
continue;
end
fieldName = strtrim( txt{ii}(1:colon-1) );
fieldValue = strtrim( txt{ii}(colon+1:end) );
if isempty( fieldName ) || isempty( fieldValue )
continue;
end

% Is it one of the fields we're interested in?
idx = find( strcmpi( lookup(:,1), fieldName ) );
if ~isempty( idx )
newName = lookup{idx,2};
info.(newName) = fieldValue;
end
end

% Convert clock speed
info.Clock = [info.Clock, ' MHz'];

% Convert num cores
info.NumCores = str2double( info.NumCores );

% convert num cpus and figure out total core count
info.NumCPUs = str2num(info.NumCPUs) + 1;
info.TotalCores = info.NumCPUs * info.NumCores;

David

Nice Job!
This did exactly what I was looking for.

nikolat

Ben Tordoff

Hi Daniel, I don't know much about CPU serial numbers, but from what I've read they don't exist in modern CPUs. See e.g.: http://en.wikipedia.org/wiki/Processor_Serial_Number#Controversy_about_privacy_issues

When I ask for the serial on my CPUs (on linux) I just get "none specified".

It might be possible to get the motherboard serial number, although I haven't managed to get it on Linux without sudo'ing (not a problem on Windows as far as I can tell).

What is it you want to achieve?

Cheers. Ben

Daniel Dolan

This function does exactly what it says it should. Is there a way to pull a serial number from the CPU?

Stephen

Updates

1.1.0.1

Updated license

1.1.0.0

Fix for multi-socket Windows boxes.

MATLAB Release Compatibility
Created with R2010a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Acknowledgements

Inspired: detectOS