From eb83a1f8215abbd5378b4f5caa1df89e7b040f27 Mon Sep 17 00:00:00 2001 From: Jim Warner Date: Mon, 19 Oct 2020 00:00:00 -0500 Subject: [PATCH] library: a tweak to the UNREF_RPTHASH code, api If a hash results report is output (via UNREF_RPTHASH) a portion is devoted to occupied table entries ordered by depth. There is a possibility that some depths will not be found among existing occupied table entries and to avoid any confusion probably should not be printed. [ to illustrate the potential for confusion prior to ] [ this patch, force a very small table size (like 8) ] [ & then trigger the procps_pids_unref() eoj report. ] So this patch ensures only 'in use' entries are shown. [ admittedly, all of the remaining logic in the loop ] [ could/should be subordinate to this new 'if' test, ] [ but we will keep the change to a minimum. besides, ] [ there's no harm subtracting/adding a zero numdepth ] [ especially since the chance of a zero is very low. ] Signed-off-by: Jim Warner --- proc/pids.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proc/pids.c b/proc/pids.c index cd3d9618..c118c82c 100644 --- a/proc/pids.c +++ b/proc/pids.c @@ -727,7 +727,7 @@ static void pids_unref_rpthash ( for (pop = total_occupied, cross_foot = 0; maxdepth; maxdepth--) { for (i = 0, numdepth = 0; i < HHASH_SIZE; i++) if (depths[i] == maxdepth) ++numdepth; - fprintf(stderr, + if (numdepth) fprintf(stderr, "\t %5d (%3d%%) hash table entries at depth %d\n" , numdepth, (numdepth * 100) / total_occupied, maxdepth); pop -= numdepth;