Be the first to rate this file! 9 Downloads (last 30 days) File Size: 45.9 KB File ID: #26662
image thumbnail

System Information Class for Windows

by Xin Zhao

 

12 Feb 2010 (Updated 20 Feb 2010)

This class will query the current system information in MATLAB. Works with R2009a and up.

| Watch this File

File Information
Description

Recently, we just got an interesting question about how to measure the CPU usage of current MATLAB process.

Frankly speaking, during my more than 5 years working in The MathWorks, I never thought we can do it inside MATLAB. But with the recent and excellent .Net support, this is actually quite easy and straightforward.

This class, wrapping all the basic information regarding to you Windows machine, gives you full knowledge of the performance you may want to know.

the detailed information includes:
1. Machine Name, Total Physical Memory, Processor(CPU) information
2. CPU usage in %
3. Memory usage in MB

the class has one important public method called 'measure', every time you call it, it will measure and store the CPU usage and memory usage.

the class has been tested in Winxp, Vista(SP1), Windows 7, but feel free to send me fix requests.

At the end there is a demo of using this class.
1. run startRecordPerformance
2. do what ever you want to do, (don't use clear all, of course)
3. run stopRecordAndDisplay
4. do your clean up, say 'delete(perfData), delete(t)'

Note: I am working on a GUI version for performance measurement purpose(using this class of course), so I need the processor information.
But this info needs to read the registry of windows, and it makes the class initialization slow. Unfortunately that's the only easy way I know in MATLAB, so if you don't need it, delete the specific lines in the class.

Acknowledgements

This file inspired System Resource Monitor For Windows.

MATLAB release MATLAB 7.9 (R2009b)
Other requirements Windows Only
Tags for This File  
Everyone's Tags
cpu(2), memory, performance, processor
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (8)
15 Apr 2013 Kushal Khaitan

Is it so that the output value I get gives me the exact CPU usage & memory utilized by that process?

13 Apr 2012 Kausihan

hi i am getting the following error. i use the 64 bit matlab r2010a
??? Error using ==> SysInfoData>SysInfoData.SysInfoData at 48
Message: Category does not exist.
Source: System
HelpLink:

02 Jul 2010 fiza khalid

>>plz tell me how i can run it with my function to calculate the memory and cpu use for the process that i am running.
>>do help me i need to know thnx in advance.

20 Feb 2010 Xin Zhao

UPDATE-FEB 20, 2010
This class does not work the R2008b and previous MATLAB verions. thanks for the feedbacks from nav0239 and ali.

For R2009a, there is a new syntax in R2009b not supported, just made the changes to use the old syntax.
now it works fine with R2009a and up.

18 Feb 2010 Xin Zhao

nav0239,
it looks your machine somehow does not work with .Net with MATLAB. I didn't test R2008b, but it should work with .Net

what if you try
NET.addAssembly('System')

more details here.
http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_external/brpb5k6.html

17 Feb 2010 nav0239

>> startRecordPerformance
??? Undefined variable "System" or class "System.Environment.MachineName".

Error in ==> SysInfoData>SysInfoData.SysInfoData at 43
obj.MachineName = char(System.Environment.MachineName);

I am running 2008b.

17 Feb 2010 Xin Zhao

hi Ali,
which version of MATLAB you are using?
it looks the 'memory' command is not working as in R2009b or R2009a.
to verify that, try
[a,b] = memory; b.SystemMemory.Available

for details
http://www.mathworks.com/access/helpdesk/help/techdoc/ref/memory.html

17 Feb 2010 ali

Reference to non-existent field 'SystemMemory'.

Error in ==> SysInfoData>SysInfoData.SysInfoData at 36
obj.TotalMemory = round(systemview.SystemMemory.Available/1024^2);

what is the reason

Updates
20 Feb 2010

UPDATE-FEB 20, 2010
This class does not work the R2008b and previous MATLAB versions. For R2009a, there is a new syntax in R2009b not supported, just made the changes to use the old syntax.
now it works fine with R2009a and up.

Contact us