library: prefer /proc/stat before /proc/status, <pids>
Long ago, in a galaxy far away (when top was in charge of library FILL flgs) /proc/status was to be preferred over /proc/stat if a field could be satisfied by both. This was done to avoid costly 64-bit math emulation in a 32-bit application due to 'unsigned long long' data. Well it's time to acknowledge the prevalence of 64-bit platforms. And in such an environment the cost picture has shifted significantly. It now costs 14 times (wow) as much to access /proc/status compared to /proc/stat. In other words, even with '%llu' variables, a sscanf() call in stat2proc() beats the pants off that home brew gperf based hashing employed by the status2proc() guy. In fact, status2proc incurs higher costs than found in the most expensive aspect of top's forest view option. Here's a gprof extract to illustrate the costs. It was produced with an rcfile requiring fields from both the /proc/stat & /proc/status pseudo files (among others). There were 5000 iterations in each of 4 separate gprof runs subsequently merged into 1 gmon.sum for analysis. % self self time seconds calls us/call name ----- ------- ------- ------- ----------- 28.65 4.10 4689423 0.87 status2proc 26.14 3.74 40000 93.50 forest_adds ... 01.96 0.28 4689427 0.06 stat2proc [ since forest_adds is recursive, the calls value is ] [ the non-recursive #, its 'call graph' shows totals ] Anyway, now that such cost is known this patch becomes what is euphemistically known as the usual no-brainer. [ jeeze, was it really this long between profilings? ] Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
parent
4e4debda9b
commit
e9c101edcb
@ -339,7 +339,7 @@ srtDECL(noop) {
|
||||
// ___ Controlling Table ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||
|
||||
// from either 'stat' or 'status' (preferred)
|
||||
#define f_either PROC_SPARE_1
|
||||
#define f_either PROC_SPARE_1 // either status or stat (favor stat)
|
||||
#define f_grp PROC_FILLGRP
|
||||
#define f_lxc PROC_FILL_LXC
|
||||
#define f_ns PROC_FILLNS
|
||||
@ -913,8 +913,8 @@ static inline void pids_libflags_set (
|
||||
info->history_yes |= Item_table[e].needhist;
|
||||
}
|
||||
if (info->oldflags & f_either) {
|
||||
if (!(info->oldflags & f_stat))
|
||||
info->oldflags |= f_status;
|
||||
if (!(info->oldflags & (f_stat | f_status)))
|
||||
info->oldflags |= f_stat;
|
||||
}
|
||||
return;
|
||||
} // end: pids_libflags_set
|
||||
|
Loading…
Reference in New Issue
Block a user