@@ -123,16 +123,23 @@ function runValgrindPhpCgiCommand(
123
123
'-d opcache.validate_timestamps=0 ' ,
124
124
...$ args ,
125
125
]);
126
- $ instructions = extractInstructionsFromValgrindOutput ($ process ->stderr );
126
+ $ valgrindMetrics = extractMetricsFromValgrindOutput ($ process ->stderr );
127
+ $ instructions = $ valgrindMetrics ['Ir ' ];
127
128
if ($ repeat > 1 ) {
128
129
$ instructions = gmp_strval (gmp_div_q ($ instructions , $ repeat ));
129
130
}
130
131
return ['instructions ' => $ instructions ];
131
132
}
132
133
133
- function extractInstructionsFromValgrindOutput (string $ output ): string {
134
- preg_match ("(==[0-9]+== Events : Ir \n==[0-9]+== Collected : (?<instructions>[0-9]+)) " , $ output , $ matches );
135
- return $ matches ['instructions ' ] ?? throw new \Exception ('Unexpected valgrind output ' );
134
+ /**
135
+ * @return array<non-empty-string, numeric-string>
136
+ */
137
+ function extractMetricsFromValgrindOutput (string $ output ): array {
138
+ if (!preg_match ('/==\d+== Events *:((?: +\w+)+)\n==\d+== Collected :((?: +\d+)+)\n/ ' , $ output , $ matches )) {
139
+ throw new \Exception ('Unexpected valgrind output: ' . $ output );
140
+ }
141
+
142
+ return array_combine (explode ('' , ltrim ($ matches [1 ], '' )), explode ('' , ltrim ($ matches [2 ], '' )));
136
143
}
137
144
138
145
main ();
0 commit comments