Example Code

Reference Example of a System Monitor displaying CPU and Memory Usage

Code and Documents

Attachment

Overview


In some applications it is desirable to be able to monitor and track certain system parameters for diagnostics and optimization of the application. iThe attached example shows how to read the current CPU and memory usage on a Windows machine in LabVIEW.

The attached reference example includes subVIs to read the current CPU usage and memory usage of a Windows machine.

These VIs read information using functions available in standard Windows DLLs and will not work on other platforms. They have been tested  in Windows XP, but not other versions of Windows to date.

Figure 1: System Monitor example VI

CPU Usage

There are three subVIs to monitor CPU usage as the Windows SDK requires you to initialize and configure a query which you can then execute many times to retrieve the current CPU usage level. You should not call the Tools_System CPU Usage VI more than once per second in order to allow the monitor to adequately average the measured data.

Figure 2: Example diagram showing the use of the CPU Usage VIs

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Contributors