问题:
I once had the task of determining the following performance parameters from inside a running application: 我曾经负责从运行的应用程序内部确定以下性能参数的任务:
- Total virtual memory available 可用虚拟内存总量
- Virtual memory currently used 当前使用的虚拟内存
- Virtual memory currently used by my process 我的进程当前使用的虚拟内存
- Total RAM available 总可用RAM
- RAM currently used 当前使用的RAM
- RAM currently used by my process 我的进程当前使用的RAM
- % CPU currently used 当前使用的CPU百分比
- % CPU currently used by my process 我的进程当前使用的CPU百分比
The code had to run on Windows and Linux. 该代码必须在Windows和Linux上运行。 Even though this seems to be a standard task, finding the necessary information in the manuals (WIN32 API, GNU docs) as well as on the Internet took me several days, because there's so much incomplete/incorrect/outdated information on this topic to be found out there. 尽管这似乎是一项标准任务,但在手册(WIN32 API,GNU文档)以及Internet上找到必要的信息还是花了我几天的时间,因为关于该主题的信息太多,不完整/不正确/过时发现在那里。
In order to save others from going through the same trouble, I thought it would be a good idea to collect all the scattered information plus what I found by trial and error here in one place. 为了使其他人免于遭受同样的麻烦,我认为将所有分散的信息以及通过反复试验发现的信息收集到一个地方是一个好主意。
解决方案:
参考一: https://stackoom.com/question/GQo/如何从进程内部确定CPU和内存消耗参考二: https://oldbug.net/q/GQo/How-to-determine-CPU-and-memory-consumption-from-inside-a-process
来源:oschina
链接:https://my.oschina.net/u/3797416/blog/4422375