Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdec6c5a

Browse files
author
Alexander Korotkov
committed
Online history parameters change.
1 parent0079269 commitdec6c5a

File tree

3 files changed

+84
-25
lines changed

3 files changed

+84
-25
lines changed

‎contrib/pg_stat_wait/collector.c

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,44 @@ AllocHistory(History *observations, int count)
6666
observations->wraparound= false;
6767
}
6868

69+
/*
70+
* Reallocate memory for changed number of history items.
71+
*/
72+
staticvoid
73+
ReallocHistory(History*observations,intcount)
74+
{
75+
HistoryItem*newitems;
76+
intcopyCount;
77+
inti,j;
78+
79+
newitems= (HistoryItem*)palloc0(sizeof(HistoryItem)*count);
80+
81+
if (observations->wraparound)
82+
copyCount=observations->count;
83+
else
84+
copyCount=observations->index;
85+
86+
copyCount=Min(copyCount,count);
87+
88+
i=0;
89+
j=observations->index;
90+
while (i<copyCount)
91+
{
92+
j--;
93+
if (j<0)
94+
j=observations->count-1;
95+
memcpy(&newitems[i],&observations->items[j],sizeof(HistoryItem));
96+
i++;
97+
}
98+
99+
pfree(observations->items);
100+
observations->items=newitems;
101+
102+
observations->index=copyCount;
103+
observations->count=count;
104+
observations->wraparound= false;
105+
}
106+
69107
/*
70108
* Read current wait information for given proc.
71109
*/
@@ -137,7 +175,12 @@ get_next_observation(History *observations)
137175
staticvoid
138176
write_waits_history(History*observations,TimestampTzcurrent_ts)
139177
{
140-
inti;
178+
inti,
179+
newSize;
180+
181+
newSize=collector_hdr->historySize;
182+
if (observations->count!=newSize)
183+
ReallocHistory(observations,newSize);
141184

142185
LWLockAcquire(ProcArrayLock,LW_SHARED);
143186
for (i=0;i<ProcGlobal->allProcCount;i++)
@@ -151,7 +194,7 @@ write_waits_history(History *observations, TimestampTz current_ts)
151194
if (proc->pid==0)
152195
continue;
153196

154-
if (historySkipLatch&&item.classid==WAIT_LATCH)
197+
if (collector_hdr->historySkipLatch&&item.classid==WAIT_LATCH)
155198
continue;
156199

157200
item.ts=current_ts;
@@ -212,7 +255,7 @@ collector_main(Datum main_arg)
212255
ALLOCSET_DEFAULT_INITSIZE,
213256
ALLOCSET_DEFAULT_MAXSIZE);
214257
old_context=MemoryContextSwitchTo(collector_context);
215-
AllocHistory(&observations,historySize);
258+
AllocHistory(&observations,collector_hdr->historySize);
216259
MemoryContextSwitchTo(old_context);
217260

218261
while (1)
@@ -230,7 +273,7 @@ collector_main(Datum main_arg)
230273

231274
rc=WaitLatch(&MyProc->procLatch,
232275
WL_LATCH_SET |WL_TIMEOUT |WL_POSTMASTER_DEATH,
233-
historyPeriod);
276+
collector_hdr->historyPeriod);
234277

235278
if (rc&WL_POSTMASTER_DEATH)
236279
exit(1);

‎contrib/pg_stat_wait/pg_stat_wait.c

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include"postmaster/autovacuum.h"
1919
#include"storage/spin.h"
2020
#include"storage/ipc.h"
21+
#include"storage/pg_shmem.h"
2122
#include"storage/procarray.h"
2223
#include"storage/shm_mq.h"
2324
#include"storage/shm_toc.h"
@@ -33,9 +34,6 @@ void_PG_fini(void);
3334
/* Global variables */
3435
boolshmem_initialized= false;
3536
boolwaitsHistoryOn;
36-
inthistorySize;
37-
inthistoryPeriod;
38-
boolhistorySkipLatch;
3937

4038
/* Shared memory variables */
4139
shm_toc*toc=NULL;
@@ -107,6 +105,21 @@ init_current_wait_event()
107105
}
108106
}
109107

108+
staticbool
109+
shmem_int_guc_check_hook(int*newval,void**extra,GucSourcesource)
110+
{
111+
if (UsedShmemSegAddr==NULL)
112+
return false;
113+
return true;
114+
}
115+
116+
staticbool
117+
shmem_bool_guc_check_hook(bool*newval,void**extra,GucSourcesource)
118+
{
119+
if (UsedShmemSegAddr==NULL)
120+
return false;
121+
return true;
122+
}
110123

111124
/*
112125
* Distribute shared memory.
@@ -159,6 +172,24 @@ pgsw_shmem_startup(void)
159172
}
160173
}
161174

175+
if (waitsHistoryOn)
176+
{
177+
DefineCustomIntVariable("pg_stat_wait.history_size",
178+
"Sets size of waits history.",NULL,
179+
&collector_hdr->historySize,5000,100,INT_MAX,
180+
PGC_SUSET,0,shmem_int_guc_check_hook,NULL,NULL);
181+
182+
DefineCustomIntVariable("pg_stat_wait.history_period",
183+
"Sets period of waits history sampling.",NULL,
184+
&collector_hdr->historyPeriod,10,1,INT_MAX,
185+
PGC_SUSET,0,shmem_int_guc_check_hook,NULL,NULL);
186+
187+
DefineCustomBoolVariable("pg_stat_wait.history_skip_latch",
188+
"Skip latch events in waits history",NULL,
189+
&collector_hdr->historySkipLatch, false,
190+
PGC_SUSET,0,shmem_bool_guc_check_hook,NULL,NULL);
191+
}
192+
162193
shmem_initialized= true;
163194

164195
if (prev_shmem_startup_hook)
@@ -398,20 +429,6 @@ _PG_init(void)
398429
DefineCustomBoolVariable("pg_stat_wait.history","Collect waits history",
399430
NULL,&waitsHistoryOn, false,PGC_POSTMASTER,0,NULL,NULL,NULL);
400431

401-
DefineCustomIntVariable("pg_stat_wait.history_size",
402-
"Sets size of waits history.",NULL,
403-
&historySize,5000,100,INT_MAX,
404-
PGC_POSTMASTER,0,NULL,NULL,NULL);
405-
406-
DefineCustomIntVariable("pg_stat_wait.history_period",
407-
"Sets period of waits history sampling.",NULL,
408-
&historyPeriod,10,1,INT_MAX,
409-
PGC_POSTMASTER,0,NULL,NULL,NULL);
410-
411-
DefineCustomBoolVariable("pg_stat_wait.history_skip_latch",
412-
"Skip latch events in waits history",NULL,
413-
&historySkipLatch, false,PGC_POSTMASTER,0,NULL,NULL,NULL);
414-
415432
/* Calculate maximem number of processes */
416433
maxProcs=MaxConnections+autovacuum_max_workers+1+
417434
max_worker_processes+NUM_AUXILIARY_PROCS;

‎contrib/pg_stat_wait/pg_stat_wait.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ typedef struct
9292
{
9393
Latch*latch;
9494
SHMRequestrequest;
95+
inthistorySize;
96+
inthistoryPeriod;
97+
boolhistorySkipLatch;
9598
}CollectorShmqHeader;
9699

97100
#defineWAIT_EVENTS_COUNT (WAIT_CPU_EVENTS_COUNT + 1 + WAIT_LWLOCKS_COUNT + \
@@ -112,10 +115,6 @@ extern void check_shmem(void);
112115
externCollectorShmqHeader*collector_hdr;
113116
externCurrentWaitEventWrap*cur_wait_events;
114117
externshm_mq*collector_mq;
115-
externinthistorySize;
116-
externinthistoryPeriod;
117-
externboolhistorySkipLatch;
118-
119118

120119
externvoidRegisterWaitsCollector(void);
121120
externvoidAllocHistory(History*,int);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp