Skip to content

Commit d9e0386

Browse files
committed
Make levels 1-based in pg_log_backend_memory_contexts()
Both pg_get_process_memory_contexts() and pg_backend_memory_contexts have 1-based levels, whereas pg_log_backend_memory_contexts() was using 0-based levels. Align these. This results in slightly saner behavior from MemoryContextStatsDetail() in regards to the max_level. Previously it would stop at 1 level before the maximum requested level rather than at that level. Reported-by: Atsushi Torikoshi <torikoshia@oss.nttdata.com> Author: Atsushi Torikoshi <torikoshia@oss.nttdata.com> Author: David Rowley <drowleyml@gmail.com Reviewed-by: Melih Mutlu <m.melihmutlu@gmail.com> Reviewed-by: Rahila Syed <rahilasyed90@gmail.com> Discussion: https://postgr.es/m/395ea5d4fe190480efa95bf533485c70@oss.nttdata.com
1 parent fc5e966 commit d9e0386

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/backend/utils/mmgr/mcxt.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,7 @@ MemoryContextStatsDetail(MemoryContext context,
873873
print_location = PRINT_STATS_TO_LOGS;
874874

875875
/* num_contexts report number of contexts aggregated in the output */
876-
MemoryContextStatsInternal(context, 0, max_level, max_children,
876+
MemoryContextStatsInternal(context, 1, max_level, max_children,
877877
&grand_totals, print_location, &num_contexts);
878878

879879
if (print_to_stderr)
@@ -968,7 +968,7 @@ MemoryContextStatsInternal(MemoryContext context, int level,
968968
*/
969969
child = context->firstchild;
970970
ichild = 0;
971-
if (level < max_level && !stack_is_too_deep())
971+
if (level <= max_level && !stack_is_too_deep())
972972
{
973973
for (; child != NULL && ichild < max_children;
974974
child = child->nextchild, ichild++)
@@ -1003,7 +1003,7 @@ MemoryContextStatsInternal(MemoryContext context, int level,
10031003

10041004
if (print_location == PRINT_STATS_TO_STDERR)
10051005
{
1006-
for (int i = 0; i <= level; i++)
1006+
for (int i = 0; i < level; i++)
10071007
fprintf(stderr, " ");
10081008
fprintf(stderr,
10091009
"%d more child contexts containing %zu total in %zu blocks; %zu free (%zu chunks); %zu used\n",
@@ -1104,7 +1104,7 @@ MemoryContextStatsPrint(MemoryContext context, void *passthru,
11041104

11051105
if (print_to_stderr)
11061106
{
1107-
for (i = 0; i < level; i++)
1107+
for (i = 1; i < level; i++)
11081108
fprintf(stderr, " ");
11091109
fprintf(stderr, "%s: %s%s\n", name, stats_string, truncated_ident);
11101110
}
@@ -1585,12 +1585,11 @@ ProcessGetMemoryContextInterrupt(void)
15851585
{
15861586
MemoryContextCounters grand_totals;
15871587
int num_contexts = 0;
1588-
int level = 0;
15891588

15901589
path = NIL;
15911590
memset(&grand_totals, 0, sizeof(grand_totals));
15921591

1593-
MemoryContextStatsInternal(c, level, 100, 100, &grand_totals,
1592+
MemoryContextStatsInternal(c, 1, 100, 100, &grand_totals,
15941593
PRINT_STATS_NONE, &num_contexts);
15951594

15961595
path = compute_context_path(c, context_id_lookup);

0 commit comments

Comments
 (0)