1

我正在尝试使用 C# 中的性能计数器类监视 openoffice 的性能信息。我遇到了一个奇怪的问题,虽然我的程序可以很好地监控其他应用程序信息,但它无法使用相同的程序正确监控 Open Office 的性能数据。本质上,我创建了一个进程并让性能计数器使用它的文件名从该进程中获取处理器时间。我注意到,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);
4

1 回答 1

3

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

因此C:\Program Files (x86)\OpenOffice.org 3\program\soffice.bin,您应该指定soffice(for soffice.exe) 或,而不是soffice.bin

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

于 2010-03-22T22:05:32.850 回答