LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

get cpu usage programatically

Yes XP SP2.

I tried % Processor Time and that graphs gives me value of higher 90%. Actual CPU usuage is less then 10%.

Thanks.
CVI 2010
LabVIEW 2011 SP1
Vision Builder AI 2011 SP1
0 Kudos
Message 11 of 20
(3,443 Views)

From CVI example code,   

status = Initialize_System();   //I added status
   

//status = 0 no error
      
     // Create .NET performance counter objects
    status = System_Diagnostics_PerformanceCounter__Create_2(&gCPUCounter, "Processor",
        "% Processor Time", "_Total", 0);//I added status

//status = -6571
 error = CDotNetGetErrorDescription(status);   //I added this

//error=Target invoked by Labwindows/CVI .net library threw an exception.

Any idea why?

Thanks.
CVI 2010
LabVIEW 2011 SP1
Vision Builder AI 2011 SP1
0 Kudos
Message 12 of 20
(3,429 Views)
Hey Sheetal,
One thing I would recommend trying is to repair the CVI Run Time Engine.  If you installed DotNET after installing CVI, this is necessary to do.  You can go to Add Remove Programs, select National Instruments Software, select the CVI Run Time Engine for 8.0.1, and select repair.
Pat P.
Software Engineer
National Instruments
0 Kudos
Message 13 of 20
(3,403 Views)

Thanks for suggestions.

It did not work. Same results.

I have CVI version 8.0.1 but my RTE is 8.1. Does it make any difference?

Thanks.
CVI 2010
LabVIEW 2011 SP1
Vision Builder AI 2011 SP1
0 Kudos
Message 14 of 20
(3,399 Views)
Howdy Sheetal,

Do you have both the .NET 1.1 and 2.0 framework installed or just the 2.0 framework?

I am curious to see if the issue resides with LabWindows/CVI or rather with the .NET framework. I found and modified a small .NET example (found on www.codeproject.com) that uses the .NET performance monitor. Open and run this project to see if you also see a value of 0. This example is using the same assembly as the LabWindows/CVI example is.

If you don't have Visual Studio 2005 (which is what I created it in), then simply run the debug exe located in the bin\debug directory of the attached zip file. 

Secondly, I see that you might now some LabVIEW. If you have LabVIEW installed, run the SimpleTaskMonitor.VI example to see if you see the same behavior. It also use the .NET assembly.

Let me know the findings.

Thanks and best regards,
Jonathan N.
National Instruments
Message 15 of 20
(3,364 Views)
When I tried labview example I get error 1172. A Labview .net exception occured.
Thanks.
CVI 2010
LabVIEW 2011 SP1
Vision Builder AI 2011 SP1
0 Kudos
Message 16 of 20
(3,352 Views)
Hi Sheetal,

What about the other example I sent that was built with VS2005. Does that work?
Jonathan N.
National Instruments
0 Kudos
Message 17 of 20
(3,347 Views)

When I run your program I get this error.

The thread 0x5f4 has exited with code 0 (0x0).

The thread '<No Name>' (0x828) has exited with code 0 (0x0).

'CpuUsageTest.vshost.exe' (Managed): Loaded 'C:\Documents and Settings\apatelsh\Desktop\Test CPU_Usage\Test CPU_Usage\CpuUsage\CpuUsageTest\bin\Debug\CpuUsageTest.exe', Symbols loaded.

A first chance exception of type 'System.InvalidOperationException' occurred in System.dll

An unhandled exception of type 'System.InvalidOperationException' occurred in System.dll

Additional information: Category does not exist.

'CpuUsageTest.vshost.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll', No symbols loaded.

The thread '<No Name>' (0xf6c) has exited with code 0 (0x0).

The program '[3324] CpuUsageTest.vshost.exe: Managed' has exited with code -532459699 (0xe0434f4d).

Thanks.
CVI 2010
LabVIEW 2011 SP1
Vision Builder AI 2011 SP1
0 Kudos
Message 18 of 20
(3,341 Views)

Howdy Sheetal,

Hmmm.... that's a little weird that you are receiving errors issues in LabWindows/CVI, LabVIEW, and with Visual Studio executables. 

What brought up a possibly light bulb in my head was the Visual Studio error that you posted which mentioned that the Category does not exist.

When you create a Performance Counter object in .NET, you must specify the Category to which you will be monitoring (in this case, the category was Processor). Thus, I found a Microsoft document entitled Some performance objects and counters are not available in the System Monitor tool on your Windows X.... Essentially, if you have paging turned off, you don't get access to those counters. I changed my virtual memory to no paging, and I receive the same Visual Studio error and CVI behavior you mentioned. That Microsoft document says to either contact Microsoft for the hotfix or gives you a workaround of basically changing your paging memory. 

Anyway, this should fix your problem. Let me know what happens!

Best Regards,

Message Edited by Jonathan N on 03-09-2007 09:55 AM

Jonathan N.
National Instruments
Message 19 of 20
(3,324 Views)

Hi Jon,

Thanks for your help. Yes I had page file off. I changed to system managed file. Restarted laptop and I tried CVI, labview and C sharp project but no success. I get same result.

Then  I waited 10 minutes and tried again and it worked with all programs.. Interesting...Again thank you very much for help. This solves my problem.

Thanks.
CVI 2010
LabVIEW 2011 SP1
Vision Builder AI 2011 SP1
0 Kudos
Message 20 of 20
(3,307 Views)