|
1 | | -#! /usr/bin/perl -w |
2 | 1 | #------------------------------------------------------------------------- |
| 2 | +# Perl script to create dummy probes.h file when dtrace is not available |
3 | 3 | # |
4 | | -# Gen_dummy_probes.pl |
5 | | -# Perl script that generates probes.h file when dtrace is not available |
6 | | -# |
7 | | -# Portions Copyright (c) 2008-2023, PostgreSQL Global Development Group |
8 | | -# |
9 | | -# |
10 | | -# IDENTIFICATION |
11 | | -# src/backend/utils/Gen_dummy_probes.pl |
12 | | -# |
13 | | -# This program was generated by running perl's s2p over Gen_dummy_probes.sed |
| 4 | +# Copyright (c) 2008-2023, PostgreSQL Global Development Group |
14 | 5 | # |
| 6 | +# src/backend/utils/Gen_dummy_probes.pl |
15 | 7 | #------------------------------------------------------------------------- |
16 | 8 |
|
17 | | -# turn off perlcritic for autogenerated code |
18 | | -## no critic |
19 | | - |
20 | | -$0 =~ s/^.*?(\w+)[\.\w+]*$/$1/; |
21 | | - |
22 | 9 | use strict; |
23 | | -use Symbol; |
24 | | -use vars qw{ $isEOF $Hold %wFiles @Q $CondReg |
25 | | - $doAutoPrint $doOpenWrite $doPrint }; |
26 | | -$doAutoPrint = 1; |
27 | | -$doOpenWrite = 1; |
28 | | - |
29 | | -# prototypes |
30 | | -sub openARGV(); |
31 | | -sub getsARGV(;\$); |
32 | | -sub eofARGV(); |
33 | | -sub printQ(); |
34 | | - |
35 | | -# Run: the sed loop reading input and applying the script |
36 | | -# |
37 | | -sub Run() |
38 | | -{ |
39 | | - my ($h, $icnt, $s, $n); |
40 | | - |
41 | | - # hack (not unbreakable :-/) to avoid // matching an empty string |
42 | | - my $z = "\000"; |
43 | | - $z =~ /$z/; |
44 | | - |
45 | | - # Initialize. |
46 | | - openARGV(); |
47 | | - $Hold = ''; |
48 | | - $CondReg = 0; |
49 | | - $doPrint = $doAutoPrint; |
50 | | - CYCLE: |
51 | | - while (getsARGV()) |
52 | | - { |
53 | | - chomp(); |
54 | | - $CondReg = 0; # cleared on t |
55 | | - BOS:; |
56 | | - |
57 | | - # /^[ ]*probe /!d |
58 | | - unless (m /^[ \t]*probe /s) |
59 | | - { |
60 | | - $doPrint = 0; |
61 | | - goto EOS; |
62 | | - } |
63 | | - |
64 | | - # s/^[ ]*probe \([^(]*\)\(.*\);/\1\2/ |
65 | | - { |
66 | | - $s = s /^[ \t]*probe ([^(]*)(.*);/${1}${2}/s; |
67 | | - $CondReg ||= $s; |
68 | | - } |
69 | | - |
70 | | - # s/__/_/g |
71 | | - { |
72 | | - $s = s /__/_/sg; |
73 | | - $CondReg ||= $s; |
74 | | - } |
75 | | - |
76 | | - # y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/ |
77 | | - { y{abcdefghijklmnopqrstuvwxyz}{ABCDEFGHIJKLMNOPQRSTUVWXYZ}; } |
78 | | - |
79 | | - # s/^/#define TRACE_POSTGRESQL_/ |
80 | | - { |
81 | | - $s = s /^/#define TRACE_POSTGRESQL_/s; |
82 | | - $CondReg ||= $s; |
83 | | - } |
84 | | - |
85 | | - # s/([^,)]\{1,\})/(INT1)/ |
86 | | - { |
87 | | - $s = s /\([^,)]+\)/(INT1)/s; |
88 | | - $CondReg ||= $s; |
89 | | - } |
90 | | - |
91 | | - # s/([^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2)/ |
92 | | - { |
93 | | - $s = s /\([^,)]+, [^,)]+\)/(INT1, INT2)/s; |
94 | | - $CondReg ||= $s; |
95 | | - } |
96 | | - |
97 | | - # s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3)/ |
98 | | - { |
99 | | - $s = s /\([^,)]+, [^,)]+, [^,)]+\)/(INT1, INT2, INT3)/s; |
100 | | - $CondReg ||= $s; |
101 | | - } |
102 | | - |
103 | | - # s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3, INT4)/ |
104 | | - { |
105 | | - $s = |
106 | | - s /\([^,)]+, [^,)]+, [^,)]+, [^,)]+\)/(INT1, INT2, INT3, INT4)/s; |
107 | | - $CondReg ||= $s; |
108 | | - } |
109 | | - |
110 | | - # s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3, INT4, INT5)/ |
111 | | - { |
112 | | - $s = |
113 | | - s /\([^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+\)/(INT1, INT2, INT3, INT4, INT5)/s; |
114 | | - $CondReg ||= $s; |
115 | | - } |
116 | | - |
117 | | - # s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3, INT4, INT5, INT6)/ |
118 | | - { |
119 | | - $s = |
120 | | - s /\([^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+\)/(INT1, INT2, INT3, INT4, INT5, INT6)/s; |
121 | | - $CondReg ||= $s; |
122 | | - } |
123 | | - |
124 | | - # s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3, INT4, INT5, INT6, INT7)/ |
125 | | - { |
126 | | - $s = |
127 | | - s /\([^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+\)/(INT1, INT2, INT3, INT4, INT5, INT6, INT7)/s; |
128 | | - $CondReg ||= $s; |
129 | | - } |
130 | | - |
131 | | - # s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3, INT4, INT5, INT6, INT7, INT8)/ |
132 | | - { |
133 | | - $s = |
134 | | - s /\([^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+\)/(INT1, INT2, INT3, INT4, INT5, INT6, INT7, INT8)/s; |
135 | | - $CondReg ||= $s; |
136 | | - } |
137 | | - |
138 | | - # s/$/ do {} while (0)/ |
139 | | - { |
140 | | - $s = s /$/ do {} while (0)/s; |
141 | | - $CondReg ||= $s; |
142 | | - } |
143 | | - |
144 | | - # P |
145 | | - { |
146 | | - if (/^(.*)/) { print $1, "\n"; } |
147 | | - } |
148 | | - |
149 | | - # s/(.*$/_ENABLED() (0)/ |
150 | | - { |
151 | | - $s = s /\(.*$/_ENABLED() (0)/s; |
152 | | - $CondReg ||= $s; |
153 | | - } |
154 | | - EOS: if ($doPrint) |
155 | | - { |
156 | | - print $_, "\n"; |
157 | | - } |
158 | | - else |
159 | | - { |
160 | | - $doPrint = $doAutoPrint; |
161 | | - } |
162 | | - printQ() if @Q; |
163 | | - } |
164 | | - |
165 | | - exit(0); |
166 | | -} |
167 | | -Run(); |
168 | | - |
169 | | -# openARGV: open 1st input file |
170 | | -# |
171 | | -sub openARGV() |
172 | | -{ |
173 | | - unshift(@ARGV, '-') unless @ARGV; |
174 | | - my $file = shift(@ARGV); |
175 | | - open(ARG, "<$file") |
176 | | - || die("$0: can't open $file for reading ($!)\n"); |
177 | | - $isEOF = 0; |
178 | | -} |
179 | | - |
180 | | -# getsARGV: Read another input line into argument (default: $_). |
181 | | -# Move on to next input file, and reset EOF flag $isEOF. |
182 | | -sub getsARGV(;\$) |
183 | | -{ |
184 | | - my $argref = @_ ? shift() : \$_; |
185 | | - while ($isEOF || !defined($$argref = <ARG>)) |
186 | | - { |
187 | | - close(ARG); |
188 | | - return 0 unless @ARGV; |
189 | | - my $file = shift(@ARGV); |
190 | | - open(ARG, "<$file") |
191 | | - || die("$0: can't open $file for reading ($!)\n"); |
192 | | - $isEOF = 0; |
193 | | - } |
194 | | - 1; |
195 | | -} |
196 | | - |
197 | | -# eofARGV: end-of-file test |
198 | | -# |
199 | | -sub eofARGV() |
200 | | -{ |
201 | | - return @ARGV == 0 && ($isEOF = eof(ARG)); |
202 | | -} |
203 | | - |
204 | | -# makeHandle: Generates another file handle for some file (given by its path) |
205 | | -# to be written due to a w command or an s command's w flag. |
206 | | -sub makeHandle($) |
207 | | -{ |
208 | | - my ($path) = @_; |
209 | | - my $handle; |
210 | | - if (!exists($wFiles{$path}) || $wFiles{$path} eq '') |
211 | | - { |
212 | | - $handle = $wFiles{$path} = gensym(); |
213 | | - if ($doOpenWrite) |
214 | | - { |
215 | | - if (!open($handle, ">$path")) |
216 | | - { |
217 | | - die("$0: can't open $path for writing: ($!)\n"); |
218 | | - } |
219 | | - } |
220 | | - } |
221 | | - else |
222 | | - { |
223 | | - $handle = $wFiles{$path}; |
224 | | - } |
225 | | - return $handle; |
226 | | -} |
227 | | - |
228 | | -# printQ: Print queued output which is either a string or a reference |
229 | | -# to a pathname. |
230 | | -sub printQ() |
231 | | -{ |
232 | | - for my $q (@Q) |
233 | | - { |
234 | | - if (ref($q)) |
235 | | - { |
236 | | - |
237 | | - # flush open w files so that reading this file gets it all |
238 | | - if (exists($wFiles{$$q}) && $wFiles{$$q} ne '') |
239 | | - { |
240 | | - open($wFiles{$$q}, ">>$$q"); |
241 | | - } |
242 | | - |
243 | | - # copy file to stdout: slow, but safe |
244 | | - if (open(RF, "<$$q")) |
245 | | - { |
246 | | - while (defined(my $line = <RF>)) |
247 | | - { |
248 | | - print $line; |
249 | | - } |
250 | | - close(RF); |
251 | | - } |
252 | | - } |
253 | | - else |
254 | | - { |
255 | | - print $q; |
256 | | - } |
257 | | - } |
258 | | - undef(@Q); |
259 | | -} |
| 10 | +use warnings; |
| 11 | + |
| 12 | +m/^\s*probe / || next; |
| 13 | +s/^\s*probe ([^(]*)(.*);/$1$2/; |
| 14 | +s/__/_/g; |
| 15 | +y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/; |
| 16 | +s/^/#define TRACE_POSTGRESQL_/; |
| 17 | +s/\([^,)]{1,}\)/(INT1)/; |
| 18 | +s/\([^,)]{1,}, [^,)]{1,}\)/(INT1, INT2)/; |
| 19 | +s/\([^,)]{1,}, [^,)]{1,}, [^,)]{1,}\)/(INT1, INT2, INT3)/; |
| 20 | +s/\([^,)]{1,}, [^,)]{1,}, [^,)]{1,}, [^,)]{1,}\)/(INT1, INT2, INT3, INT4)/; |
| 21 | +s/\([^,)]{1,}, [^,)]{1,}, [^,)]{1,}, [^,)]{1,}, [^,)]{1,}\)/(INT1, INT2, INT3, INT4, INT5)/; |
| 22 | +s/\([^,)]{1,}, [^,)]{1,}, [^,)]{1,}, [^,)]{1,}, [^,)]{1,}, [^,)]{1,}\)/(INT1, INT2, INT3, INT4, INT5, INT6)/; |
| 23 | +s/\([^,)]{1,}, [^,)]{1,}, [^,)]{1,}, [^,)]{1,}, [^,)]{1,}, [^,)]{1,}, [^,)]{1,}\)/(INT1, INT2, INT3, INT4, INT5, INT6, INT7)/; |
| 24 | +s/\([^,)]{1,}, [^,)]{1,}, [^,)]{1,}, [^,)]{1,}, [^,)]{1,}, [^,)]{1,}, [^,)]{1,}, [^,)]{1,}\)/(INT1, INT2, INT3, INT4, INT5, INT6, INT7, INT8)/; |
| 25 | +s/$/ do {} while (0)/; |
| 26 | +print; |
| 27 | +s/\(.*$/_ENABLED() (0)/; |
| 28 | +print; |
0 commit comments