Skip to content

Commit 0d06faf

Browse files
committed
Move allocations event to CPU class
1 parent ae78219 commit 0d06faf

File tree

4 files changed

+37
-27
lines changed

4 files changed

+37
-27
lines changed

Diff for: contrib/pg_stat_wait/pg_stat_wait.c

+6-5
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pg_wait_class_list(PG_FUNCTION_ARGS)
9191
TupleDesc tupdesc;
9292

9393
funcctx = SRF_FIRSTCALL_INIT();
94-
funcctx->max_calls = WAITS_COUNT - 1;
94+
funcctx->max_calls = WAITS_COUNT;
9595

9696
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
9797

@@ -119,7 +119,7 @@ pg_wait_class_list(PG_FUNCTION_ARGS)
119119
MemSet(values, 0, sizeof(values));
120120
MemSet(nulls, 0, sizeof(nulls));
121121

122-
idx = funcctx->call_cntr + 1;
122+
idx = funcctx->call_cntr;
123123
values[0] = Int32GetDatum(idx);
124124
values[1] = CStringGetDatum(WAIT_CLASSES[idx]);
125125

@@ -163,7 +163,6 @@ pg_wait_event_list(PG_FUNCTION_ARGS)
163163
funcctx->tuple_desc = BlessTupleDesc(tupdesc);
164164
funcctx->user_fctx = palloc0(sizeof(WaitEventContext));
165165

166-
((WaitEventContext *)funcctx->user_fctx)->class_cnt = 1;
167166
MemoryContextSwitchTo(oldcontext);
168167
}
169168

@@ -185,7 +184,9 @@ pg_wait_event_list(PG_FUNCTION_ARGS)
185184
values[1] = Int32GetDatum(ctx->event_cnt);
186185
values[2] = CStringGetDatum(WaitsEventName(ctx->class_cnt, ctx->event_cnt));
187186

188-
if (ctx->class_cnt == WAIT_LWLOCK && ctx->event_cnt < (LWLockTranchesCount()-1))
187+
if (ctx->class_cnt == WAIT_CPU && ctx->event_cnt < (WAIT_CPU_EVENTS_COUNT-1))
188+
ctx->event_cnt++;
189+
else if (ctx->class_cnt == WAIT_LWLOCK && ctx->event_cnt < (LWLockTranchesCount()-1))
189190
ctx->event_cnt++;
190191
else if (ctx->class_cnt == WAIT_LOCK && ctx->event_cnt < (WAIT_LOCKS_COUNT-1))
191192
ctx->event_cnt++;
@@ -456,7 +457,7 @@ pg_stat_wait_get_profile(PG_FUNCTION_ARGS)
456457

457458
if (params->eventIdx == WAIT_EVENTS_COUNT)
458459
{
459-
params->classIdx = WAIT_LWLOCK;
460+
params->classIdx = 0;
460461
params->eventIdx = 0;
461462
params->backendIdx++;
462463
Assert(params->backendIdx <= MaxBackends);

Diff for: src/backend/storage/lmgr/wait.c

+10-9
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,17 @@ int WaitsFlushPeriod;
2121

2222
const char *WAIT_CLASSES[] =
2323
{
24-
"",
24+
"CPU",
2525
"LWLocks",
2626
"Locks",
2727
"Storage",
2828
"Latch",
29-
"Network",
30-
"Allocations"
29+
"Network"
30+
};
31+
32+
const char *WAIT_CPU_NAMES[] =
33+
{
34+
"MemAllocation"
3135
};
3236

3337
const char *WAIT_IO_NAMES[] =
@@ -52,13 +56,12 @@ const char *WAIT_NETWORK_NAMES[] =
5256

5357
const int WAIT_OFFSETS[] =
5458
{
55-
0, /* skip */
59+
WAIT_CPU_OFFSET,
5660
WAIT_LWLOCKS_OFFSET,
5761
WAIT_LOCKS_OFFSET,
5862
WAIT_IO_OFFSET,
5963
WAIT_LATCH_OFFSET,
60-
WAIT_NETWORK_OFFSET,
61-
WAIT_ALLOC_OFFSET
64+
WAIT_NETWORK_OFFSET
6265
};
6366

6467
/* Returns event name for wait */
@@ -68,11 +71,11 @@ WaitsEventName(int classId, int eventId)
6871
static char *empty = "";
6972
switch (classId)
7073
{
74+
case WAIT_CPU: return WAIT_CPU_NAMES[eventId];
7175
case WAIT_LOCK: return LOCK_NAMES[eventId];
7276
case WAIT_LWLOCK: return LWLOCK_TRANCHE_NAME(eventId);
7377
case WAIT_IO: return WAIT_IO_NAMES[eventId];
7478
case WAIT_NETWORK: return WAIT_NETWORK_NAMES[eventId];
75-
case WAIT_ALLOC: /* fallthrough */;
7679
case WAIT_LATCH: return WAIT_CLASSES[classId];
7780
};
7881
return empty;
@@ -232,8 +235,6 @@ StartWait(int classId, int eventId, int p1, int p2, int p3, int p4, int p5)
232235
ProcWaits *waits;
233236
ProcWait *curwait;
234237

235-
Assert(classId > 0 && classId < WAITS_COUNT);
236-
237238
if (!MyProc || !WaitsInitialized)
238239
return;
239240

Diff for: src/backend/utils/mmgr/aset.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ AllocSetContextCreate(MemoryContext parent,
496496
Size blksize = MAXALIGN(minContextSize);
497497
AllocBlock block;
498498

499-
WAIT_START(WAIT_ALLOC, 0, 0, 0, 0, 0, 0);
499+
WAIT_START(WAIT_CPU, WAIT_MALLOC, 0, 0, 0, 0, 0);
500500
block = (AllocBlock) malloc(blksize);
501501
WAIT_STOP();
502502
if (block == NULL)
@@ -677,7 +677,7 @@ AllocSetAlloc(MemoryContext context, Size size)
677677
{
678678
chunk_size = MAXALIGN(size);
679679
blksize = chunk_size + ALLOC_BLOCKHDRSZ + ALLOC_CHUNKHDRSZ;
680-
WAIT_START(WAIT_ALLOC, 0, 0, 0, 0, 0, 0);
680+
WAIT_START(WAIT_CPU, WAIT_MALLOC, 0, 0, 0, 0, 0);
681681
block = (AllocBlock) malloc(blksize);
682682
WAIT_STOP();
683683
if (block == NULL)
@@ -860,7 +860,7 @@ AllocSetAlloc(MemoryContext context, Size size)
860860
blksize <<= 1;
861861

862862
/* Try to allocate it */
863-
WAIT_START(WAIT_ALLOC, 0, 0, 0, 0, 0, 0);
863+
WAIT_START(WAIT_CPU, WAIT_MALLOC, 0, 0, 0, 0, 0);
864864
block = (AllocBlock) malloc(blksize);
865865

866866
/*

Diff for: src/include/storage/wait.h

+18-10
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,33 @@
2222
2323
Monitored waits by now:
2424
25-
1) Heavy-weight locks (lock.c)
26-
2) LW-Locks (lwlock.c)
27-
3) IO read-write (md.c)
28-
4) Network (be-secure.c)
29-
5) Latches (pg_latch.c)
25+
1) CPU events. For now it is on memory chunks allocation
26+
2) Heavy-weight locks (lock.c)
27+
3) LW-Locks (lwlock.c)
28+
4) IO read-write (md.c)
29+
5) Network (be-secure.c)
30+
6) Latches (pg_latch.c)
3031
*/
3132

3233
enum WaitClasses
3334
{
34-
WAIT_LWLOCK = 1,
35+
WAIT_CPU,
36+
WAIT_LWLOCK,
3537
WAIT_LOCK,
3638
WAIT_IO,
3739
WAIT_LATCH,
3840
WAIT_NETWORK,
39-
WAIT_ALLOC,
4041
/* Last item as count */
4142
WAITS_COUNT
4243
} WaitClasses;
4344

45+
enum WaitCPUEvents
46+
{
47+
WAIT_MALLOC,
48+
/* Last item as count */
49+
WAIT_CPU_EVENTS_COUNT
50+
} WaitCPUEvents;
51+
4452
enum WaitIOEvents
4553
{
4654
WAIT_SMGR_READ,
@@ -69,13 +77,13 @@ enum WaitNetworkEvents
6977
#define WAIT_LOCKS_COUNT (LOCKTAG_LAST_TYPE + 1)
7078

7179
/* Waits in arrays in backends and in shared memory located by offsets */
72-
#define WAIT_LWLOCKS_OFFSET 0
80+
#define WAIT_CPU_OFFSET 0
81+
#define WAIT_LWLOCKS_OFFSET (WAIT_CPU_OFFSET + WAIT_CPU_EVENTS_COUNT)
7382
#define WAIT_LOCKS_OFFSET (WAIT_LWLOCKS_OFFSET + WAIT_LWLOCKS_COUNT)
7483
#define WAIT_IO_OFFSET (WAIT_LOCKS_OFFSET + WAIT_LOCKS_COUNT)
7584
#define WAIT_LATCH_OFFSET (WAIT_IO_OFFSET + WAIT_IO_EVENTS_COUNT)
7685
#define WAIT_NETWORK_OFFSET (WAIT_LATCH_OFFSET + 1)
77-
#define WAIT_ALLOC_OFFSET (WAIT_NETWORK_OFFSET + WAIT_NETWORK_EVENTS_COUNT)
78-
#define WAIT_EVENTS_COUNT (WAIT_ALLOC_OFFSET + 1)
86+
#define WAIT_EVENTS_COUNT (WAIT_NETWORK_OFFSET + WAIT_NETWORK_EVENTS_COUNT)
7987

8088
#define WAIT_START(classId, eventId, p1, p2, p3, p4, p5) \
8189
do { \

0 commit comments

Comments
 (0)