PostgreSQL Source Code: src/backend/utils/adt/mcxtfuncs.c Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
17
22#include "catalog/pg_authid_d.h"
30#include "utils/wait_event_types.h"
31
32
33
34
35
36#define MEMORY_CONTEXT_IDENT_DISPLAY_SIZE 1024
39
40
41
42
43
46{
47 Datum *datum_array;
48 int length;
50
53
56
58
60}
61
62
63
64
65
66static void
69 HTAB *context_id_lookup)
70{
71#define PG_GET_BACKEND_MEMORY_CONTEXTS_COLS 10
72
77 const char *name;
78 const char *ident;
79 const char *type;
80
82
83
84
85
86
88 {
90 bool found;
91
93
94 if (!found)
95 elog(ERROR, "hash table corrupted");
97 }
98
99
100 memset(&stat, 0, sizeof(stat));
101 (*context->methods->stats) (context, NULL, NULL, &stat, true);
102
104 memset(nulls, 0, sizeof(nulls));
105
108
109
110
111
112
113 if (ident && strcmp(name, "dynahash") == 0)
114 {
117 }
118
121 else
122 nulls[0] = true;
123
125 {
126 int idlen = strlen(ident);
128
129
130
131
132
135
136 memcpy(clipped_ident, ident, idlen);
137 clipped_ident[idlen] = '\0';
139 }
140 else
141 nulls[1] = true;
142
144
153
156}
157
158
159
160
161
162
163
164const char *
166{
167 const char *context_type;
168
169 switch (type)
170 {
171 case T_AllocSetContext:
172 context_type = "AllocSet";
173 break;
174 case T_GenerationContext:
175 context_type = "Generation";
176 break;
177 case T_SlabContext:
178 context_type = "Slab";
179 break;
180 case T_BumpContext:
181 context_type = "Bump";
182 break;
183 default:
184 context_type = "???";
185 break;
186 }
187 return context_type;
188}
189
190
191
192
193
196{
198 int context_id;
199 List *contexts;
201 HTAB *context_id_lookup;
202
206
207 context_id_lookup = hash_create("pg_get_backend_memory_contexts",
208 256,
211
213
214
215
216
217
218
219
220
221
222
223
225
226
227 context_id = 1;
228
230 {
232 bool found;
233
234
235
236
237
238
243
247 context_id_lookup);
248
249
250
251
252
254 contexts = lappend(contexts, c);
255 }
256
258
259 return (Datum) 0;
260}
261
262
263
264
265
266
267
268
269
270
271
272
273
274
277{
281
282
283
284
286 if (proc == NULL)
288
289
290
291
292
293
294
295
296
297
298 if (proc == NULL)
299 {
300
301
302
303
305 (errmsg("PID %d is not a PostgreSQL server process", pid)));
307 }
308
311 {
312
314 (errmsg("could not send signal to process %d: %m", pid)));
316 }
317
319}
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354#define MEMSTATS_WAIT_TIMEOUT 100
357{
363 bool proc_is_aux = false;
367
368
369
370
371
373 if (proc == NULL)
374 {
376 proc_is_aux = true;
377 }
378
379
380
381
382
383
384 if (proc == NULL)
385 {
386
387
388
389
391 errmsg("PID %d is not a PostgreSQL server process", pid));
393 }
394
396
398
402
404
405
406
407
408
410 {
412 errmsg("could not send signal to process %d: %m", pid));
414 }
415
416
417
418
419
420
421
422
423
424
425 while (1)
426 {
427 long msecs;
428
429
430
431
432
433
434
435
436
437
439
440
441
442
443
444
445
446
447 if (memCxtState[procNumber].proc_id == pid)
448 {
449
450
451
452
453
455 memCxtState[procNumber].stats_timestamp);
456
458 && msecs > 0)
459 break;
460 }
462
463
464
465
466
467
468 if (proc_is_aux)
470 else
472
473
474
475
476
477 if (proc == NULL)
478 {
480 errmsg("PID %d is no longer a PostgreSQL server process",
481 pid));
483 }
484
486
487
488
489
490
491 if (msecs > 0 && msecs < (timeout * 1000))
492 {
493
494
495
496
497
498
499
500
502 ((timeout * 1000) - msecs), WAIT_EVENT_MEM_CXT_PUBLISH))
503 {
505
507 break;
508 else
509 {
512 }
513 }
514 }
515 else
516 {
518
520 break;
521 else
522 {
525 }
526 }
527 }
528
529
530
531
532
533
535
537 {
539
544 }
545
546
547
548
551
552#define PG_GET_PROCESS_MEMORY_CONTEXTS_COLS 12
554 {
561 Datum *path_datum = NULL;
562 int *path_int = NULL;
563
565 memset(nulls, 0, sizeof(nulls));
566
568 {
571 }
572 else
573 nulls[0] = true;
574
576 {
579 }
580 else
581 nulls[1] = true;
582
584
588 {
594 }
595 else
596 nulls[3] = true;
597
604 memcxt_info[i].freespace);
607
610 }
612
614
616}
617
620{
622 Size TotalProcs = 0;
623
627
629
630 return sz;
631}
632
633
634
635
636void
638{
639 bool found;
640
644
645 if (!found)
646 {
649 }
650
654 &found);
655
656 if (found)
657 return;
658
660 {
664 }
665}
ArrayType * construct_array_builtin(Datum *elems, int nelems, Oid elmtype)
long TimestampDifferenceMilliseconds(TimestampTz start_time, TimestampTz stop_time)
TimestampTz GetCurrentTimestamp(void)
static Datum values[MAXATTR]
#define CStringGetTextDatum(s)
bool ConditionVariableCancelSleep(void)
bool ConditionVariableTimedSleep(ConditionVariable *cv, long timeout, uint32 wait_event_info)
void ConditionVariableInit(ConditionVariable *cv)
dsa_area * dsa_attach(dsa_handle handle)
void * dsa_get_address(dsa_area *area, dsa_pointer dp)
void dsa_pin_mapping(dsa_area *area)
#define InvalidDsaPointer
#define DSA_HANDLE_INVALID
#define DsaPointerIsValid(x)
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
void hash_destroy(HTAB *hashp)
HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
Datum Int64GetDatum(int64 X)
#define PG_GETARG_FLOAT8(n)
#define PG_GETARG_INT32(n)
#define PG_GETARG_BOOL(n)
#define PG_RETURN_BOOL(x)
void InitMaterializedSRF(FunctionCallInfo fcinfo, bits32 flags)
Datum path_length(PG_FUNCTION_ARGS)
Assert(PointerIsAligned(start, uint64))
List * lappend(List *list, void *datum)
List * lcons_int(int datum, List *list)
void list_free(List *list)
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
void LWLockRelease(LWLock *lock)
void LWLockInitialize(LWLock *lock, int tranche_id)
@ LWTRANCHE_MEMORY_CONTEXT_REPORTING_PROC
@ LWTRANCHE_MEMORY_CONTEXT_REPORTING_STATE
int pg_mbcliplen(const char *mbstr, int len, int limit)
MemoryContext TopMemoryContext
MemoryContext CurrentMemoryContext
dsa_area * MemoryStatsDsaArea
Size MemoryContextReportingShmemSize(void)
const char * ContextTypeToString(NodeTag type)
struct MemoryStatsBackendState * memCxtState
static Datum int_list_to_array(const List *list)
Datum pg_get_process_memory_contexts(PG_FUNCTION_ARGS)
#define PG_GET_PROCESS_MEMORY_CONTEXTS_COLS
static void PutMemoryContextsStatsTupleStore(Tuplestorestate *tupstore, TupleDesc tupdesc, MemoryContext context, HTAB *context_id_lookup)
Datum pg_log_backend_memory_contexts(PG_FUNCTION_ARGS)
#define PG_GET_BACKEND_MEMORY_CONTEXTS_COLS
struct MemoryStatsCtl * memCxtArea
void MemoryContextReportingShmemInit(void)
#define MEMORY_CONTEXT_IDENT_DISPLAY_SIZE
Datum pg_get_backend_memory_contexts(PG_FUNCTION_ARGS)
#define MemoryContextIsValid(context)
struct MemoryStatsContextId MemoryStatsContextId
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
static int list_length(const List *l)
#define foreach_current_index(var_or_cell)
#define foreach_ptr(type, var, lst)
#define foreach_int(var, lst)
static Datum PointerGetDatum(const void *X)
static Datum Int32GetDatum(int32 X)
#define NUM_AUXILIARY_PROCS
#define GetNumberFromPGProc(proc)
PGPROC * BackendPidGetProc(int pid)
#define INVALID_PROC_NUMBER
int SendProcSignal(pid_t pid, ProcSignalReason reason, ProcNumber procNumber)
@ PROCSIG_GET_MEMORY_CONTEXT
@ PROCSIG_LOG_MEMORY_CONTEXT
Size add_size(Size s1, Size s2)
Size mul_size(Size s1, Size s2)
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
PGPROC * AuxiliaryPidGetProc(int pid)
const MemoryContextMethods * methods
void(* stats)(MemoryContext context, MemoryStatsPrintFunc printfunc, void *passthru, MemoryContextCounters *totals, bool print_to_stderr)
dsa_pointer memstats_dsa_pointer
dsa_handle memstats_dsa_handle
Tuplestorestate * setResult
void tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc, const Datum *values, const bool *isnull)
static Datum TimestampTzGetDatum(TimestampTz X)