|
4 | 4 | # Generate wait events support files from wait_event_names.txt: |
5 | 5 | # - wait_event_types.h (if --code is passed) |
6 | 6 | # - pgstat_wait_event.c (if --code is passed) |
| 7 | +# - wait_event_funcs_data.c (if --code is passed) |
7 | 8 | # - wait_event_types.sgml (if --docs is passed) |
8 | 9 | # |
9 | 10 | # Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group |
|
98 | 99 | # multiple times. |
99 | 100 | my $htmp = "$output_path/wait_event_types.h.tmp$$"; |
100 | 101 | my $ctmp = "$output_path/pgstat_wait_event.c.tmp$$"; |
| 102 | + my $wctmp = "$output_path/wait_event_funcs_data.c.tmp$$"; |
101 | 103 | open my $h, '>', $htmp or die "Could not open $htmp: $!"; |
102 | 104 | open my $c, '>', $ctmp or die "Could not open $ctmp: $!"; |
| 105 | + open my $wc, '>', $wctmp or die "Could not open $wctmp: $!"; |
103 | 106 |
|
104 | 107 | my $header_comment = |
105 | 108 | '/*------------------------------------------------------------------------- |
|
129 | 132 |
|
130 | 133 | printf $c $header_comment, 'pgstat_wait_event.c'; |
131 | 134 |
|
| 135 | + printf $wc $header_comment, 'wait_event_funcs_data.c'; |
| 136 | + |
| 137 | + # Generate the pgstat_wait_event.c and wait_event_types.h files |
132 | 138 | # uc() is being used to force the comparison to be case-insensitive. |
133 | 139 | foreach my $waitclass (sort { uc($a) cmp uc($b) } keys %hashwe) |
134 | 140 | { |
135 | | - |
136 | | - # Don't generate .c and .h files for Extension, LWLock and |
137 | | - # Lock, these are handled independently. |
| 141 | + # Don't generate the pgstat_wait_event.c and wait_event_types.h files |
| 142 | + # for Extension, LWLock and Lock, these are handled independently. |
138 | 143 | next |
139 | 144 | if ( $waitclass eq 'WaitEventExtension' |
140 | 145 | || $waitclass eq 'WaitEventLWLock' |
|
183 | 188 | printf $c "}\n\n"; |
184 | 189 | } |
185 | 190 |
|
| 191 | + # Generate wait_event_funcs_data.c, building the contents of a static |
| 192 | + # C structure holding all the information about the wait events. |
| 193 | + # uc() is being used to force the comparison to be case-insensitive, |
| 194 | + # even though it is not required here. |
| 195 | + foreach my $waitclass (sort { uc($a) cmp uc($b) } keys %hashwe) |
| 196 | + { |
| 197 | + my $last = $waitclass; |
| 198 | + $last =~ s/^WaitEvent//; |
| 199 | + |
| 200 | + foreach my $wev (@{ $hashwe{$waitclass} }) |
| 201 | + { |
| 202 | + my $new_desc = substr $wev->[2], 1, -2; |
| 203 | + # Escape single quotes. |
| 204 | + $new_desc =~ s/'/\\'/g; |
| 205 | + |
| 206 | + # Replace the "quote" markups by real ones. |
| 207 | + $new_desc =~ s/<quote>(.*?)<\/quote>/\\"$1\\"/g; |
| 208 | + |
| 209 | + # Remove SGML markups. |
| 210 | + $new_desc =~ s/<.*?>(.*?)<.*?>/$1/g; |
| 211 | + |
| 212 | + # Tweak contents about links <xref linkend="text"/> |
| 213 | + # on GUCs, |
| 214 | + while (my ($capture) = |
| 215 | + $new_desc =~ m/<xref linkend="guc-(.*?)"\/>/g) |
| 216 | + { |
| 217 | + $capture =~ s/-/_/g; |
| 218 | + $new_desc =~ s/<xref linkend="guc-.*?"\/>/$capture/g; |
| 219 | + } |
| 220 | + # Then remove any reference to |
| 221 | + # "see <xref linkend="text"/>". |
| 222 | + $new_desc =~ s/; see.*$//; |
| 223 | + |
| 224 | + # Build one element of the C structure holding the |
| 225 | + # wait event info, as of (type, name, description). |
| 226 | + printf $wc "\t{\"%s\", \"%s\", \"%s\"},\n", $last, $wev->[1], |
| 227 | + $new_desc; |
| 228 | + } |
| 229 | + } |
| 230 | + |
186 | 231 | printf $h "#endif /* WAIT_EVENT_TYPES_H */\n"; |
187 | 232 | close $h; |
188 | 233 | close $c; |
| 234 | + close $wc; |
189 | 235 |
|
190 | 236 | rename($htmp, "$output_path/wait_event_types.h") |
191 | 237 | || die "rename: $htmp to $output_path/wait_event_types.h: $!"; |
192 | 238 | rename($ctmp, "$output_path/pgstat_wait_event.c") |
193 | 239 | || die "rename: $ctmp to $output_path/pgstat_wait_event.c: $!"; |
| 240 | + rename($wctmp, "$output_path/wait_event_funcs_data.c") |
| 241 | + || die "rename: $wctmp to $output_path/wait_event_funcs_data.c: $!"; |
194 | 242 | } |
195 | 243 | # Generate the .sgml file. |
196 | 244 | elsif ($gen_docs) |
@@ -249,7 +297,7 @@ sub usage |
249 | 297 |
|
250 | 298 | Options: |
251 | 299 | --outdir Output directory (default '.') |
252 | | - --code Generate wait_event_types.h and pgstat_wait_event.c. |
| 300 | + --code Generate C and header files. |
253 | 301 | --sgml Generate wait_event_types.sgml. |
254 | 302 |
|
255 | 303 | generate-wait_event_types.pl generates the SGML documentation and code |
|
0 commit comments