88 |
#define tv2sec(tv) (((u_int64_t) tv.tv_sec * 1000000) + (u_int64_t) tv.tv_usec) |
#define tv2sec(tv) (((u_int64_t) tv.tv_sec * 1000000) + (u_int64_t) tv.tv_usec) |
89 |
|
|
90 |
static int pageshift; |
static int pageshift; |
|
static long mem_kbyte_max; |
|
91 |
|
|
92 |
#ifndef LOG1024 |
#ifndef LOG1024 |
93 |
#define LOG1024 10 |
#define LOG1024 10 |
328 |
return TRUE; |
return TRUE; |
329 |
|
|
330 |
} |
} |
331 |
|
|
332 |
|
/** |
333 |
|
* Read all processes of the proc files system to initilize |
334 |
|
* the process tree (sysdep version... but should work for |
335 |
|
* all procfs based unices) |
336 |
|
* @param reference reference of ProcessTree |
337 |
|
* @return treesize>0 if succeeded otherwise =0. |
338 |
|
*/ |
339 |
|
int initprocesstree_sysdep(ProcessTree_T ** reference) { |
340 |
|
|
341 |
|
struct kinfo_proc *pinfo; |
342 |
|
|
343 |
|
/* Only needed for older versions of BSD that use kvm_uread */ |
344 |
|
/* struct user *u_addr = (struct user *)USRSTACK; */ |
345 |
|
struct plimit plimit; |
346 |
|
struct vmspace *vms; |
347 |
|
|
348 |
|
u_int64_t rss_lim; |
349 |
|
|
350 |
|
int treesize; |
351 |
|
|
352 |
|
/* Got it from libgtop */ |
353 |
|
|
354 |
|
pinfo = kvm_getprocs(kvm_handle, KERN_PROC_ALL, 0, &treesize); |
355 |
|
|
356 |
|
if ((pinfo == NULL) || (treesize < 1)) { |
357 |
|
|
358 |
|
return 0; |
359 |
|
|
360 |
|
} |
361 |
|
|
362 |
|
/* Allocate the tree */ |
363 |
|
|
364 |
|
pt = xcalloc(sizeof(ProcessTree_T), treesize); |
365 |
|
memset( pt, 0, sizeof(ProcessTree_T)*treesize ); |
366 |
|
|
367 |
|
/* Insert data from /proc directory */ |
368 |
|
|
369 |
|
for(i=0;i<treesize;i++) { |
370 |
|
|
371 |
|
pt[i]->pid = pinfo[i].kp_proc.p_pid; |
372 |
|
pt[i]->ppid = pinfo[i].kp_eproc.e_ppid; |
373 |
|
|
374 |
|
if (kvm_read (kvm_handle, |
375 |
|
(unsigned long) pinfo[i].kp_proc.p_limit, |
376 |
|
(char *) &plimit, sizeof (plimit)) != sizeof (plimit)) { |
377 |
|
|
378 |
|
return FALSE; |
379 |
|
|
380 |
|
} |
381 |
|
|
382 |
|
rss_lim = (u_int64_t) |
383 |
|
(plimit.pl_rlimit [RLIMIT_RSS].rlim_cur); |
384 |
|
|
385 |
|
vms = &pinfo [i].kp_eproc.e_vm; |
386 |
|
|
387 |
|
pt[i]->mem_kbyte= (u_int64_t) pagetok (vms->vm_rssize); |
388 |
|
/* <<LOG1024 removed, we wanna have kb */ |
389 |
|
|
390 |
|
} |
391 |
|
|
392 |
|
* reference = pt; |
393 |
|
|
394 |
|
return treesize; |
395 |
|
|
396 |
|
} |
397 |
|
|
398 |
|
/** |
399 |
|
* This routine returns 'nelem' double precision floats containing |
400 |
|
* the load averages in 'loadv'; at most 3 values will be returned. |
401 |
|
* @param loadv destination of the load averages |
402 |
|
* @param nelem number of averages |
403 |
|
* @return: 0 if successful, -1 if failed (and all load averages are 0). |
404 |
|
*/ |
405 |
|
int getloadavg_sysdep (double *loadv, int nelem) { |
406 |
|
|
407 |
|
return getloadavg(loadv, nelem); |
408 |
|
|
409 |
|
} |