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

Commitfb3d5da

Browse files
author
Alexander Korotkov
committed
Hooks for wait monitoring.
1 parentec09f50 commitfb3d5da

File tree

14 files changed

+255
-1
lines changed

14 files changed

+255
-1
lines changed

‎src/backend/access/transam/slru.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
#include"access/xlog.h"
5757
#include"storage/fd.h"
5858
#include"storage/shmem.h"
59+
#include"utils/wait.h"
5960
#include"miscadmin.h"
6061

6162

@@ -677,13 +678,17 @@ SlruPhysicalReadPage(SlruCtl ctl, int pageno, int slotno)
677678
}
678679

679680
errno=0;
681+
WAIT_START(WAIT_IO,WAIT_SLRU_READ,pageno,
682+
shared->lwlock_tranche_id,0,0,0);
680683
if (read(fd,shared->page_buffer[slotno],BLCKSZ)!=BLCKSZ)
681684
{
685+
WAIT_STOP();
682686
slru_errcause=SLRU_READ_FAILED;
683687
slru_errno=errno;
684688
CloseTransientFile(fd);
685689
return false;
686690
}
691+
WAIT_STOP();
687692

688693
if (CloseTransientFile(fd))
689694
{
@@ -836,8 +841,11 @@ SlruPhysicalWritePage(SlruCtl ctl, int pageno, int slotno, SlruFlush fdata)
836841
}
837842

838843
errno=0;
844+
WAIT_START(WAIT_IO,WAIT_SLRU_WRITE,pageno,
845+
shared->lwlock_tranche_id,0,0,0);
839846
if (write(fd,shared->page_buffer[slotno],BLCKSZ)!=BLCKSZ)
840847
{
848+
WAIT_STOP();
841849
/* if write didn't set errno, assume problem is no disk space */
842850
if (errno==0)
843851
errno=ENOSPC;
@@ -847,20 +855,25 @@ SlruPhysicalWritePage(SlruCtl ctl, int pageno, int slotno, SlruFlush fdata)
847855
CloseTransientFile(fd);
848856
return false;
849857
}
858+
WAIT_STOP();
850859

851860
/*
852861
* If not part of Flush, need to fsync now. We assume this happens
853862
* infrequently enough that it's not a performance issue.
854863
*/
855864
if (!fdata)
856865
{
866+
WAIT_START(WAIT_IO,WAIT_SLRU_FSYNC,pageno,
867+
shared->lwlock_tranche_id,0,0,0);
857868
if (ctl->do_fsync&&pg_fsync(fd))
858869
{
870+
WAIT_STOP();
859871
slru_errcause=SLRU_FSYNC_FAILED;
860872
slru_errno=errno;
861873
CloseTransientFile(fd);
862874
return false;
863875
}
876+
WAIT_STOP();
864877

865878
if (CloseTransientFile(fd))
866879
{

‎src/backend/access/transam/xlog.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
#include"utils/relmapper.h"
7171
#include"utils/snapmgr.h"
7272
#include"utils/timestamp.h"
73+
#include"utils/wait.h"
7374
#include"pg_trace.h"
7475

7576
externuint32bootstrap_data_checksum_version;
@@ -2276,6 +2277,9 @@ XLogWrite(XLogwrtRqst WriteRqst, bool flexible)
22762277
from=XLogCtl->pages+startidx* (Size)XLOG_BLCKSZ;
22772278
nbytes=npages* (Size)XLOG_BLCKSZ;
22782279
nleft=nbytes;
2280+
2281+
WAIT_START(WAIT_IO,WAIT_XLOG_WRITE,0,0,0,0,0);
2282+
22792283
do
22802284
{
22812285
errno=0;
@@ -2295,6 +2299,8 @@ XLogWrite(XLogwrtRqst WriteRqst, bool flexible)
22952299
from+=written;
22962300
}while (nleft>0);
22972301

2302+
WAIT_STOP();
2303+
22982304
/* Update state for write */
22992305
openLogOff+=nbytes;
23002306
npages=0;
@@ -2979,6 +2985,7 @@ XLogFileInit(XLogSegNo logsegno, bool *use_existent, bool use_lock)
29792985
*/
29802986
zbuffer= (char*)MAXALIGN(zbuffer_raw);
29812987
memset(zbuffer,0,XLOG_BLCKSZ);
2988+
WAIT_START(WAIT_IO,WAIT_XLOG_WRITE,0,0,0,0,0);
29822989
for (nbytes=0;nbytes<XLogSegSize;nbytes+=XLOG_BLCKSZ)
29832990
{
29842991
errno=0;
@@ -3001,14 +3008,17 @@ XLogFileInit(XLogSegNo logsegno, bool *use_existent, bool use_lock)
30013008
errmsg("could not write to file \"%s\": %m",tmppath)));
30023009
}
30033010
}
3011+
WAIT_STOP();
30043012

3013+
WAIT_START(WAIT_IO,WAIT_XLOG_FSYNC,0,0,0,0,0);
30053014
if (pg_fsync(fd)!=0)
30063015
{
30073016
close(fd);
30083017
ereport(ERROR,
30093018
(errcode_for_file_access(),
30103019
errmsg("could not fsync file \"%s\": %m",tmppath)));
30113020
}
3021+
WAIT_STOP();
30123022

30133023
if (close(fd))
30143024
ereport(ERROR,
@@ -3135,6 +3145,8 @@ XLogFileCopy(XLogSegNo destsegno, TimeLineID srcTLI, XLogSegNo srcsegno,
31353145
if (nread>sizeof(buffer))
31363146
nread=sizeof(buffer);
31373147
errno=0;
3148+
3149+
WAIT_START(WAIT_IO,WAIT_XLOG_READ,0,0,0,0,0);
31383150
if (read(srcfd,buffer,nread)!=nread)
31393151
{
31403152
if (errno!=0)
@@ -3147,8 +3159,10 @@ XLogFileCopy(XLogSegNo destsegno, TimeLineID srcTLI, XLogSegNo srcsegno,
31473159
(errmsg("not enough data in file \"%s\"",
31483160
path)));
31493161
}
3162+
WAIT_STOP();
31503163
}
31513164
errno=0;
3165+
WAIT_START(WAIT_IO,WAIT_XLOG_WRITE,0,0,0,0,0);
31523166
if ((int)write(fd,buffer,sizeof(buffer))!= (int)sizeof(buffer))
31533167
{
31543168
intsave_errno=errno;
@@ -3164,12 +3178,15 @@ XLogFileCopy(XLogSegNo destsegno, TimeLineID srcTLI, XLogSegNo srcsegno,
31643178
(errcode_for_file_access(),
31653179
errmsg("could not write to file \"%s\": %m",tmppath)));
31663180
}
3181+
WAIT_STOP();
31673182
}
31683183

3184+
WAIT_START(WAIT_IO,WAIT_XLOG_FSYNC,0,0,0,0,0);
31693185
if (pg_fsync(fd)!=0)
31703186
ereport(ERROR,
31713187
(errcode_for_file_access(),
31723188
errmsg("could not fsync file \"%s\": %m",tmppath)));
3189+
WAIT_STOP();
31733190

31743191
if (CloseTransientFile(fd))
31753192
ereport(ERROR,
@@ -9626,6 +9643,8 @@ assign_xlog_sync_method(int new_sync_method, void *extra)
96269643
void
96279644
issue_xlog_fsync(intfd,XLogSegNosegno)
96289645
{
9646+
WAIT_START(WAIT_IO,WAIT_XLOG_FSYNC,0,0,0,0,0);
9647+
96299648
switch (sync_method)
96309649
{
96319650
caseSYNC_METHOD_FSYNC:
@@ -9661,6 +9680,8 @@ issue_xlog_fsync(int fd, XLogSegNo segno)
96619680
elog(PANIC,"unrecognized wal_sync_method: %d",sync_method);
96629681
break;
96639682
}
9683+
9684+
WAIT_STOP();
96649685
}
96659686

96669687
/*
@@ -11000,6 +11021,8 @@ XLogPageRead(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr, int reqLen,
1100011021
gotonext_record_is_invalid;
1100111022
}
1100211023

11024+
WAIT_START(WAIT_IO,WAIT_XLOG_READ,0,0,0,0,0);
11025+
1100311026
if (read(readFile,readBuf,XLOG_BLCKSZ)!=XLOG_BLCKSZ)
1100411027
{
1100511028
charfname[MAXFNAMELEN];
@@ -11012,6 +11035,8 @@ XLogPageRead(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr, int reqLen,
1101211035
gotonext_record_is_invalid;
1101311036
}
1101411037

11038+
WAIT_STOP();
11039+
1101511040
Assert(targetSegNo==readSegNo);
1101611041
Assert(targetPageOff==readOff);
1101711042
Assert(reqLen <=readLen);

‎src/backend/libpq/be-secure.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include"miscadmin.h"
3636
#include"tcop/tcopprot.h"
3737
#include"utils/memutils.h"
38+
#include"utils/wait.h"
3839
#include"storage/proc.h"
3940

4041

@@ -122,6 +123,8 @@ secure_read(Port *port, void *ptr, size_t len)
122123
ssize_tn;
123124
intwaitfor;
124125

126+
WAIT_START(WAIT_NETWORK,WAIT_NETWORK_READ,0,0,0,0,0);
127+
125128
retry:
126129
#ifdefUSE_SSL
127130
waitfor=0;
@@ -169,6 +172,8 @@ secure_read(Port *port, void *ptr, size_t len)
169172
*/
170173
ProcessClientReadInterrupt(false);
171174

175+
WAIT_STOP();
176+
172177
returnn;
173178
}
174179

@@ -177,6 +182,8 @@ secure_raw_read(Port *port, void *ptr, size_t len)
177182
{
178183
ssize_tn;
179184

185+
WAIT_START(WAIT_NETWORK,WAIT_NETWORK_READ,0,0,0,0,0);
186+
180187
/*
181188
* Try to read from the socket without blocking. If it succeeds we're
182189
* done, otherwise we'll wait for the socket using the latch mechanism.
@@ -189,6 +196,8 @@ secure_raw_read(Port *port, void *ptr, size_t len)
189196
pgwin32_noblock= false;
190197
#endif
191198

199+
WAIT_STOP();
200+
192201
returnn;
193202
}
194203

@@ -202,6 +211,8 @@ secure_write(Port *port, void *ptr, size_t len)
202211
ssize_tn;
203212
intwaitfor;
204213

214+
WAIT_START(WAIT_NETWORK,WAIT_NETWORK_WRITE,0,0,0,0,0);
215+
205216
retry:
206217
waitfor=0;
207218
#ifdefUSE_SSL
@@ -248,6 +259,8 @@ secure_write(Port *port, void *ptr, size_t len)
248259
*/
249260
ProcessClientWriteInterrupt(false);
250261

262+
WAIT_STOP();
263+
251264
returnn;
252265
}
253266

@@ -256,6 +269,8 @@ secure_raw_write(Port *port, const void *ptr, size_t len)
256269
{
257270
ssize_tn;
258271

272+
WAIT_START(WAIT_NETWORK,WAIT_NETWORK_WRITE,0,0,0,0,0);
273+
259274
#ifdefWIN32
260275
pgwin32_noblock= true;
261276
#endif
@@ -264,5 +279,7 @@ secure_raw_write(Port *port, const void *ptr, size_t len)
264279
pgwin32_noblock= false;
265280
#endif
266281

282+
WAIT_STOP();
283+
267284
returnn;
268285
}

‎src/backend/port/unix_latch.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
#include"storage/latch.h"
5656
#include"storage/pmsignal.h"
5757
#include"storage/shmem.h"
58+
#include"utils/wait.h"
5859

5960
/* Are we currently in WaitLatch? The signal handler would like to know. */
6061
staticvolatilesig_atomic_twaiting= false;
@@ -262,6 +263,7 @@ WaitLatchOrSocket(volatile Latch *latch, int wakeEvents, pgsocket sock,
262263
#endif
263264
}
264265

266+
WAIT_START(WAIT_LATCH,0,0,0,0,0,0);
265267
waiting= true;
266268
do
267269
{
@@ -500,6 +502,7 @@ WaitLatchOrSocket(volatile Latch *latch, int wakeEvents, pgsocket sock,
500502
}
501503
}while (result==0);
502504
waiting= false;
505+
WAIT_STOP();
503506

504507
returnresult;
505508
}

‎src/backend/port/win32_latch.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include"storage/latch.h"
3232
#include"storage/pmsignal.h"
3333
#include"storage/shmem.h"
34+
#include"utils/wait.h"
3435

3536

3637
void
@@ -177,6 +178,7 @@ WaitLatchOrSocket(volatile Latch *latch, int wakeEvents, pgsocket sock,
177178
/* Ensure that signals are serviced even if latch is already set */
178179
pgwin32_dispatch_queued_signals();
179180

181+
WAIT_START(WAIT_LATCH,0,0,0,0,0,0);
180182
do
181183
{
182184
/*
@@ -277,6 +279,7 @@ WaitLatchOrSocket(volatile Latch *latch, int wakeEvents, pgsocket sock,
277279
}
278280
}
279281
}while (result==0);
282+
WAIT_STOP();
280283

281284
/* Clean up the event object we created for the socket */
282285
if (sockevent!=WSA_INVALID_EVENT)

‎src/backend/storage/buffer/bufmgr.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#include"utils/rel.h"
5151
#include"utils/resowner_private.h"
5252
#include"utils/timestamp.h"
53+
#include"utils/wait.h"
5354

5455

5556
/* Note: these two macros only work on shared buffers, not local ones! */
@@ -3290,6 +3291,8 @@ LockBufferForCleanup(Buffer buffer)
32903291
UnlockBufHdr(bufHdr);
32913292
LockBuffer(buffer,BUFFER_LOCK_UNLOCK);
32923293

3294+
LWLockReportStartWait(BufferDescriptorGetContentLock(bufHdr));
3295+
32933296
/* Wait to be signaled by UnpinBuffer() */
32943297
if (InHotStandby)
32953298
{
@@ -3303,6 +3306,8 @@ LockBufferForCleanup(Buffer buffer)
33033306
else
33043307
ProcWaitForSignal();
33053308

3309+
LWLockReportStopWait();
3310+
33063311
/*
33073312
* Remove flag marking us as waiter. Normally this will not be set
33083313
* anymore, but ProcWaitForSignal() can return for other signals as

‎src/backend/storage/lmgr/lock.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include"utils/memutils.h"
4747
#include"utils/ps_status.h"
4848
#include"utils/resowner_private.h"
49+
#include"utils/wait.h"
4950

5051

5152
/* This configuration variable is used to set the lock table size */
@@ -979,8 +980,16 @@ LockAcquireExtended(const LOCKTAG *locktag,
979980
locktag->locktag_type,
980981
lockmode);
981982

983+
WAIT_START(WAIT_LOCK,locktag->locktag_type,lockmode,
984+
locktag->locktag_field1,
985+
locktag->locktag_field2,
986+
locktag->locktag_field3,
987+
locktag->locktag_field4);
988+
982989
WaitOnLock(locallock,owner);
983990

991+
WAIT_STOP();
992+
984993
TRACE_POSTGRESQL_LOCK_WAIT_DONE(locktag->locktag_field1,
985994
locktag->locktag_field2,
986995
locktag->locktag_field3,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp