How to get CPU load / RAM usage out of QNX?

喜你入骨 提交于 2020-01-03 05:38:10

问题


I'm currently trying to get information about the CPU load and RAM usage out of an PowerPC with QNX running on it. The idea is to write that information in a text file with a time stamp over a certain amount of time, but this ain't my problem here once I have the information as a "standard value". My programm will be in C++ and I already did this kind of program for Windows (via PDH API). Maybe you have page like this but for QNX? Probably I'm looking for the wrong keywords.

Can you help me with this problem? Any kind of direction would be most welcome as I'm new to QNX and this kind of programming. Thanks a lot!


回答1:


You will work with the /proc filesystem.

  1. From the command line you can check the size of the memory space of the process that has process ID = 1234 by:

ls -l /proc/1234/as

"as" stands for "address space" and the size of this virtual file will indicate a good estimate of the memory used by the process in question, 1236992 bytes in this example:

-rw-r--r-- 1 root root 1236992 Aug 21 21:25 as

To get the same value programmatically you will need to use the stat() function on the /proc/PID/as file.

You can refer the following page in the documentation for a more detailed explanation of the same: http://www.qnx.com/developers/docs/660/index.jsp?topic=%2Fcom.qnx.doc.neutrino.cookbook%2Ftopic%2Fs3_procfs_pid_directories.html

  1. In order to get the CPU time (system/user) used by the process you can use the DCMD_PROC_INFO devctly() on the /proc/PID/as file. You will need to refer the "utime" and "stime" members of the debug_process_t structure passed to the devctl().

You can find a detailed explanation and sample code on the following page in the QNX documentation: http://www.qnx.com/developers/docs/660/index.jsp?topic=%2Fcom.qnx.doc.neutrino.cookbook%2Ftopic%2Fs3_procfs_DCMD_PROC_INFO.html



来源:https://stackoverflow.com/questions/30209649/how-to-get-cpu-load-ram-usage-out-of-qnx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!