简体   繁体   中英

How can I take the performance information from OpenOffice in C#?

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);

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM