如何获取当前进程的 Windows 性能计数器

编程入门 行业动态 更新时间:2024-10-25 09:40:46
本文介绍了如何获取当前进程的 Windows 性能计数器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在为 C++ 应用程序 foo.exe 编写代码.在应用程序内部,我想记录其地址空间使用情况.所以我想查看的性能计数器是\Process(foo)\Virtual Bytes".我遇到的问题是系统上可能运行了多个 foo.exe 实例.在 perfmon 中,我可以看到这些被引用为\Process(foo#2)\Virtual Bytes",其中 #2 可以是任何数字,具体取决于进程数.

I am writing code for a C++ application foo.exe. Inside the application, I want to log its address space usage. So the performance counter I want to look at is "\Process(foo)\Virtual Bytes". The problem I am encountering is that there may be multiple instances of foo.exe running on the system. In perfmon, I can see that these are referenced as "\Process(foo#2)\Virtual Bytes" where the #2 could be any number depending on the number of processes.

如何构造计数器路径来获取当前进程的虚拟字节,以处理存在多个进程实例的情况?

How can I construct a counter path to get the virtual bytes for the current process that handles the case where there are multiples instances of the process?

推荐答案

您的实例是具有与您当前的进程 ID 匹配的 ID Process 计数器值的实例.不幸的是,除了获取所有实例并枚举它们,直到找到属于您的实例为止,别无他法,但这很简单.

Your instance is the one that has the ID Process counter value that matches your current process ID. Unfortunately there is no other way than to get all instances and enumerate through them untill you find the instance that is yours, but that is fairly trivial to do.

更多推荐

如何获取当前进程的 Windows 性能计数器

本文发布于:2023-11-17 11:46:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1609908.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:计数器   进程   性能   Windows

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!