2 #-------------------------------------------------------------------------
5 # Perl script that generates probes.h file when dtrace is not available
7 # Portions Copyright (c) 2008-2019, PostgreSQL Global Development Group
11 # src/backend/utils/Gen_dummy_probes.pl
13 # This program was generated by running perl's s2p over Gen_dummy_probes.sed
15 #-------------------------------------------------------------------------
17 # turn off perlcritic for autogened code
20 $0 =~ s/^.*?(\w+)[\.\w+]*$/$1/;
24 use vars qw{ $isEOF $Hold %wFiles @Q $CondReg
25 $doAutoPrint $doOpenWrite $doPrint };
35 # Run: the sed loop reading input and applying the script
39 my ($h, $icnt, $s, $n);
41 # hack (not unbreakable :-/) to avoid // matching an empty string
49 $doPrint = $doAutoPrint;
54 $CondReg = 0; # cleared on t
58 unless (m /^[ \t]*probe /s)
64 # s/^[ ]*probe \([^(]*\)\(.*\);/\1\2/
66 $s = s /^[ \t]*probe ([^(]*)(.*);/${1}${2}/s;
76 # y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/
77 { y{abcdefghijklmnopqrstuvwxyz}{ABCDEFGHIJKLMNOPQRSTUVWXYZ}; }
79 # s/^/#define TRACE_POSTGRESQL_/
81 $s = s /^/#define TRACE_POSTGRESQL_/s;
85 # s/([^,)]\{1,\})/(INT1)/
87 $s = s /\([^,)]+\)/(INT1)/s;
91 # s/([^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2)/
93 $s = s /\([^,)]+, [^,)]+\)/(INT1, INT2)/s;
97 # s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3)/
99 $s = s /\([^,)]+, [^,)]+, [^,)]+\)/(INT1, INT2, INT3)/s;
103 # s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3, INT4)/
106 s /\([^,)]+, [^,)]+, [^,)]+, [^,)]+\)/(INT1, INT2, INT3, INT4)/s;
110 # s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3, INT4, INT5)/
113 s /\([^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+\)/(INT1, INT2, INT3, INT4, INT5)/s;
117 # s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3, INT4, INT5, INT6)/
120 s /\([^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+\)/(INT1, INT2, INT3, INT4, INT5, INT6)/s;
124 # s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3, INT4, INT5, INT6, INT7)/
127 s /\([^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+\)/(INT1, INT2, INT3, INT4, INT5, INT6, INT7)/s;
131 # s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3, INT4, INT5, INT6, INT7, INT8)/
134 s /\([^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+\)/(INT1, INT2, INT3, INT4, INT5, INT6, INT7, INT8)/s;
140 if (/^(.*)/) { print $1, "\n"; }
143 # s/(.*$/_ENABLED() (0)/
145 $s = s /\(.*$/_ENABLED() (0)/s;
154 $doPrint = $doAutoPrint;
163 # openARGV: open 1st input file
167 unshift(@ARGV, '-') unless @ARGV;
168 my $file = shift(@ARGV);
170 || die("$0: can't open $file for reading ($!)\n");
174 # getsARGV: Read another input line into argument (default: $_).
175 # Move on to next input file, and reset EOF flag $isEOF.
178 my $argref = @_ ? shift() : \$_;
179 while ($isEOF || !defined($$argref = <ARG>))
182 return 0 unless @ARGV;
183 my $file = shift(@ARGV);
185 || die("$0: can't open $file for reading ($!)\n");
191 # eofARGV: end-of-file test
195 return @ARGV == 0 && ($isEOF = eof(ARG));
198 # makeHandle: Generates another file handle for some file (given by its path)
199 # to be written due to a w command or an s command's w flag.
204 if (!exists($wFiles{$path}) || $wFiles{$path} eq '')
206 $handle = $wFiles{$path} = gensym();
209 if (!open($handle, ">$path"))
211 die("$0: can't open $path for writing: ($!)\n");
217 $handle = $wFiles{$path};
222 # printQ: Print queued output which is either a string or a reference
231 # flush open w files so that reading this file gets it all
232 if (exists($wFiles{$$q}) && $wFiles{$$q} ne '')
234 open($wFiles{$$q}, ">>$$q");
237 # copy file to stdout: slow, but safe
238 if (open(RF, "<$$q"))
240 while (defined(my $line = <RF>))