05-10-2013 12:23 AM
Danny,
Thanks for the reply and suggestion....
I will try this way and let you know...
-Vaishakh
05-10-2013 01:16 AM
Danny,
I have tried your suggesion.
When i am compiling Code it is throwing "Missing Prototype" Error.
So i tried to load library for the API ("ni_emb.dll " you have suggested).
But the library is only for LabView Not for LabWindows.It is in another format not as ' .lib ' format.
So which library i have to add for successful compilation?
For CPU Usage API also same error its throwing..
Please help to solve this problem...
05-10-2013 08:38 AM
I should have been more explicit. You need to dynamically load this function in order for it to work - it is not included in any exported headers. This code is written for a C++ compiler, but it's an example of how to do what you want to do.
struct RTMemStats { unsigned int numBytesAllocated; unsigned int numBytesFree; unsigned int maxFreeBlockSize; }; __declspec(dllexport) int __cdecl printFreeMemory( void ) { typedef unsigned int (*tGetRTMemStatsFunc)(RTMemStats *memStats); HMODULE handle = LoadLibrary( "ni_emb.dll" ); if( !handle ) { printf( "ni_emb.dll failed to load!\n" ); return -1; } tGetRTMemStatsFunc myfunc = (tGetRTMemStatsFunc) GetProcAddress( handle, "GetRTMemStats" ); if( !myfunc) { printf( "GetRTMemStats not found in ni_emb.dll!\n" ); return -2; } struct RTMemStats myRTMemStats; myfunc( &myRTMemStats ); printf( "The system has 0x%x bytes free!\n", myRTMemStats.numBytesFree ); FreeLibrary( handle ); return 0; }
The process is the same for the CPU Utilization function, too. Remember that ni_emb.dll is a "ghost" DLL on PharLap-based targets; you won't find it in the file system, but if you attempt to load the library from within LoadLibrary it will succeed - this is because ni_emb is cleverly hidden within the ph_exec.exe component (required by the system to exist) so that it's always guaranteed to be present on the system.
-Danny
05-11-2013 01:07 PM
Danny,
Thanks for the help...
I have tried your suggestion ..
getting memory usage i have tested in my target ..
It is working fine..
Thanks once more for giving great help...
But CPU usage api is showing error.. like "General Protection Fault"
Please help to sort out this issue ..
05-12-2013 09:30 PM
If you're getting a protection fault, that's probably because you used a NULL pointer as one of the input parameters. All of the pointers have to be good, you cannot use NULL for any of the pointers.
-Danny
05-13-2013 09:09 AM
Danny,
Thanks for the help.. It is working fine...
Using this CPU time details .. how i can calculate CPU Usage in percentage??
05-13-2013 09:29 AM
I'm sure if you thought about that for a few more minutes you'll come up with your answer - if you add up all the values, what do you get? Remember, those values represent ALL of the CPUs in the system (if there are multiple cores) and in those values is an idle amount (how much of the CPU is not being used); the rest of the values represent components of the CPU "usage". I'll leave the math as an exercise to the reader.
-Danny
05-14-2013 04:32 AM
Danny,
Thanks for helping ...
Sorry am very new to processor level coding...
--Vaishakh