LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

CPU performance monitor?

Hi,

 

I'd like to write a module which displays CPU and memory usage to the user similar to what is visible in the task manager / performance monitor window. I have found >>>this<<< article which is cool, but not quite what I need. See the chart below:

 

1984_0-1686645503015.png

 

My PC has 4 cores with 2 logical cores each, so I put 8 graphs on the chart each representing the load of a given logical processor. Then (at about the middle) I launched a VI which has nothing but a while loop with a false constant at its conditional terminal. 

 

In the task manager I saw what I expected: one of the cores got compeletely busy with the VI so the CPU load increased to about 25% and stayed there (I didnt have any other load on the CPUs except this VI so 25-26% looks good). In my VI though the logical cores went up and down and it was not even that a given core take the full load, but it seems the task changed cores. I dont know if this is possible at all, I'm not an expert on this subject, but this is what my graph suggests.

 

What I have in my VI could have more details, but for me and for a regular user is a lot less informative, so I'm wondering if there is a way to get values diplayed by the task manager directly?

 

(Using Windows11. I took a sample from the CPU load in every 1000ms and displaying the average of the last four samples)

 

Thanks.

0 Kudos
Message 1 of 17
(1,495 Views)

I using pdh.dll to obtain these counters:

Multi Core CPU Snippet.png

and they matched Task Manager values (more or less, you might need to have some minor averaging and rescaling to get 1:1 visual appearance):

Screenshot 2023-06-13 11.38.49.png

Andrey.

Message 2 of 17
(1,469 Views)

Could you convert this back to LV2022?

0 Kudos
Message 3 of 17
(1,463 Views)

@1984 wrote:

Could you convert this back to LV2022?


Yes, sure, downgraded to LV2022 in attachment.

Message 4 of 17
(1,450 Views)

@1984 wrote:

I'm wondering if there is a way to get values diplayed by the task manager directly?

 


you can get the taskmanager values via windows' perfmon.exe, which is part of Windows 11

perfmon can also be used to create a logfile

but the whole .exe is sort of clumsy to use.

 

a good soul wrote this dot net wrapper for LabView, which I tested with LabView 2020 64bit and Windows 10

https://forums.ni.com/t5/Example-Code/Performance-Monitor-Using-LabVIEW/ta-p/3501988

 

Message 5 of 17
(1,444 Views)

Hi Andrey,

 

what about a VI version for the pre-subscription era?

Could you downconvert to LV2019 or LV2021?

Thanks!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 17
(1,418 Views)

@GerdW wrote:

Hi Andrey,

 

what about a VI version for the pre-subscription era?

Could you downconvert to LV2019 or LV2021?

Thanks!


You're welcome! Attached in LabVIEW 2018. That was an issue with 32-bit, because 64 bit was hard coded, but now should work for both 32-bit and 64-bit LabVIEW.

In general its doesn't matter how performance counters are obtained, in theory the .net - based solution should output exactly the same measurements. But usually if a have a choice to stay dependent from pure DLL or .net assembly, then I choosing DLL (in the past got some troubles with very old code and .net).

On the other hand, on Windows 11 I have seen some strange differences in term of CPU load and memory usage appeared in Task Manager compared to other tools like SysInternals.

Andrey.

Message 7 of 17
(1,384 Views)

Hi Andrey,

 

thanks for your effort, but with LV2021/32bit on Win11Pro22H2 I don't get any useful CPU load data, just "zero" load for all cores.

 

I have to investigate that behaviour when I have some more time…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 8 of 17
(1,351 Views)

@Andrey_Dmitriev wrote:

@1984 wrote:

Could you convert this back to LV2022?


Yes, sure, downgraded to LV2022 in attachment.


Hey Andrey. Actually same here, your code does not work on my PC (win11). The dll call throws an error even if I browse the dll and add it to the call library node.

0 Kudos
Message 9 of 17
(1,347 Views)

@GerdW wrote:

Hi Andrey,

 

thanks for your effort, but with LV2021/32bit on Win11Pro22H2 I don't get any useful CPU load data, just "zero" load for all cores.

 

I have to investigate that behaviour when I have some more time…


Ah, its because you're under non-English OS with very big probability. For example, for German it should be "\\Prozessor(%d)\\Prozessorzeit (%%)" instead of "\\Processor(%d)\\%% Processor Time". Or, better, to use language neutral PdhAddEnglishCounterA() function. Good to know, thank you.

Try attached one, probably should work for you:

Message 10 of 17
(1,319 Views)