Module Name: src
Committed By: sjg
Date: Mon Jul 20 18:12:48 UTC 2020
Modified Files:
src/usr.bin/make: hash.c hash.h main.c nonints.h targ.c var.c
Log Message:
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.
To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/usr.bin/make/hash.c
cvs rdiff -u -r1.14 -r1.15 src/usr.bin/make/hash.h
cvs rdiff -u -r1.282 -r1.283 src/usr.bin/make/main.c
cvs rdiff -u -r1.80 -r1.81 src/usr.bin/make/nonints.h
cvs rdiff -u -r1.63 -r1.64 src/usr.bin/make/targ.c
cvs rdiff -u -r1.285 -r1.286 src/usr.bin/make/var.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/make/hash.c
diff -u src/usr.bin/make/hash.c:1.24 src/usr.bin/make/hash.c:1.25
--- src/usr.bin/make/hash.c:1.24 Sun Jul 19 15:42:25 2020
+++ src/usr.bin/make/hash.c Mon Jul 20 18:12:48 2020
@@ -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 @@ static void RebuildTable(Hash_Table *);
#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 @@ Hash_InitTable(Hash_Table *t, int numBuc
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_FindEntry(Hash_Table *t, const char
}
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_CreateEntry(Hash_Table *t, const ch
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 @@ Hash_CreateEntry(Hash_Table *t, const ch
break;
}
}
- if (chainlen > t->maxlen)
- t->maxlen = chainlen;
+ if (chainlen > t->maxchain)
+ t->maxchain = chainlen;
if (e)
return e;
@@ -490,9 +497,9 @@ RebuildTable(Hash_Table *t)
}
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 @@ void Hash_ForEach(Hash_Table *t, void (*
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);
+}
Index: src/usr.bin/make/hash.h
diff -u src/usr.bin/make/hash.h:1.14 src/usr.bin/make/hash.h:1.15
--- src/usr.bin/make/hash.h:1.14 Sat Jul 18 21:37:38 2020
+++ src/usr.bin/make/hash.h Mon Jul 20 18:12:48 2020
@@ -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 @@ typedef struct Hash_Table {
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 @@ void Hash_DeleteEntry(Hash_Table *, Hash
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 */
Index: src/usr.bin/make/main.c
diff -u src/usr.bin/make/main.c:1.282 src/usr.bin/make/main.c:1.283
--- src/usr.bin/make/main.c:1.282 Sun Jul 19 12:35:30 2020
+++ src/usr.bin/make/main.c Mon Jul 20 18:12:48 2020
@@ -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 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 19
#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 @@ PrintOnError(GNode *gn, const char *s)
{
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;
Index: src/usr.bin/make/nonints.h
diff -u src/usr.bin/make/nonints.h:1.80 src/usr.bin/make/nonints.h:1.81
--- src/usr.bin/make/nonints.h:1.80 Sun Jul 19 12:26:17 2020
+++ src/usr.bin/make/nonints.h Mon Jul 20 18:12:48 2020
@@ -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 @@ void Suff_PrintAll(void);
/* 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_GetTail(const char *);
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);
Index: src/usr.bin/make/targ.c
diff -u src/usr.bin/make/targ.c:1.63 src/usr.bin/make/targ.c:1.64
--- src/usr.bin/make/targ.c:1.63 Fri Jul 3 08:02:55 2020
+++ src/usr.bin/make/targ.c Mon Jul 20 18:12:48 2020
@@ -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 @@ Targ_Init(void)
void
Targ_End(void)
{
+ Targ_Stats();
#ifdef CLEANUP
Lst_Destroy(allTargets, NULL);
if (allGNs)
@@ -194,6 +195,12 @@ Targ_End(void)
#endif
}
+void
+Targ_Stats(void)
+{
+ Hash_DebugStats(&targets, "targets");
+}
+
/*-
*-----------------------------------------------------------------------
* Targ_List --
Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.285 src/usr.bin/make/var.c:1.286
--- src/usr.bin/make/var.c:1.285 Mon Jul 20 16:55:10 2020
+++ src/usr.bin/make/var.c Mon Jul 20 18:12:48 2020
@@ -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 @@ Var_Init(void)
void
Var_End(void)
{
+ Var_Stats();
+}
+
+void
+Var_Stats(void)
+{
+ Hash_DebugStats(&VAR_GLOBAL->context, "VAR_GLOBAL");
}