Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 12227a1

Browse files
committed
Add context type field to pg_backend_memory_contexts
Since we now (as of v17) have 4 MemoryContext types, the type of context seems like useful information to include in the pg_backend_memory_contexts view. Here we add that. Reviewed-by: David Christensen, Michael Paquier Discussion: https://postgr.es/m/CAApHDvrXX1OR09Zjb5TnB0AwCKze9exZN%3D9Nxxg1ZCVV8W-3BA%40mail.gmail.com
1 parent e26d313 commit 12227a1

File tree

7 files changed

+53
-22
lines changed

7 files changed

+53
-22
lines changed

doc/src/sgml/system-views.sgml

+9
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,15 @@
490490
</para></entry>
491491
</row>
492492

493+
<row>
494+
<entry role="catalog_table_entry"><para role="column_definition">
495+
<structfield>type</structfield> <type>text</type>
496+
</para>
497+
<para>
498+
Type of the memory context
499+
</para></entry>
500+
</row>
501+
493502
<row>
494503
<entry role="catalog_table_entry"><para role="column_definition">
495504
<structfield>level</structfield> <type>int4</type>

src/backend/utils/adt/mcxtfuncs.c

+28-7
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,15 @@ PutMemoryContextsStatsTupleStore(Tuplestorestate *tupstore,
3636
TupleDesc tupdesc, MemoryContext context,
3737
const char *parent, int level)
3838
{
39-
#define PG_GET_BACKEND_MEMORY_CONTEXTS_COLS 9
39+
#define PG_GET_BACKEND_MEMORY_CONTEXTS_COLS 10
4040

4141
Datum values[PG_GET_BACKEND_MEMORY_CONTEXTS_COLS];
4242
bool nulls[PG_GET_BACKEND_MEMORY_CONTEXTS_COLS];
4343
MemoryContextCounters stat;
4444
MemoryContext child;
4545
const char *name;
4646
const char *ident;
47+
const char *type;
4748

4849
Assert(MemoryContextIsValid(context));
4950

@@ -96,12 +97,32 @@ PutMemoryContextsStatsTupleStore(Tuplestorestate *tupstore,
9697
else
9798
nulls[2] = true;
9899

99-
values[3] = Int32GetDatum(level);
100-
values[4] = Int64GetDatum(stat.totalspace);
101-
values[5] = Int64GetDatum(stat.nblocks);
102-
values[6] = Int64GetDatum(stat.freespace);
103-
values[7] = Int64GetDatum(stat.freechunks);
104-
values[8] = Int64GetDatum(stat.totalspace - stat.freespace);
100+
switch (context->type)
101+
{
102+
case T_AllocSetContext:
103+
type = "AllocSet";
104+
break;
105+
case T_GenerationContext:
106+
type = "Generation";
107+
break;
108+
case T_SlabContext:
109+
type = "Slab";
110+
break;
111+
case T_BumpContext:
112+
type = "Bump";
113+
break;
114+
default:
115+
type = "???";
116+
break;
117+
}
118+
119+
values[3] = CStringGetTextDatum(type);
120+
values[4] = Int32GetDatum(level);
121+
values[5] = Int64GetDatum(stat.totalspace);
122+
values[6] = Int64GetDatum(stat.nblocks);
123+
values[7] = Int64GetDatum(stat.freespace);
124+
values[8] = Int64GetDatum(stat.freechunks);
125+
values[9] = Int64GetDatum(stat.totalspace - stat.freespace);
105126
tuplestore_putvalues(tupstore, tupdesc, values, nulls);
106127

107128
for (child = context->firstchild; child != NULL; child = child->nextchild)

src/include/catalog/catversion.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@
5757
*/
5858

5959
/* yyyymmddN */
60-
#define CATALOG_VERSION_NO 202406281
60+
#define CATALOG_VERSION_NO 202407011
6161

6262
#endif

src/include/catalog/pg_proc.dat

+3-3
Original file line numberDiff line numberDiff line change
@@ -8279,9 +8279,9 @@
82798279
proname => 'pg_get_backend_memory_contexts', prorows => '100',
82808280
proretset => 't', provolatile => 'v', proparallel => 'r',
82818281
prorettype => 'record', proargtypes => '',
8282-
proallargtypes => '{text,text,text,int4,int8,int8,int8,int8,int8}',
8283-
proargmodes => '{o,o,o,o,o,o,o,o,o}',
8284-
proargnames => '{name, ident, parent, level, total_bytes, total_nblocks, free_bytes, free_chunks, used_bytes}',
8282+
proallargtypes => '{text,text,text,text,int4,int8,int8,int8,int8,int8}',
8283+
proargmodes => '{o,o,o,o,o,o,o,o,o,o}',
8284+
proargnames => '{name, ident, parent, type, level, total_bytes, total_nblocks, free_bytes, free_chunks, used_bytes}',
82858285
prosrc => 'pg_get_backend_memory_contexts' },
82868286

82878287
# logging memory contexts of the specified backend

src/test/regress/expected/rules.out

+2-1
Original file line numberDiff line numberDiff line change
@@ -1306,13 +1306,14 @@ pg_available_extensions| SELECT e.name,
13061306
pg_backend_memory_contexts| SELECT name,
13071307
ident,
13081308
parent,
1309+
type,
13091310
level,
13101311
total_bytes,
13111312
total_nblocks,
13121313
free_bytes,
13131314
free_chunks,
13141315
used_bytes
1315-
FROM pg_get_backend_memory_contexts() pg_get_backend_memory_contexts(name, ident, parent, level, total_bytes, total_nblocks, free_bytes, free_chunks, used_bytes);
1316+
FROM pg_get_backend_memory_contexts() pg_get_backend_memory_contexts(name, ident, parent, type, level, total_bytes, total_nblocks, free_bytes, free_chunks, used_bytes);
13161317
pg_config| SELECT name,
13171318
setting
13181319
FROM pg_config() pg_config(name, setting);

src/test/regress/expected/sysviews.out

+8-8
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ select count(*) >= 0 as ok from pg_available_extensions;
2121

2222
-- The entire output of pg_backend_memory_contexts is not stable,
2323
-- we test only the existence and basic condition of TopMemoryContext.
24-
select name, ident, parent, level, total_bytes >= free_bytes
24+
select type, name, ident, parent, level, total_bytes >= free_bytes
2525
from pg_backend_memory_contexts where level = 0;
26-
name | ident | parent | level | ?column?
27-
------------------+-------+--------+-------+----------
28-
TopMemoryContext | | | 0 | t
26+
type | name | ident | parent | level | ?column?
27+
----------+------------------+-------+--------+-------+----------
28+
AllocSet | TopMemoryContext | | | 0 | t
2929
(1 row)
3030

3131
-- We can exercise some MemoryContext type stats functions. Most of the
@@ -43,11 +43,11 @@ fetch 1 from cur;
4343
bbbbbbbbbb | 2
4444
(1 row)
4545

46-
select name, parent, total_bytes > 0, total_nblocks, free_bytes > 0, free_chunks
46+
select type, name, parent, total_bytes > 0, total_nblocks, free_bytes > 0, free_chunks
4747
from pg_backend_memory_contexts where name = 'Caller tuples';
48-
name | parent | ?column? | total_nblocks | ?column? | free_chunks
49-
---------------+----------------+----------+---------------+----------+-------------
50-
Caller tuples | TupleSort sort | t | 2 | t | 0
48+
type | name | parent | ?column? | total_nblocks | ?column? | free_chunks
49+
------+---------------+----------------+----------+---------------+----------+-------------
50+
Bump | Caller tuples | TupleSort sort | t | 2 | t | 0
5151
(1 row)
5252

5353
rollback;

src/test/regress/sql/sysviews.sql

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ select count(*) >= 0 as ok from pg_available_extensions;
1414

1515
-- The entire output of pg_backend_memory_contexts is not stable,
1616
-- we test only the existence and basic condition of TopMemoryContext.
17-
select name, ident, parent, level, total_bytes >= free_bytes
17+
select type, name, ident, parent, level, total_bytes >= free_bytes
1818
from pg_backend_memory_contexts where level = 0;
1919

2020
-- We can exercise some MemoryContext type stats functions. Most of the
@@ -28,7 +28,7 @@ declare cur cursor for select left(a,10), b
2828
from (values(repeat('a', 512 * 1024),1),(repeat('b', 512),2)) v(a,b)
2929
order by v.a desc;
3030
fetch 1 from cur;
31-
select name, parent, total_bytes > 0, total_nblocks, free_bytes > 0, free_chunks
31+
select type, name, parent, total_bytes > 0, total_nblocks, free_bytes > 0, free_chunks
3232
from pg_backend_memory_contexts where name = 'Caller tuples';
3333
rollback;
3434

0 commit comments

Comments
 (0)