如何使用 C# 获取 OpenOffice 的性能信息?

发布于 2024-08-26 00:18:21 字数 1016 浏览 5 评论 0原文

我正在尝试使用 C# 中的性能计数器类来监视 openoffice 的性能信息。我遇到一个奇怪的问题,虽然我的程序可以很好地监视其他应用程序信息,但它无法使用相同的过程正确监视开放办公室的性能数据。本质上,我创建一个进程,并让性能计数器使用该进程的文件名获取处理器时间。我注意到 OpenOffice 在任务管理器下有两个进程;一种是 soffice.bin,一种是 soffice.exe。 bin 文件比 exe 文件占用更多的内存,因此在 exe 文件没有给我提供可用的性能数据(性能计数器不断返回 0 值)后,我尝试进行监控。然而,bin 文件也有同样的问题——无论我对应用程序做什么,我都无法获得任何可用的性能数据。

谁能告诉我为什么我没有得到任何有关 openoffice 性能的良好读数?我是否使用了错误的进程名称,或者是更微妙的东西?

// create a process
        p = new Process();
        p.StartInfo.UseShellExecute = true;
        p.StartInfo.CreateNoWindow = true;
        p.StartInfo.FileName = fileName;
        p.Start();

        // for open office, I found that the BIN file takes up more memory in the task manager
        String name = "C:\\Program Files (x86)\\OpenOffice.org 3\\program\\soffice.bin";

        // So I make a performance counter to monitor that. 
        pc = new System.Diagnostics.PerformanceCounter("Process",
                    "% Processor Time",
                    name,
                    true);

I'm trying to monitor the performance information for openoffice using the performance counter class in C#. I'm encountering a wierd issue where although my program can monitor other applications information just fine, it cannot monitor open office's performance data properly using the same procedure. Essentially, I create a process and have a performance counter get the Processor time from that process using it's filename. OpenOffice, I have noticed, has two processes under the task manager; one is soffice.bin and one is soffice.exe. The bin file takes up way more memory than the exe file, so I tried to monitor that after the exe file gave me no usable performance data(Performance conter kept returning a value of 0). However, the bin file has the same issue - I can't get any usable performance data, no matter what I do to the application.

Can anyone tell me why I'm not getting any good readings for openoffice's performance? Am I using the wrong process name, or is it something more subtle?

// create a process
        p = new Process();
        p.StartInfo.UseShellExecute = true;
        p.StartInfo.CreateNoWindow = true;
        p.StartInfo.FileName = fileName;
        p.Start();

        // for open office, I found that the BIN file takes up more memory in the task manager
        String name = "C:\\Program Files (x86)\\OpenOffice.org 3\\program\\soffice.bin";

        // So I make a performance counter to monitor that. 
        pc = new System.Diagnostics.PerformanceCounter("Process",
                    "% Processor Time",
                    name,
                    true);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

贱贱哒 2024-09-02 00:18:21

Process 对象使用的“实例名称”只是可执行文件的名称,减去任何 .exe 扩展名。这不是整个文件路径。

因此,您应该指定 soffice (对于 soffice.exe< /code>) 或 soffice.bin

查看 Perfmon 以查看系统上的实际实例名称。

The "instance name" used by the Process object is just the name of the executable file, minus any .exe extension. It's not the whole file path.

Thus instead of C:\Program Files (x86)\OpenOffice.org 3\program\soffice.bin, you should specify soffice (for soffice.exe) or soffice.bin.

Take a look in Perfmon to see the actual instance names on your system.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文