LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

get cpu usage programatically

Is there anyway to receive total CPU usuage and cpu usuage by a program programatically?
Thanks.
CVI 2010
LabVIEW 2011 SP1
Vision Builder AI 2011 SP1
0 Kudos
Message 1 of 20
(6,508 Views)

Hello Sheetal,

Take a look at the .NET example: c:\Program Files\National Instruments\CVI80\samples\dotnet\SimpleTaskMonitor

I never looked at the code, but it seems to me that this kinda does what you are looking for.

Good luck

Message Edited by Wim S on 03-01-2007 09:35 AM

Message 2 of 20
(6,467 Views)
Hi,
Thanks for your reply. This is exactly what I need. Only problem is CPU activity is always 0!
Thanks.
CVI 2010
LabVIEW 2011 SP1
Vision Builder AI 2011 SP1
0 Kudos
Message 3 of 20
(6,449 Views)
Are you sure you have the .NET Framework installed? This example should give you CPU usage as long as it can make calls to .NET.

Brandon Vasquez | Software Engineer | Integration Services | National Instruments
Message 4 of 20
(6,428 Views)
i have framework 2.0 installed.
Thanks.
CVI 2010
LabVIEW 2011 SP1
Vision Builder AI 2011 SP1
0 Kudos
Message 5 of 20
(6,430 Views)
I verified this on another PC and same results. CPU usuage is always 0. I do have framework 2.0 installed. CVI version 8.0.1.
Thanks.
CVI 2010
LabVIEW 2011 SP1
Vision Builder AI 2011 SP1
0 Kudos
Message 6 of 20
(6,418 Views)
Do you see anything?  Does the memory usage change at all and does it list the current processes?  Are either of these machines dual core machines?  Because it could be possible that the line that sets up the performance counter for the processor could be different if you have two processors.  It is located in the Initialize funciton.  Hope this helps!
Pat P.
Software Engineer
National Instruments
0 Kudos
Message 7 of 20
(6,386 Views)

Thanks for the reply.

Yes. I see 0% CPU usuage and bar keep going from left to right.

No, Memory usuage does not change. (memory Usage tab)

No, it is not dual core machine.

I do see all applications listed in Process tab and memory Usage does change there after I click refresh button.

 

 

Thanks.
CVI 2010
LabVIEW 2011 SP1
Vision Builder AI 2011 SP1
0 Kudos
Message 8 of 20
(6,385 Views)

When following called both     gCPUCounter = NULL and gCommittedBytesCounter=NULL.

System_Diagnostics_PerformanceCounter__Create_2(&gCPUCounter, "Processor",
        "% Processor Time", "_Total", 0);
    System_Diagnostics_PerformanceCounter__Create_4(&gCommittedBytesCounter,
        "Memory", "Committed Bytes", 0);

Thanks.
CVI 2010
LabVIEW 2011 SP1
Vision Builder AI 2011 SP1
0 Kudos
Message 9 of 20
(6,387 Views)
Hey Sheetal,

These counters are the same ones being used in performance monitor.  We can check to make sure these are working properly.  You should be able to go to Start>>Run and type in perfmon.  This should open performance monitor.  You can then right click on the graph and select to add a counter.  These should directly correspond to what is in CVI (Performance Object = Processor, Counter = % Processor Time).  You can test it here to make sure that you can see the CPU Usage.  Also what operating system are you running, Win XP SP2?
Pat P.
Software Engineer
National Instruments
0 Kudos
Message 10 of 20
(6,386 Views)