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

Diff of /monit/process/sysdep_OPENBSD.c

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

revision 1.4 by rory, Thu Aug 14 02:47:03 2003 UTC revision 1.5 by rory, Thu Aug 14 23:32:16 2003 UTC
# Line 147  static int pageshift; Line 147  static int pageshift;
147    
148  static kvm_t * kvm_handle;  static kvm_t * kvm_handle;
149    
 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  
     
   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;  
     }  
 }  
   
150  int init_process_info_sysdep(void) {  int init_process_info_sysdep(void) {
151    
152    register int pagesize;    register int pagesize;
# Line 256  int init_process_info_sysdep(void) { Line 204  int init_process_info_sysdep(void) {
204    /* we only need the amount of log(2)1024 for our conversion */    /* we only need the amount of log(2)1024 for our conversion */
205    pageshift -= LOG1024;    pageshift -= LOG1024;
206    
   /* Get the data from kvm_* */  
207    /* Use sysctl here. We should probably be using sysctl all over, instead    /* Use sysctl here. We should probably be using sysctl all over, instead
208       of kvm_read */       of kvm_read */
209    
210      len = sizeof(vmm);
211    if (sysctl(mib, 2, &vmm, &len, NULL, 0) < 0) {    if (sysctl(mib, 2, &vmm, &len, NULL, 0) < 0) {
212      return FALSE;      return FALSE;
213    
# Line 276  int get_process_info_sysdep(ProcInfo_T p Line 225  int get_process_info_sysdep(ProcInfo_T p
225    
226    struct kinfo_proc *pinfo;    struct kinfo_proc *pinfo;
227    
   /* Only needed for older versions of BSD that use kvm_uread */  
   /* struct user *u_addr = (struct user *)USRSTACK; */  
   struct pstats pstats;  
228    struct plimit plimit;    struct plimit plimit;
229    struct vmspace *vms;    struct vmspace *vms;
230    register struct rusage *rup;    struct rusage rup;
231      struct rusage crup;
232    long stat_utime;    long stat_utime;
233    long stat_stime;    long stat_stime;
234    long stat_cutime;    long stat_cutime;
# Line 305  int get_process_info_sysdep(ProcInfo_T p Line 252  int get_process_info_sysdep(ProcInfo_T p
252    /* ----------------------------- CPU TIMING ----------------------------*/    /* ----------------------------- CPU TIMING ----------------------------*/
253    /* Got it from libgtop/sysdep/freebsd/proctime.c */    /* Got it from libgtop/sysdep/freebsd/proctime.c */
254        
255    if (kvm_read (kvm_handle,    if ( getrusage(RUSAGE_SELF, &rup) < 0 ) {
256                  (unsigned long) pinfo [0].kp_proc.p_stats,      return FALSE;
                 &pstats, sizeof (pstats)) == sizeof (pstats)) {  
       
     /* Need to fix for different versions of BSD - I think older ones  
        use kvm_uread, and newer use kvm_read */  
   
   /*  if ((pinfo [0].kp_proc.p_flag & P_INMEM) &&  
       kvm_uread (kvm_handle, &(pinfo [0]).kp_proc,  
                  (unsigned long) &u_addr->u_stats,  
                  (char *) &pstats, sizeof (pstats)) == sizeof (pstats)) {  
   */  
     rup = &pstats.p_ru;  
     calcru(&(pinfo [0]).kp_proc,  
            &rup->ru_utime, &rup->ru_stime, NULL);  
   
     stat_utime = tv2sec (pstats.p_ru.ru_utime);  
     stat_stime = tv2sec (pstats.p_ru.ru_stime);  
   
     stat_cutime = tv2sec (pstats.p_cru.ru_utime);  
     stat_cstime = tv2sec (pstats.p_cru.ru_stime);  
   
257    } else {    } else {
258    
259      return FALSE;      stat_utime = tv2sec (rup.ru_utime);
260        stat_stime = tv2sec (rup.ru_stime);
261    
262    }    }
263    
264    
265    
266    p->cputime_prev= p->cputime;    p->cputime_prev= p->cputime;
267    p->cputime= (int)(( stat_utime + stat_stime ) / 1000);    p->cputime= (int)(( stat_utime + stat_stime ) / 1000);
268    
269    if( include_children ) {    if( include_children ) {
270    
271        if ( getrusage(RUSAGE_CHILDREN, &crup) < 0) {
272          return FALSE;
273        } else {
274          
275          stat_cutime = tv2sec (crup.ru_utime);
276          stat_cstime = tv2sec (crup.ru_stime);
277          
278        }
279        
280      p->cputime+= (int)(( stat_cutime + stat_cstime ) / 1000);      p->cputime+= (int)(( stat_cutime + stat_cstime ) / 1000);
281        
282    }    }
283    
284    /* first run ? */    /* first run ? */

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