/[monit]/monit/process/sysdep_DARWIN.c
ViewVC logotype

Diff of /monit/process/sysdep_DARWIN.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.4 by chopp, Wed Aug 13 22:18:43 2003 UTC revision 1.5 by rory, Sat Aug 16 00:12:19 2003 UTC
# Line 124  static int pageshift; Line 124  static int pageshift;
124    
125  static kvm_t * kvm_handle;  static kvm_t * kvm_handle;
126    
 static void calcru(struct proc *p, struct timeval *up, struct timeval *sp,  
                    struct timeval *ip)  
 {  
   quad_t totusec;  
   u_quad_t u, st, ut, it, tot;  
     
 #if (__FreeBSD_version < 300003)  
   long sec, usec;  
 #endif  
     
   struct timeval tv;  
   
   st = p->p_sticks;  
   ut = p->p_uticks;  
   it = p->p_iticks;  
     
   tot = st + ut + it;  
   if (tot == 0)  
     {  
       st = 1;  
       tot = 1;  
     }  
     
 #if (defined __FreeBSD__) && (__FreeBSD_version >= 300003)  
   totusec = (u_quad_t) p->p_runtime;  
 #else  
   sec = p->p_rtime.tv_usec;  
   usec = p->p_rtime.tv_usec;  
     
   totusec = (quad_t)sec * 1000000 + usec;  
 #endif  
     
   if(totusec < 0)  
     {  
       fprintf (stderr, "calcru: negative time: %ld usec\n",  
                (long)totusec);  
       totusec = 0;  
     }  
     
   u = totusec;  
   st = (u * st) / tot;  
   sp->tv_sec = st / 1000000;  
   sp->tv_usec = st % 1000000;  
   ut = (u * ut) / tot;  
   up->tv_sec = ut / 1000000;  
   up->tv_usec = ut % 1000000;  
     
   if(ip != NULL)  
     {  
       it = (u * it) / tot;  
       ip->tv_sec = it / 1000000;  
       ip->tv_usec = it % 1000000;  
     }  
 }  
   
127  int init_process_info_sysdep(void) {  int init_process_info_sysdep(void) {
128    
129    register int pagesize;    register int pagesize;
130    struct vmmeter vmm;    struct vmmeter vmm;
131      int mib[2];
132      size_t len;
133        
134    struct nlist nlst [] = {    struct nlist nlst [] = {
135        { "_bufspace"},        { "_bufspace"},
# Line 196  int init_process_info_sysdep(void) { Line 143  int init_process_info_sysdep(void) {
143    
144    }    }
145    
146      mib[0] = CTL_HW;
147      mib[1] = HW_NCPU;
148      len = sizeof(num_cpus);
149    
150      sysctl(mib, 2, &num_cpus, &len, NULL, 0);
151    
152    kvm_handle = kvm_open(NULL, NULL, NULL, O_RDONLY, "monit");    kvm_handle = kvm_open(NULL, NULL, NULL, O_RDONLY, "monit");
153        
154    if ( kvm_handle == NULL ) {    if ( kvm_handle == NULL ) {
# Line 228  int init_process_info_sysdep(void) { Line 181  int init_process_info_sysdep(void) {
181    /* we only need the amount of log(2)1024 for our conversion */    /* we only need the amount of log(2)1024 for our conversion */
182    pageshift -= LOG1024;    pageshift -= LOG1024;
183    
184    /* Get the data from kvm_* */    len = sizeof(vmm);
   if (kvm_read (kvm_handle, nlst[1].n_value,  
                 &vmm, sizeof (vmm)) != sizeof (vmm)) {  
     return FALSE;  
185    
186      if (sysctl(mib, 2, &vmm, &len, NULL, 0) < 0) {
187        return FALSE;
188    }    }
189    
190    mem_kbyte_max= vmm.v_free_min +    mem_kbyte_max= vmm.v_free_min +
# Line 246  int init_process_info_sysdep(void) { Line 198  int init_process_info_sysdep(void) {
198  int get_process_info_sysdep(ProcInfo_T p) {  int get_process_info_sysdep(ProcInfo_T p) {
199    
200    struct kinfo_proc *pinfo;    struct kinfo_proc *pinfo;
201    struct pstats pstats;    /*  struct pstats pstats; */
202    struct plimit plimit;    struct plimit plimit;
203    struct vmspace *vms;    struct vmspace *vms;
204    register struct rusage *rup;    /*  register struct rusage *rup; */
205    long stat_utime=0;    long stat_utime=0;
206    long stat_stime=0;    long stat_stime=0;
207    long stat_cutime=0;    long stat_cutime=0;
# Line 365  int initprocesstree_sysdep(ProcessTree_T Line 317  int initprocesstree_sysdep(ProcessTree_T
317    
318    u_int64_t rss_lim;    u_int64_t rss_lim;
319    
320      int i = 0;
321    int treesize;    int treesize;
322    
323      ProcessTree_T * pt;
324    /* Got it from libgtop */    /* Got it from libgtop */
325    
326    pinfo = kvm_getprocs(kvm_handle, KERN_PROC_ALL, 0, &treesize);    pinfo = kvm_getprocs(kvm_handle, KERN_PROC_ALL, 0, &treesize);
# Line 386  int initprocesstree_sysdep(ProcessTree_T Line 340  int initprocesstree_sysdep(ProcessTree_T
340    
341    for(i=0;i<treesize;i++) {    for(i=0;i<treesize;i++) {
342    
343      pt[i]->pid   = pinfo[i].kp_proc.p_pid;      pt[i].pid   = pinfo[i].kp_proc.p_pid;
344      pt[i]->ppid  = pinfo[i].kp_eproc.e_ppid;      pt[i].ppid  = pinfo[i].kp_eproc.e_ppid;
345    
346      if (kvm_read (kvm_handle,      /*    if (kvm_read (kvm_handle,
347                    (unsigned long) pinfo[i].kp_proc.p_limit,                    (unsigned long) pinfo[i].kp_proc.p_limit,
348                    (char *) &plimit, sizeof (plimit)) != sizeof (plimit)) {                    (char *) &plimit, sizeof (plimit)) != sizeof (plimit)) {
349                
350        return FALSE;        return FALSE;
351                
352      }        }*/
353    
354      rss_lim = (u_int64_t)      rss_lim = (u_int64_t)
355        (plimit.pl_rlimit [RLIMIT_RSS].rlim_cur);        (plimit.pl_rlimit [RLIMIT_RSS].rlim_cur);
356            
357      vms = &pinfo [i].kp_eproc.e_vm;      vms = &pinfo [i].kp_eproc.e_vm;
358            
359      pt[i]->mem_kbyte= (u_int64_t) pagetok (vms->vm_rssize);      pt[i].mem_kbyte= (u_int64_t) pagetok (vms->vm_rssize);
360      /* <<LOG1024 removed, we wanna have kb */      /* <<LOG1024 removed, we wanna have kb */
361    
362    }    }

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26