Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make Make DEBUG_HASH less of a fire-hose.



details:   https://anonhg.NetBSD.org/src/rev/387591350a36
branches:  trunk
changeset: 936185:387591350a36
user:      sjg <sjg%NetBSD.org@localhost>
date:      Mon Jul 20 18:12:48 2020 +0000

description:
Make DEBUG_HASH less of a fire-hose.

Reporting keys on every lookup is overkill unless
playing with a new HASH, so wrap in #ifdef DEBUG_HASH_LOOKUP
Also add some stats at the end so we can see
final size and max chain length - maxchain is a better
variable name than maxlen.

diffstat:

 usr.bin/make/hash.c    |  43 +++++++++++++++++++++++++++++--------------
 usr.bin/make/hash.h    |   5 +++--
 usr.bin/make/main.c    |  11 ++++++++---
 usr.bin/make/nonints.h |   4 +++-
 usr.bin/make/targ.c    |  13 ++++++++++---
 usr.bin/make/var.c     |  13 ++++++++++---
 6 files changed, 63 insertions(+), 26 deletions(-)

diffs (truncated from 301 to 300 lines):

diff -r 2af0afd71639 -r 387591350a36 usr.bin/make/hash.c
--- a/usr.bin/make/hash.c       Mon Jul 20 17:56:13 2020 +0000
+++ b/usr.bin/make/hash.c       Mon Jul 20 18:12:48 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: hash.c,v 1.24 2020/07/19 15:42:25 riastradh Exp $      */
+/*     $NetBSD: hash.c,v 1.25 2020/07/20 18:12:48 sjg Exp $    */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -70,14 +70,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: hash.c,v 1.24 2020/07/19 15:42:25 riastradh Exp $";
+static char rcsid[] = "$NetBSD: hash.c,v 1.25 2020/07/20 18:12:48 sjg Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)hash.c     8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: hash.c,v 1.24 2020/07/19 15:42:25 riastradh Exp $");
+__RCSID("$NetBSD: hash.c,v 1.25 2020/07/20 18:12:48 sjg Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -108,12 +108,15 @@
 #define rebuildLimit 3
 
 /* The hash function(s) */
-/* This one matches Gosling's emacs */
+
+#ifndef HASH
+/* The default: this one matches Gosling's emacs */
 #define HASH(h, key, p) do { \
        for (h = 0, p = key; *p;) \
                h = (h << 5) - h + *p++; \
        } while (0)
 
+#endif
 
 /*
  *---------------------------------------------------------
@@ -154,7 +157,7 @@
                         continue;
        }
        t->numEntries = 0;
-       t->maxlen = 0;
+       t->maxchain = 0;
        t->size = i;
        t->mask = i - 1;
        t->bucketPtr = hp = bmake_malloc(sizeof(*hp) * i);
@@ -236,17 +239,19 @@
        }
        HASH(h, key, p);
        p = key;
+       chainlen = 0;
+#ifdef DEBUG_HASH_LOOKUP
        if (DEBUG(HASH))
                fprintf(debug_file, "%s: %p h=%x key=%s\n", __func__,
                    t, h, key);
-       chainlen = 0;
+#endif
        for (e = t->bucketPtr[h & t->mask]; e != NULL; e = e->next) {
                chainlen++;
                if (e->namehash == h && strcmp(e->name, p) == 0)
                        break;
        }
-       if (chainlen > t->maxlen)
-               t->maxlen = chainlen;
+       if (chainlen > t->maxchain)
+               t->maxchain = chainlen;
        return e;
 }
 
@@ -292,10 +297,12 @@
        HASH(h, key, p);
        keylen = p - key;
        p = key;
+       chainlen = 0;
+#ifdef DEBUG_HASH_LOOKUP
        if (DEBUG(HASH))
                fprintf(debug_file, "%s: %p h=%x key=%s\n", __func__,
                    t, h, key);
-       chainlen = 0;
+#endif
        for (e = t->bucketPtr[h & t->mask]; e != NULL; e = e->next) {
                chainlen++;
                if (e->namehash == h && strcmp(e->name, p) == 0) {
@@ -304,8 +311,8 @@
                        break;
                }
        }
-       if (chainlen > t->maxlen)
-               t->maxlen = chainlen;
+       if (chainlen > t->maxchain)
+               t->maxchain = chainlen;
        if (e)
                return e;
 
@@ -490,9 +497,9 @@
        }
        free(oldhp);
        if (DEBUG(HASH))
-               fprintf(debug_file, "%s: %p size=%d entries=%d maxlen=%d\n",
-                   __func__, t, t->size, t->numEntries, t->maxlen);
-       t->maxlen = 0;
+               fprintf(debug_file, "%s: %p size=%d entries=%d maxchain=%d\n",
+                   __func__, t, t->size, t->numEntries, t->maxchain);
+       t->maxchain = 0;
 }
 
 void Hash_ForEach(Hash_Table *t, void (*action)(void *, void *), void *data)
@@ -505,3 +512,11 @@
             e = Hash_EnumNext(&search))
                action(Hash_GetValue(e), data);
 }
+
+void
+Hash_DebugStats(Hash_Table *t, const char *name)
+{
+    if (DEBUG(HASH))
+       fprintf(debug_file, "Hash_Table %s: size=%d numEntries=%d maxchain=%d\n",
+               name, t->size, t->numEntries, t->maxchain);
+}
diff -r 2af0afd71639 -r 387591350a36 usr.bin/make/hash.h
--- a/usr.bin/make/hash.h       Mon Jul 20 17:56:13 2020 +0000
+++ b/usr.bin/make/hash.h       Mon Jul 20 18:12:48 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: hash.h,v 1.14 2020/07/18 21:37:38 sjg Exp $    */
+/*     $NetBSD: hash.h,v 1.15 2020/07/20 18:12:48 sjg Exp $    */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -100,7 +100,7 @@
     int        size;           /* Actual size of array. */
     int        numEntries;     /* Number of entries in the table. */
     int        mask;           /* Used to select bits for hashing. */
-    int        maxlen;         /* max length of chain detected */
+    int        maxchain;       /* max length of chain detected */
 } Hash_Table;
 
 /*
@@ -147,5 +147,6 @@
 Hash_Entry *Hash_EnumFirst(Hash_Table *, Hash_Search *);
 Hash_Entry *Hash_EnumNext(Hash_Search *);
 void Hash_ForEach(Hash_Table *, void (*)(void *, void *), void *);
+void Hash_DebugStats(Hash_Table *, const char *);
 
 #endif /* _HASH_H */
diff -r 2af0afd71639 -r 387591350a36 usr.bin/make/main.c
--- a/usr.bin/make/main.c       Mon Jul 20 17:56:13 2020 +0000
+++ b/usr.bin/make/main.c       Mon Jul 20 18:12:48 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.282 2020/07/19 12:35:30 rillig Exp $        */
+/*     $NetBSD: main.c,v 1.283 2020/07/20 18:12:48 sjg Exp $   */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,7 +69,7 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: main.c,v 1.282 2020/07/19 12:35:30 rillig Exp $";
+static char rcsid[] = "$NetBSD: main.c,v 1.283 2020/07/20 18:12:48 sjg Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
@@ -81,7 +81,7 @@
 #if 0
 static char sccsid[] = "@(#)main.c     8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: main.c,v 1.282 2020/07/19 12:35:30 rillig Exp $");
+__RCSID("$NetBSD: main.c,v 1.283 2020/07/20 18:12:48 sjg Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -2040,6 +2040,11 @@
 {
     static GNode *en = NULL;
 
+    if (DEBUG(HASH)) {
+       Targ_Stats();
+       Var_Stats();
+    }
+
     /* we generally want to keep quiet if a sub-make died */
     if (dieQuietly(gn, -1))
        return;
diff -r 2af0afd71639 -r 387591350a36 usr.bin/make/nonints.h
--- a/usr.bin/make/nonints.h    Mon Jul 20 17:56:13 2020 +0000
+++ b/usr.bin/make/nonints.h    Mon Jul 20 18:12:48 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nonints.h,v 1.80 2020/07/19 12:26:17 rillig Exp $      */
+/*     $NetBSD: nonints.h,v 1.81 2020/07/20 18:12:48 sjg Exp $ */
 
 /*-
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -159,6 +159,7 @@
 /* targ.c */
 void Targ_Init(void);
 void Targ_End(void);
+void Targ_Stats(void);
 Lst Targ_List(void);
 GNode *Targ_NewGN(const char *);
 GNode *Targ_FindNode(const char *, int);
@@ -194,6 +195,7 @@
 char *Var_GetHead(const char *);
 void Var_Init(void);
 void Var_End(void);
+void Var_Stats(void);
 void Var_Dump(GNode *);
 void Var_ExportVars(void);
 void Var_Export(char *, int);
diff -r 2af0afd71639 -r 387591350a36 usr.bin/make/targ.c
--- a/usr.bin/make/targ.c       Mon Jul 20 17:56:13 2020 +0000
+++ b/usr.bin/make/targ.c       Mon Jul 20 18:12:48 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: targ.c,v 1.63 2020/07/03 08:02:55 rillig Exp $ */
+/*     $NetBSD: targ.c,v 1.64 2020/07/20 18:12:48 sjg Exp $    */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: targ.c,v 1.63 2020/07/03 08:02:55 rillig Exp $";
+static char rcsid[] = "$NetBSD: targ.c,v 1.64 2020/07/20 18:12:48 sjg Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)targ.c     8.2 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: targ.c,v 1.63 2020/07/03 08:02:55 rillig Exp $");
+__RCSID("$NetBSD: targ.c,v 1.64 2020/07/20 18:12:48 sjg Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -186,6 +186,7 @@
 void
 Targ_End(void)
 {
+    Targ_Stats();
 #ifdef CLEANUP
     Lst_Destroy(allTargets, NULL);
     if (allGNs)
@@ -194,6 +195,12 @@
 #endif
 }
 
+void
+Targ_Stats(void)
+{
+    Hash_DebugStats(&targets, "targets");
+}
+
 /*-
  *-----------------------------------------------------------------------
  * Targ_List --
diff -r 2af0afd71639 -r 387591350a36 usr.bin/make/var.c
--- a/usr.bin/make/var.c        Mon Jul 20 17:56:13 2020 +0000
+++ b/usr.bin/make/var.c        Mon Jul 20 18:12:48 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.285 2020/07/20 16:55:10 rillig Exp $ */
+/*     $NetBSD: var.c,v 1.286 2020/07/20 18:12:48 sjg Exp $    */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.285 2020/07/20 16:55:10 rillig Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.286 2020/07/20 18:12:48 sjg Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)var.c      8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: var.c,v 1.285 2020/07/20 16:55:10 rillig Exp $");
+__RCSID("$NetBSD: var.c,v 1.286 2020/07/20 18:12:48 sjg Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -3992,6 +3992,13 @@
 void
 Var_End(void)
 {
+    Var_Stats();
+}
+
+void
+Var_Stats(void)
+{
+    Hash_DebugStats(&VAR_GLOBAL->context, "VAR_GLOBAL");
 }
 



Home | Main Index | Thread Index | Old Index