161 |
unsigned long stat_item_utime = 0; |
unsigned long stat_item_utime = 0; |
162 |
unsigned long stat_item_stime = 0; |
unsigned long stat_item_stime = 0; |
163 |
ProcessTree_T *pt = NULL; |
ProcessTree_T *pt = NULL; |
|
#ifndef USE_QUICK_MEM_CALC |
|
|
int statm_item_share = 0; |
|
|
int statm_item_trs = 0; |
|
|
int statm_item_drs = 0; |
|
|
#endif |
|
164 |
|
|
165 |
ASSERT(reference); |
ASSERT(reference); |
166 |
|
|
236 |
pt[i].status_flag |= PROCESS_ZOMBIE; |
pt[i].status_flag |= PROCESS_ZOMBIE; |
237 |
} |
} |
238 |
|
|
|
#ifdef USE_QUICK_MEM_CALC |
|
239 |
if(PAGE_TO_KBYTE_SHIFT < 0) |
if(PAGE_TO_KBYTE_SHIFT < 0) |
240 |
{ |
{ |
241 |
pt[i].mem_kbyte = (stat_item_rss >> abs(PAGE_TO_KBYTE_SHIFT)); |
pt[i].mem_kbyte = (stat_item_rss >> abs(PAGE_TO_KBYTE_SHIFT)); |
244 |
{ |
{ |
245 |
pt[i].mem_kbyte = (stat_item_rss << abs(PAGE_TO_KBYTE_SHIFT)); |
pt[i].mem_kbyte = (stat_item_rss << abs(PAGE_TO_KBYTE_SHIFT)); |
246 |
} |
} |
|
#else |
|
|
if(!read_proc_file(buf, 4096, "statm", pt[i].pid)) |
|
|
{ |
|
|
DEBUG( |
|
|
"system statistic error -- cannot read /proc/%d/statm\n", |
|
|
pt[i].pid); |
|
|
pt[i].mem_kbyte = 0; |
|
|
} |
|
|
else |
|
|
{ |
|
|
/* This implementation is done by using fs/procfs/array.c as a basis |
|
|
* it is also worth looking into the source of the procps utils. |
|
|
* Beware then proc man page has a wrong sorting of the entries! */ |
|
|
if(sscanf(buf, |
|
|
"%*d %*d %d %d %*d %d %*d\n", |
|
|
&statm_item_share, |
|
|
&statm_item_trs, |
|
|
&statm_item_drs) != 3) |
|
|
{ |
|
|
DEBUG( |
|
|
"system statistic error -- file /proc/%d/statm parse error\n", |
|
|
pt[i].pid); |
|
|
continue; |
|
|
} |
|
|
|
|
|
if(PAGE_TO_KBYTE_SHIFT < 0) |
|
|
{ |
|
|
pt[i].mem_kbyte = |
|
|
(statm_item_trs >> abs(PAGE_TO_KBYTE_SHIFT)) + |
|
|
(statm_item_drs >> abs(PAGE_TO_KBYTE_SHIFT)) - |
|
|
(statm_item_share >> abs(PAGE_TO_KBYTE_SHIFT)); |
|
|
|
|
|
} |
|
|
else |
|
|
{ |
|
|
pt[i].mem_kbyte = |
|
|
(statm_item_trs << abs(PAGE_TO_KBYTE_SHIFT)) + |
|
|
(statm_item_drs << abs(PAGE_TO_KBYTE_SHIFT)) - |
|
|
(statm_item_share << abs(PAGE_TO_KBYTE_SHIFT)); |
|
|
} |
|
|
} |
|
|
#endif |
|
247 |
} |
} |
248 |
|
|
249 |
*reference = pt; |
*reference = pt; |