[Mono-dev] PerformanceCounters 2.4.2.1

Gladish, Jacob Jacob.Gladish at sig.com
Wed Jul 15 14:34:14 EDT 2009


I was trying the PerfCounter api on sles 10 and am getting some garbled output. I have the following test app:

public class Procs {
   public static void Main(string[] args) {

      PerformanceCounterCategory cat = new PerformanceCounterCategory("Process");

      foreach (PerformanceCounter counter in cat.GetCounters()) {
         Console.WriteLine("CounterName: {0}", counter.CounterName);
      }

      foreach (string s in cat.GetInstanceNames()) {
         Console.WriteLine("CounterInst: '{0}'", s);
      }
   }
}

That produces output like:

CounterName: % User Time
CounterName: % Privileged Time
CounterName: % Processor Time
CounterName: Thread Count
CounterName: Virtual Bytes
CounterName: Working Set
CounterName: Private Bytes
CounterInst: '1/init [3]'
CounterInst: '2/migration/0
'+'
CounterInst: '3/ksoftirqd/0
'+'
CounterInst: '4/migration/1
'+'
CounterInst: '5/ksoftirqd/1
'+'
CounterInst: '6/migration/2
'+'
CounterInst: '7/ksoftirqd/2
'+'
CounterInst: '8/migration/3
'+'
CounterInst: '9/ksoftirqd/3
'+'
CounterInst: '10/migration/4
'+'
CounterInst: '11/ksoftirqd/4
'+'

I think the issue is in mono/utils/mono-proclib.c

*** 131,137 ****
                fclose (f);
                len = strlen (s);
                strncpy (rbuf, s, MIN (len, blen));
!               rbuf [blen - 1] = 0;
                if (error)
                        *error = MONO_PROCESS_ERROR_NONE;
                return rbuf;
--- 131,137 ----
                fclose (f);
                len = strlen (s);
                strncpy (rbuf, s, MIN (len, blen));
!               rbuf [MIN(len,blen) - 1] = 0;
                if (error)
                        *error = MONO_PROCESS_ERROR_NONE;
                return rbuf;


or use len+1 in strncpy to get the NULL in the right place.

IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.


More information about the Mono-devel-list mailing list