Question

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);
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top