On Tue, Jul 5, 2016 at 8:48 PM, Tom Lane <t...@sss.pgh.pa.us> wrote: > Unfortunately the way I did (1) only works on systems with pmap; I'm not > sure how to make it more portable.
I did a similar(ish) test which is admittedly not as exhaustive as using pmap. I instrumented check_stack_depth() itself to keep track of a high water mark (and based on Robert's thought process) to keep track of the largest increment over the previous checked stack depth. This doesn't cover any cases where there's no check_stack_depth() call in the call stack at all (but then if there's no check_stack_depth call at all it's hard to see how any setting of STACK_DEPTH_SLOP is necessarily going to help). I see similar results to you. The regexp test shows: LOG: disconnection: highest stack depth: 392256 largest stack increment: 35584 And the: STATEMENT: select infinite_recurse(); LOG: disconnection: highest stack depth: 2097584 largest stack increment: 1936 There were a couple other tests with similar stack increase increments to the regular expression test: STATEMENT: alter table atacc2 add constraint foo check (test>0) no inherit; LOG: disconnection: highest stack depth: 39232 largest stack increment: 34224 STATEMENT: SELECT chr(0); LOG: disconnection: highest stack depth: 44144 largest stack increment: 34512 But aside from those two the next largest increment between two success check_stack_depth calls was about 12kB: STATEMENT: select array_elem_check(121.00); LOG: disconnection: highest stack depth: 24256 largest stack increment: 12896 This was all on x86_64 too. -- greg
diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c index b185c1b..b5d7f80 100644 --- a/src/backend/tcop/postgres.c +++ b/src/backend/tcop/postgres.c @@ -3120,6 +3120,24 @@ check_stack_depth(void) } } +#ifdef DEBUG_STACK_DEPTH +long last_stack_depth = 0; +long high_stack_depth = 0; +long high_stack_incr = 0; +bool stack_depth_on_proc_exit = 0; + +/* + * on_proc_exit handler to log end of session + */ +static void +log_stack_depth(int code, Datum arg) +{ + ereport(LOG, + (errmsg("disconnection: highest stack depth: %lu largest stack increment: %lu", + high_stack_depth, high_stack_incr))); +} +#endif + bool stack_is_too_deep(void) { @@ -3137,6 +3155,21 @@ stack_is_too_deep(void) if (stack_depth < 0) stack_depth = -stack_depth; +#ifdef DEBUG_STACK_DEPTH + /* book-keeping for measuring STACK_DEPTH_SLOP */ + if (stack_depth > high_stack_depth) + high_stack_depth = stack_depth; + if (stack_depth - last_stack_depth > high_stack_incr) + high_stack_incr = stack_depth - last_stack_depth; + last_stack_depth = stack_depth; + + if (!stack_depth_on_proc_exit) + { + stack_depth_on_proc_exit = 1; + on_proc_exit(log_stack_depth, 0); + } +#endif + /* * Trouble? *
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers