Print hash-table statistics with "-ds" debugging.
Some checks failed
Remind unit tests / tests (push) Failing after 29s

This commit is contained in:
Dianne Skoll
2024-10-11 16:34:11 -04:00
parent a66e855ca7
commit ad382fea25
5 changed files with 63 additions and 0 deletions

View File

@@ -60,9 +60,15 @@ exitfunc(void)
/* Kill any execution-time-limiter process */
unlimit_execution_time();
int maxlen, total;
double avglen;
if (DebugFlag & DB_PARSE_EXPR) {
fflush(stdout);
fflush(stderr);
get_var_hash_stats(&total, &maxlen, &avglen);
fprintf(stderr, " Var hash: total = %d; maxlen = %d; avglen = %.3f\n", total, maxlen, avglen);
get_userfunc_hash_stats(&total, &maxlen, &avglen);
fprintf(stderr, "Func hash: total = %d; maxlen = %d; avglen = %.3f\n", total, maxlen, avglen);
UnsetAllUserFuncs();
print_expr_nodes_stats();
}

View File

@@ -247,3 +247,6 @@ extern int _private_sub_overflow(int a, int b);
void print_sysvar_tokens(void);
void print_builtinfunc_tokens(void);
void print_remind_tokens(void);
void get_var_hash_stats(int *total, int *maxlen, double *avglen);
void get_userfunc_hash_stats(int *total, int *maxlen, double *avglen);

View File

@@ -401,3 +401,28 @@ UnsetAllUserFuncs(void)
FuncHash[i] = NULL;
}
}
void
get_userfunc_hash_stats(int *total, int *maxlen, double *avglen)
{
int len;
int i;
UserFunc *f;
*maxlen = 0;
*total = 0;
for (i=0; i<FUNC_HASH_SIZE; i++) {
len = 0;
f = FuncHash[i];
while(f) {
len++;
(*total)++;
f = f->next;
}
if (len > *maxlen) {
*maxlen = len;
}
}
*avglen = (double) *total / (double) FUNC_HASH_SIZE;
}

View File

@@ -1208,3 +1208,28 @@ print_sysvar_tokens(void)
printf("$%s\n", SysVarArr[i].name);
}
}
void
get_var_hash_stats(int *total, int *maxlen, double *avglen)
{
int len;
int i;
Var *v;
*maxlen = 0;
*total = 0;
for (i=0; i<VAR_HASH_SIZE; i++) {
len = 0;
v = VHashTbl[i];
while(v) {
len++;
(*total)++;
v = v->next;
}
if (len > *maxlen) {
*maxlen = len;
}
}
*avglen = (double) *total / (double) VAR_HASH_SIZE;
}

View File

@@ -5688,6 +5688,8 @@ Barf
DEBUG +s
# Don't want Remind to queue reminders
EXIT
Var hash: total = 141; maxlen = 8; avglen = 2.203
Func hash: total = 15; maxlen = 3; avglen = 0.469
Expression nodes allocated: 128
Expression nodes high-water: 73
Expression nodes leaked: 0
@@ -13139,6 +13141,8 @@ Parsed expression: isany("foo", 1 + 1, 2:00 + 1, '2021-01-01' + 1, '2021-01-01@1
"f" + "oo" => "foo"
isany("foo", 2, 02:01, 2021-01-02, 2021-01-01@14:01, "foo", ?) => 1
No reminders.
Var hash: total = 1; maxlen = 1; avglen = 0.016
Func hash: total = 0; maxlen = 0; avglen = 0.000
Expression nodes allocated: 512
Expression nodes high-water: 499
Expression nodes leaked: 0