06-13-2023 03:48 AM - edited 06-13-2023 04:10 AM
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:
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.
06-13-2023 04:53 AM - edited 06-13-2023 04:54 AM
I using pdh.dll to obtain these counters:
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):
Andrey.
06-13-2023 04:59 AM
Could you convert this back to LV2022?
06-13-2023 05:13 AM
@1984 wrote:
Could you convert this back to LV2022?
Yes, sure, downgraded to LV2022 in attachment.
06-13-2023 05:16 AM - edited 06-13-2023 05:27 AM
@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
06-13-2023 06:03 AM
06-13-2023 09:25 AM - edited 06-13-2023 09:26 AM
@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.
06-13-2023 01:40 PM
06-13-2023 01:44 PM
@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.
06-14-2023 03:16 AM
@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: