Menu

#702 mach (darwin) support for CPU utilization

closed
None
5
2012-11-08
2006-11-21
Bill Fenner
No

tanders asked me to take a look at reporting CPU stats on Darwin. I've come up with the attached. It collects stats for all CPUs and reports them, and adds them all up to report in the CPU #-1. It doesn't support the following values:
- kern_ticks, intrpt_ticks, wait_ticks, sirq_ticks, sys2_ticks
since I couldn't find mach interfaces to report these. (I used sys_ticks instead of sys2_ticks as other modules use because that way the CPUSYSTEM percentage gets reported properly).

The paging stats are reported in swap*, so pageIn and pageOut are unused. It should be the other way around, but the other modules work this way so I followed them. I also couldn't find mach interfaces for interrupts or context switches (Well, I found a per-process context switch value, but I didn't want to try to fetch them all and add them up) so nInterrupts and nCtxSwitches are also unused.

Discussion

  • Bill Fenner

    Bill Fenner - 2006-11-21
     
  • Bill Fenner

    Bill Fenner - 2006-11-21

    hardware/cpu.h diff

     
  • Dave Shield

    Dave Shield - 2006-11-23

    Logged In: YES
    user_id=88893
    Originator: NO

    Question:
    Why do you believe that other implementations use
    'swap{In,Out}' for reporting paging statistics?

    For example, from cpu_sysctl.c:
    #define NS_VM_PAGEIN pageins
    #define NS_VM_PAGEOUT pdpageouts
    #define NS_VM_SWAPIN swapins
    #define NS_VM_SWAPOUT swapouts

    cpu->swapIn       = \(unsigned long\)mem\_stats.NS\_VM\_SWAPIN;
    cpu->swapOut      = \(unsigned long\)mem\_stats.NS\_VM\_SWAPOUT;
    cpu->pageIn       = \(unsigned long\)mem\_stats.NS\_VM\_PAGEIN;
    cpu->pageOut      = \(unsigned long\)mem\_stats.NS\_VM\_PAGEOUT;
    
     
  • Bill Fenner

    Bill Fenner - 2006-11-25

    Logged In: YES
    user_id=109593
    Originator: YES

    Now that I revisit it, I don't know where I got that idea; perhaps from cpu_nlist's

    cpu->swapIn  = \(unsigned long\)mem\_stats.v\_swappgsin+mem\_stats.v\_vnodepgsin;
    cpu->swapOut = \(unsigned long\)mem\_stats.v\_swappgsout+mem\_stats.v\_vnodepgsout
    

    since I was pretty sure that at least the vnode stats are paging.

    I'd be happy to see cpu_mach doing whatever is most appropriate. If you'd like me to submit a new version, that's no problem, or of course it's easy enough to fix my source before adding it to the net-snmp repository.

     
  • Bill Fenner

    Bill Fenner - 2006-12-02

    Logged In: YES
    user_id=109593
    Originator: YES

    I was also confused because I wasn't expecting the paging stats to be reported under ssIORawSent and ssIORawReceived, and thought that maybe the reasoning for reporting using swapping was because at least those stats were exposed in the MIB.

    I've uploaded a new cpu_mach.c that uses the paging values.

     
  • Bill Fenner

    Bill Fenner - 2006-12-02
     
  • Bill Fenner

    Bill Fenner - 2006-12-02

    Logged In: YES
    user_id=109593
    Originator: YES

    I see that this has been labelled too late for 5.4. I submitted it a few hours after tanders asked me to work on it. That's quite an obnoxious release engineering process you have.

     
  • Thomas Anders

    Thomas Anders - 2006-12-03

    Logged In: YES
    user_id=848638
    Originator: NO

    I'm sorry if you feel discouraged, but the fact it didn't make it into 5.4 doesn't say anything about the usefulness of your patch. It will likely make it into 5.4.1 and 5.5 and will be easily available as a patch on top of 5.4 for any interested OSX user. Again: thanks for working on it.

     
  • Thomas Anders

    Thomas Anders - 2006-12-07

    Logged In: YES
    user_id=848638
    Originator: NO

    Thanks for the patch! It has been applied to the 5.4.x code branches and the main development tree, and will appear in future releases of the Net-SNMP package.

     
  • Troy

    Troy - 2007-01-04

    Logged In: YES
    user_id=1652863
    Originator: NO

    This patch breaks the make on

    Darwin Kernel Version 8.8.0: Fri Sep 8 17:18:57 PDT 2006; root:xnu-792.12.6.obj~1/RELEASE_PPC Power Macintosh powerpc

    Using the "configure" from the README.osx

    ./configure --with-persistent-directory=/var/db/net-snmp --with-defaults --without-rpm --with-mib-modules="host ucd-snmp/diskio" --with-out-mib-modules="mibII/icmp host/hr_swrun" --disable-static --without-kmem-usage

    make fails with:
    gcc -I../include -I. -I../agent -I../agent/mibgroup -I../snmplib -g -O2 -Udarwin8 -Ddarwin8=darwin8 -c mibgroup/host/hr_network.c -fno-common -DPIC -o mibgroup/host/.libs/hr_network.o
    mibgroup/host/hr_network.c: In function 'Save_HR_Network_Info':
    mibgroup/host/hr_network.c:250: error: invalid use of undefined type 'struct ifnet'
    mibgroup/host/hr_network.c:251: error: invalid use of undefined type 'struct ifnet'
    mibgroup/host/hr_network.c:251: error: invalid use of undefined type 'struct ifnet'
    make[1]: *** [mibgroup/host/hr_network.lo] Error 1
    make: *** [subdirs] Error 1

     
  • Thomas Anders

    Thomas Anders - 2007-01-04

    Logged In: YES
    user_id=848638
    Originator: NO

    Please post a separate bug for this with all the details (including what patches you added on top of 5.4).

     

Log in to post a comment.

MongoDB Logo MongoDB