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

Commitaa65de0

Browse files
committed
When trace_lwlocks is used, identify individual lwlocks by name.
Naming the individual lwlocks seems like something that may be usefulfor other types of debugging, monitoring, or instrumentation output,but this commit just implements it for the specific case oftrace_lwlocks.Patch by me, reviewed by Amit Kapila and Kyotaro Horiguchi
1 parenta1b2888 commitaa65de0

File tree

9 files changed

+201
-69
lines changed

9 files changed

+201
-69
lines changed

‎src/backend/Makefile

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ endif
106106
endif# aix
107107

108108
# Update the commonly used headers before building the subdirectories
109-
$(SUBDIRS:%=%-recursive):$(top_builddir)/src/include/parser/gram.h$(top_builddir)/src/include/catalog/schemapg.h$(top_builddir)/src/include/utils/fmgroids.h$(top_builddir)/src/include/utils/errcodes.h$(top_builddir)/src/include/utils/probes.h
109+
$(SUBDIRS:%=%-recursive):$(top_builddir)/src/include/parser/gram.h$(top_builddir)/src/include/catalog/schemapg.h$(top_builddir)/src/include/storage/lwlocknames.h$(top_builddir)/src/include/utils/fmgroids.h$(top_builddir)/src/include/utils/errcodes.h$(top_builddir)/src/include/utils/probes.h
110110

111111
# run this unconditionally to avoid needing to know its dependencies here:
112112
submake-schemapg:
@@ -135,6 +135,9 @@ postgres.o: $(OBJS)
135135
parser/gram.h: parser/gram.y
136136
$(MAKE) -C parser gram.h
137137

138+
storage/lmgr/lwlocknames.h: storage/lmgr/generate-lwlocknames.pl storage/lmgr/lwlocknames.txt
139+
$(MAKE) -C storage/lmgr lwlocknames.h
140+
138141
utils/fmgroids.h: utils/Gen_fmgrtab.pl catalog/Catalog.pm$(top_srcdir)/src/include/catalog/pg_proc.h
139142
$(MAKE) -C utils fmgroids.h
140143

@@ -165,6 +168,11 @@ $(top_builddir)/src/include/catalog/schemapg.h: catalog/schemapg.h
165168
cd'$(dir $@)'&& rm -f$(notdir$@)&&\
166169
$(LN_S)"$$prereqdir/$(notdir $<)".
167170

171+
$(top_builddir)/src/include/storage/lwlocknames.h: storage/lmgr/lwlocknames.h
172+
prereqdir=`cd'$(dir $<)'>/dev/null&& pwd`&&\
173+
cd'$(dir $@)'&& rm -f$(notdir$@)&&\
174+
$(LN_S)"$$prereqdir/$(notdir $<)".
175+
168176
$(top_builddir)/src/include/utils/errcodes.h: utils/errcodes.h
169177
prereqdir=`cd'$(dir $<)'>/dev/null&& pwd`&&\
170178
cd'$(dir $@)'&& rm -f$(notdir$@)&&\
@@ -192,6 +200,7 @@ distprep:
192200
$(MAKE) -C bootstrapbootparse.c bootscanner.c
193201
$(MAKE) -C catalogschemapg.h postgres.bki postgres.description postgres.shdescription
194202
$(MAKE) -C replicationrepl_gram.c repl_scanner.c
203+
$(MAKE) -C storagelwlocknames.h
195204
$(MAKE) -C utilsfmgrtab.c fmgroids.h errcodes.h
196205
$(MAKE) -C utils/miscguc-file.c
197206
$(MAKE) -C utils/sortqsort_tuple.c
@@ -282,6 +291,7 @@ clean:
282291
rm -f$(LOCALOBJS) postgres$(X)$(POSTGRES_IMP)\
283292
$(top_builddir)/src/include/parser/gram.h\
284293
$(top_builddir)/src/include/catalog/schemapg.h\
294+
$(top_builddir)/src/include/storage/lwlocknames.h\
285295
$(top_builddir)/src/include/utils/fmgroids.h\
286296
$(top_builddir)/src/include/utils/probes.h
287297
ifeq ($(PORTNAME), cygwin)
@@ -307,6 +317,8 @@ maintainer-clean: distclean
307317
catalog/postgres.shdescription\
308318
replication/repl_gram.c\
309319
replication/repl_scanner.c\
320+
storage/lmgr/lwlocknames.c\
321+
storage/lmgr/lwlocknames.h\
310322
utils/fmgroids.h\
311323
utils/fmgrtab.c\
312324
utils/errcodes.h\

‎src/backend/storage/lmgr/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/lwlocknames.c
2+
/lwlocknames.h

‎src/backend/storage/lmgr/Makefile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,17 @@ s_lock_test: s_lock.c $(top_builddir)/src/port/libpgport.a
2424
$(CC)$(CPPFLAGS)$(CFLAGS) -DS_LOCK_TEST=1$(srcdir)/s_lock.c\
2525
$(TASPATH) -L$(top_builddir)/src/port -lpgport -o s_lock_test
2626

27+
# see explanation in ../../parser/Makefile
28+
lwlocknames.c: lwlocknames.h ;
29+
30+
lwlocknames.h:$(top_srcdir)/src/backend/storage/lmgr/lwlocknames.txt generate-lwlocknames.pl
31+
$(PERL)$(srcdir)/generate-lwlocknames.pl$<
32+
2733
check: s_lock_test
2834
./s_lock_test
2935

30-
cleandistcleanmaintainer-clean:
36+
cleandistclean:
3137
rm -f s_lock_test
38+
39+
maintainer-clean: clean
40+
rm -f lwlocknames.h lwlocknames.c
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/perl
2+
#
3+
# Generate lwlocknames.h and lwlocknames.c from lwlocknames.txt
4+
# Copyright (c) 2000-2015, PostgreSQL Global Development Group
5+
6+
use warnings;
7+
use strict;
8+
9+
my$lastlockidx = -1;
10+
my$continue ="\n";
11+
12+
openmy$lwlocknames,$ARGV[0]ordie;
13+
14+
# Include PID in suffix in case parallel make runs this multiple times.
15+
my$htmp ="lwlocknames.h.tmp$$";
16+
my$ctmp ="lwlocknames.c.tmp$$";
17+
open H,'>',$htmpordie"Could not open$htmp:$!";
18+
open C,'>',$ctmpordie"Could not open$ctmp:$!";
19+
20+
my$autogen =
21+
"/* autogenerated from src/backend/storage/lmgr/lwlocknames.txt, do not edit */\n";
22+
print H$autogen;
23+
print H"/* there is deliberately not an #ifndef LWLOCKNAMES_H here */\n\n";
24+
print C$autogen,"\n";
25+
26+
print C"static char *MainLWLockNames[] = {";
27+
28+
while (<$lwlocknames>)
29+
{
30+
chomp;
31+
32+
# Skip comments
33+
nextif/^#/;
34+
nextif/^\s*$/;
35+
36+
die"unable to parse lwlocknames.txt"
37+
unless/^(\w+)\s+(\d+)$/;
38+
39+
(my$lockname,my$lockidx) = ($1,$2);
40+
41+
die"lwlocknames.txt not in order"if$lockidx <$lastlockidx;
42+
die"lwlocknames.txt has duplicates"if$lockidx ==$lastlockidx;
43+
44+
while ($lastlockidx <$lockidx - 1)
45+
{
46+
++$lastlockidx;
47+
printf C"%s\"<unassigned:%d>\"",$continue,$lastlockidx;
48+
$continue =",\n";
49+
}
50+
printf C"%s\"%s\"",$continue,$lockname;
51+
$lastlockidx =$lockidx;
52+
$continue =",\n";
53+
54+
print H"#define$lockname (&MainLWLockArray[$lockidx].lock)\n";
55+
}
56+
57+
printf C"\n};\n";
58+
print H"\n";
59+
printf H"#define NUM_INDIVIDUAL_LWLOCKS%s\n",$lastlockidx + 1;
60+
61+
close H;
62+
close C;
63+
64+
rename($htmp,'lwlocknames.h') ||die"rename:$htmp:$!";
65+
rename($ctmp,'lwlocknames.c') ||die"rename:$ctmp:$!";
66+
67+
close$lwlocknames;

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

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@
9595
#include"utils/hsearch.h"
9696
#endif
9797

98+
/* Constants for lwlock names */
99+
#include"lwlocknames.c"
100+
98101

99102
/* We use the ShmemLock spinlock to protect LWLockAssign */
100103
externslock_t*ShmemLock;
@@ -183,18 +186,32 @@ PRINT_LWDEBUG(const char *where, LWLock *lock, LWLockMode mode)
183186
if (Trace_lwlocks)
184187
{
185188
uint32state=pg_atomic_read_u32(&lock->state);
186-
187-
ereport(LOG,
188-
(errhidestmt(true),
189-
errhidecontext(true),
190-
errmsg("%d: %s(%s %d): excl %u shared %u haswaiters %u waiters %u rOK %d",
191-
MyProcPid,
192-
where,T_NAME(lock),T_ID(lock),
193-
!!(state&LW_VAL_EXCLUSIVE),
194-
state&LW_SHARED_MASK,
195-
!!(state&LW_FLAG_HAS_WAITERS),
196-
pg_atomic_read_u32(&lock->nwaiters),
197-
!!(state&LW_FLAG_RELEASE_OK))));
189+
intid=T_ID(lock);
190+
191+
if (lock->tranche==0&&id<NUM_INDIVIDUAL_LWLOCKS)
192+
ereport(LOG,
193+
(errhidestmt(true),
194+
errhidecontext(true),
195+
errmsg("%d: %s(%s): excl %u shared %u haswaiters %u waiters %u rOK %d",
196+
MyProcPid,
197+
where,MainLWLockNames[id],
198+
!!(state&LW_VAL_EXCLUSIVE),
199+
state&LW_SHARED_MASK,
200+
!!(state&LW_FLAG_HAS_WAITERS),
201+
pg_atomic_read_u32(&lock->nwaiters),
202+
!!(state&LW_FLAG_RELEASE_OK))));
203+
else
204+
ereport(LOG,
205+
(errhidestmt(true),
206+
errhidecontext(true),
207+
errmsg("%d: %s(%s %d): excl %u shared %u haswaiters %u waiters %u rOK %d",
208+
MyProcPid,
209+
where,T_NAME(lock),id,
210+
!!(state&LW_VAL_EXCLUSIVE),
211+
state&LW_SHARED_MASK,
212+
!!(state&LW_FLAG_HAS_WAITERS),
213+
pg_atomic_read_u32(&lock->nwaiters),
214+
!!(state&LW_FLAG_RELEASE_OK))));
198215
}
199216
}
200217

@@ -204,11 +221,20 @@ LOG_LWDEBUG(const char *where, LWLock *lock, const char *msg)
204221
/* hide statement & context here, otherwise the log is just too verbose */
205222
if (Trace_lwlocks)
206223
{
207-
ereport(LOG,
208-
(errhidestmt(true),
209-
errhidecontext(true),
210-
errmsg("%s(%s %d): %s",where,
211-
T_NAME(lock),T_ID(lock),msg)));
224+
intid=T_ID(lock);
225+
226+
if (lock->tranche==0&&id<NUM_INDIVIDUAL_LWLOCKS)
227+
ereport(LOG,
228+
(errhidestmt(true),
229+
errhidecontext(true),
230+
errmsg("%s(%s): %s",where,
231+
MainLWLockNames[id],msg)));
232+
else
233+
ereport(LOG,
234+
(errhidestmt(true),
235+
errhidecontext(true),
236+
errmsg("%s(%s %d): %s",where,
237+
T_NAME(lock),id,msg)));
212238
}
213239
}
214240

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Some commonly-used locks have predefined positions within MainLWLockArray;
2+
# these are defined here. If you add a lock, add it to the end to avoid
3+
# renumbering the existing locks; if you remove a lock, consider leaving a gap
4+
# in the numbering sequence for the benefit of DTrace and other external
5+
# debugging scripts.
6+
7+
# 0 is available; was formerly BufFreelistLock
8+
ShmemIndexLock1
9+
OidGenLock2
10+
XidGenLock3
11+
ProcArrayLock4
12+
SInvalReadLock5
13+
SInvalWriteLock6
14+
WALBufMappingLock7
15+
WALWriteLock8
16+
ControlFileLock9
17+
CheckpointLock10
18+
CLogControlLock11
19+
SubtransControlLock12
20+
MultiXactGenLock13
21+
MultiXactOffsetControlLock14
22+
MultiXactMemberControlLock15
23+
RelCacheInitLock16
24+
CheckpointerCommLock17
25+
TwoPhaseStateLock18
26+
TablespaceCreateLock19
27+
BtreeVacuumLock20
28+
AddinShmemInitLock21
29+
AutovacuumLock22
30+
AutovacuumScheduleLock23
31+
SyncScanLock24
32+
RelationMappingLock25
33+
AsyncCtlLock26
34+
AsyncQueueLock27
35+
SerializableXactHashLock28
36+
SerializableFinishedListLock29
37+
SerializablePredicateLockListLock30
38+
OldSerXidLock31
39+
SyncRepLock32
40+
BackgroundWorkerLock33
41+
DynamicSharedMemoryControlLock34
42+
AutoFileLock35
43+
ReplicationSlotAllocationLock36
44+
ReplicationSlotControlLock37
45+
CommitTsControlLock38
46+
CommitTsLock39
47+
ReplicationOriginLock40

‎src/include/storage/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/lwlocknames.h

‎src/include/storage/lwlock.h

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -91,56 +91,8 @@ typedef union LWLockPadded
9191
}LWLockPadded;
9292
externPGDLLIMPORTLWLockPadded*MainLWLockArray;
9393

94-
/*
95-
* Some commonly-used locks have predefined positions within MainLWLockArray;
96-
* defining macros here makes it much easier to keep track of these. If you
97-
* add a lock, add it to the end to avoid renumbering the existing locks;
98-
* if you remove a lock, consider leaving a gap in the numbering sequence for
99-
* the benefit of DTrace and other external debugging scripts.
100-
*/
101-
/* 0 is available; was formerly BufFreelistLock */
102-
#defineShmemIndexLock(&MainLWLockArray[1].lock)
103-
#defineOidGenLock(&MainLWLockArray[2].lock)
104-
#defineXidGenLock(&MainLWLockArray[3].lock)
105-
#defineProcArrayLock(&MainLWLockArray[4].lock)
106-
#defineSInvalReadLock(&MainLWLockArray[5].lock)
107-
#defineSInvalWriteLock(&MainLWLockArray[6].lock)
108-
#defineWALBufMappingLock(&MainLWLockArray[7].lock)
109-
#defineWALWriteLock(&MainLWLockArray[8].lock)
110-
#defineControlFileLock(&MainLWLockArray[9].lock)
111-
#defineCheckpointLock(&MainLWLockArray[10].lock)
112-
#defineCLogControlLock(&MainLWLockArray[11].lock)
113-
#defineSubtransControlLock(&MainLWLockArray[12].lock)
114-
#defineMultiXactGenLock(&MainLWLockArray[13].lock)
115-
#defineMultiXactOffsetControlLock(&MainLWLockArray[14].lock)
116-
#defineMultiXactMemberControlLock(&MainLWLockArray[15].lock)
117-
#defineRelCacheInitLock(&MainLWLockArray[16].lock)
118-
#defineCheckpointerCommLock(&MainLWLockArray[17].lock)
119-
#defineTwoPhaseStateLock(&MainLWLockArray[18].lock)
120-
#defineTablespaceCreateLock(&MainLWLockArray[19].lock)
121-
#defineBtreeVacuumLock(&MainLWLockArray[20].lock)
122-
#defineAddinShmemInitLock(&MainLWLockArray[21].lock)
123-
#defineAutovacuumLock(&MainLWLockArray[22].lock)
124-
#defineAutovacuumScheduleLock(&MainLWLockArray[23].lock)
125-
#defineSyncScanLock(&MainLWLockArray[24].lock)
126-
#defineRelationMappingLock(&MainLWLockArray[25].lock)
127-
#defineAsyncCtlLock(&MainLWLockArray[26].lock)
128-
#defineAsyncQueueLock(&MainLWLockArray[27].lock)
129-
#defineSerializableXactHashLock(&MainLWLockArray[28].lock)
130-
#defineSerializableFinishedListLock(&MainLWLockArray[29].lock)
131-
#defineSerializablePredicateLockListLock(&MainLWLockArray[30].lock)
132-
#defineOldSerXidLock(&MainLWLockArray[31].lock)
133-
#defineSyncRepLock(&MainLWLockArray[32].lock)
134-
#defineBackgroundWorkerLock(&MainLWLockArray[33].lock)
135-
#defineDynamicSharedMemoryControlLock(&MainLWLockArray[34].lock)
136-
#defineAutoFileLock(&MainLWLockArray[35].lock)
137-
#defineReplicationSlotAllocationLock(&MainLWLockArray[36].lock)
138-
#defineReplicationSlotControlLock(&MainLWLockArray[37].lock)
139-
#defineCommitTsControlLock(&MainLWLockArray[38].lock)
140-
#defineCommitTsLock(&MainLWLockArray[39].lock)
141-
#defineReplicationOriginLock(&MainLWLockArray[40].lock)
142-
143-
#defineNUM_INDIVIDUAL_LWLOCKS41
94+
/* Names for fixed lwlocks */
95+
#include"lwlocknames.h"
14496

14597
/*
14698
* It's a bit odd to declare NUM_BUFFER_PARTITIONS and NUM_LOCK_PARTITIONS

‎src/tools/msvc/Solution.pm

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,22 @@ s{PG_VERSION_STR "[^"]+"}{__STRINGIFY(x) #x\n#define __STRINGIFY2(z) __STRINGIFY
285285
'src/include/utils/fmgroids.h');
286286
}
287287

288+
if (IsNewer(
289+
'src/include/storage/lwlocknames.h','src/backend/storage/lmgr/lwlocknames.txt'))
290+
{
291+
print"Generating lwlocknames.c and lwlocknames.h...\n";
292+
chdir('src/backend/storage/lmgr');
293+
system('perl generate-lwlocknames.pl lwlocknames.txt');
294+
chdir('../../../..');
295+
}
296+
if (IsNewer(
297+
'src/include/storage/lwlocknames.h',
298+
'src/backend/storage/lmgr/lwlocknames.h'))
299+
{
300+
copyFile('src/backend/storage/lmgr/lwlocknames.h',
301+
'src/include/storage/lwlocknames.h');
302+
}
303+
288304
if (IsNewer('src/include/utils/probes.h','src/backend/utils/probes.d'))
289305
{
290306
print"Generating probes.h...\n";

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp