1 | #include <stdio.h> |
---|
2 | #include "xcache.h" |
---|
3 | #include "ext/standard/flock_compat.h" |
---|
4 | #ifdef HAVE_SYS_FILE_H |
---|
5 | # include <sys/file.h> |
---|
6 | #endif |
---|
7 | #include <sys/types.h> |
---|
8 | #include <sys/stat.h> |
---|
9 | #include <fcntl.h> |
---|
10 | |
---|
11 | #include "stack.h" |
---|
12 | #include "xcache_globals.h" |
---|
13 | #include "coverager.h" |
---|
14 | #include "utils.h" |
---|
15 | typedef HashTable *coverager_t; |
---|
16 | #define PCOV_HEADER_MAGIC 0x564f4350 |
---|
17 | |
---|
18 | static char *xc_coveragedump_dir = NULL; |
---|
19 | static zend_compile_file_t *old_compile_file = NULL; |
---|
20 | |
---|
21 | #if 0 |
---|
22 | #define DEBUG |
---|
23 | #endif |
---|
24 | |
---|
25 | /* dumper */ |
---|
26 | static void xc_destroy_coverage(void *pDest) /* {{{ */ |
---|
27 | { |
---|
28 | coverager_t cov = *(coverager_t*) pDest; |
---|
29 | TRACE("destroy %p", cov); |
---|
30 | zend_hash_destroy(cov); |
---|
31 | efree(cov); |
---|
32 | } |
---|
33 | /* }}} */ |
---|
34 | void xcache_mkdirs_ex(char *root, int rootlen, char *path, int pathlen TSRMLS_DC) /* {{{ */ |
---|
35 | { |
---|
36 | char *fullpath; |
---|
37 | struct stat st; |
---|
38 | |
---|
39 | TRACE("mkdirs %s %d %s %d", root, rootlen, path, pathlen); |
---|
40 | fullpath = do_alloca(rootlen + pathlen + 1); |
---|
41 | memcpy(fullpath, root, rootlen); |
---|
42 | memcpy(fullpath + rootlen, path, pathlen); |
---|
43 | fullpath[rootlen + pathlen] = '\0'; |
---|
44 | |
---|
45 | if (stat(fullpath, &st) != 0) { |
---|
46 | char *chr; |
---|
47 | |
---|
48 | chr = strrchr(path, PHP_DIR_SEPARATOR); |
---|
49 | if (chr && chr != path) { |
---|
50 | *chr = '\0'; |
---|
51 | xcache_mkdirs_ex(root, rootlen, path, chr - path TSRMLS_CC); |
---|
52 | *chr = PHP_DIR_SEPARATOR; |
---|
53 | } |
---|
54 | TRACE("mkdir %s", fullpath); |
---|
55 | #if PHP_MAJOR_VERSION > 5 |
---|
56 | php_stream_mkdir(fullpath, 0700, REPORT_ERRORS, NULL); |
---|
57 | #else |
---|
58 | mkdir(fullpath, 0700); |
---|
59 | #endif |
---|
60 | } |
---|
61 | free_alloca(fullpath); |
---|
62 | } |
---|
63 | /* }}} */ |
---|
64 | static void xc_coverager_save_cov(char *srcfile, char *outfilename, coverager_t cov TSRMLS_DC) /* {{{ */ |
---|
65 | { |
---|
66 | long *buf = NULL, *p; |
---|
67 | long covlines, *phits; |
---|
68 | int fd = -1; |
---|
69 | int size; |
---|
70 | int newfile; |
---|
71 | struct stat srcstat, outstat; |
---|
72 | HashPosition pos; |
---|
73 | char *contents = NULL; |
---|
74 | long len; |
---|
75 | |
---|
76 | if (stat(srcfile, &srcstat) != 0) { |
---|
77 | return; |
---|
78 | } |
---|
79 | |
---|
80 | newfile = 0; |
---|
81 | if (stat(outfilename, &outstat) != 0) { |
---|
82 | newfile = 1; |
---|
83 | } |
---|
84 | else { |
---|
85 | if (srcstat.st_mtime > outstat.st_mtime) { |
---|
86 | newfile = 1; |
---|
87 | } |
---|
88 | } |
---|
89 | |
---|
90 | fd = open(outfilename, O_RDWR | O_CREAT, 0600); |
---|
91 | if (fd < 0) { |
---|
92 | char *chr; |
---|
93 | chr = strrchr(srcfile, PHP_DIR_SEPARATOR); |
---|
94 | if (chr) { |
---|
95 | *chr = '\0'; |
---|
96 | xcache_mkdirs_ex(xc_coveragedump_dir, strlen(xc_coveragedump_dir), srcfile, chr - srcfile TSRMLS_CC); |
---|
97 | *chr = PHP_DIR_SEPARATOR; |
---|
98 | } |
---|
99 | fd = open(outfilename, O_RDWR | O_CREAT, 0600); |
---|
100 | if (fd < 0) { |
---|
101 | goto bailout; |
---|
102 | } |
---|
103 | } |
---|
104 | if (flock(fd, LOCK_EX) != SUCCESS) { |
---|
105 | goto bailout; |
---|
106 | } |
---|
107 | |
---|
108 | if (newfile) { |
---|
109 | TRACE("%s", "new file"); |
---|
110 | } |
---|
111 | else if (outstat.st_size) { |
---|
112 | len = outstat.st_size; |
---|
113 | contents = emalloc(len); |
---|
114 | if (read(fd, (void *) contents, len) != len) { |
---|
115 | goto bailout; |
---|
116 | } |
---|
117 | TRACE("oldsize %d", (int) len); |
---|
118 | do { |
---|
119 | p = (long *) contents; |
---|
120 | len -= sizeof(long); |
---|
121 | if (len < 0) { |
---|
122 | break; |
---|
123 | } |
---|
124 | if (*p++ != PCOV_HEADER_MAGIC) { |
---|
125 | TRACE("wrong magic in file %s", outfilename); |
---|
126 | break; |
---|
127 | } |
---|
128 | |
---|
129 | p += 2; /* skip covliens */ |
---|
130 | len -= sizeof(long) * 2; |
---|
131 | if (len < 0) { |
---|
132 | break; |
---|
133 | } |
---|
134 | |
---|
135 | for (; len >= sizeof(long) * 2; len -= sizeof(long) * 2, p += 2) { |
---|
136 | if (zend_hash_index_find(cov, p[0], (void**)&phits) == SUCCESS) { |
---|
137 | if (p[1] == -1) { |
---|
138 | /* OPTIMIZE: already marked */ |
---|
139 | continue; |
---|
140 | } |
---|
141 | if (*phits != -1) { |
---|
142 | p[1] += *phits; |
---|
143 | } |
---|
144 | } |
---|
145 | zend_hash_index_update(cov, p[0], &p[1], sizeof(p[1]), NULL); |
---|
146 | } |
---|
147 | } while (0); |
---|
148 | efree(contents); |
---|
149 | contents = NULL; |
---|
150 | } |
---|
151 | |
---|
152 | |
---|
153 | /* serialize */ |
---|
154 | size = (zend_hash_num_elements(cov) + 1) * sizeof(long) * 2 + sizeof(long); |
---|
155 | p = buf = emalloc(size); |
---|
156 | *p++ = PCOV_HEADER_MAGIC; |
---|
157 | p += 2; /* for covlines */ |
---|
158 | covlines = 0; |
---|
159 | |
---|
160 | zend_hash_internal_pointer_reset_ex(cov, &pos); |
---|
161 | while (zend_hash_get_current_data_ex(cov, (void**)&phits, &pos) == SUCCESS) { |
---|
162 | *p++ = pos->h; |
---|
163 | *p++ = *phits; |
---|
164 | if (*phits > 0) { |
---|
165 | covlines ++; |
---|
166 | } |
---|
167 | zend_hash_move_forward_ex(cov, &pos); |
---|
168 | } |
---|
169 | p = buf + 1; |
---|
170 | p[0] = 0; |
---|
171 | p[1] = covlines; |
---|
172 | |
---|
173 | ftruncate(fd, 0); |
---|
174 | lseek(fd, 0, SEEK_SET); |
---|
175 | write(fd, (char *) buf, size); |
---|
176 | |
---|
177 | bailout: |
---|
178 | if (contents) efree(contents); |
---|
179 | if (fd >= 0) close(fd); |
---|
180 | if (buf) efree(buf); |
---|
181 | } |
---|
182 | /* }}} */ |
---|
183 | |
---|
184 | static void xc_coverager_initenv(TSRMLS_D) /* {{{ */ |
---|
185 | { |
---|
186 | if (!XG(coverages)) { |
---|
187 | XG(coverages) = emalloc(sizeof(HashTable)); |
---|
188 | zend_hash_init(XG(coverages), 0, NULL, xc_destroy_coverage, 0); |
---|
189 | } |
---|
190 | } |
---|
191 | /* }}} */ |
---|
192 | static void xc_coverager_clean(TSRMLS_D) /* {{{ */ |
---|
193 | { |
---|
194 | if (XG(coverages)) { |
---|
195 | HashPosition pos; |
---|
196 | coverager_t *pcov; |
---|
197 | |
---|
198 | zend_hash_internal_pointer_reset_ex(XG(coverages), &pos); |
---|
199 | while (zend_hash_get_current_data_ex(XG(coverages), (void **) &pcov, &pos) == SUCCESS) { |
---|
200 | long *phits; |
---|
201 | coverager_t cov; |
---|
202 | HashPosition pos2; |
---|
203 | |
---|
204 | cov = *pcov; |
---|
205 | |
---|
206 | zend_hash_internal_pointer_reset_ex(cov, &pos2); |
---|
207 | while (zend_hash_get_current_data_ex(cov, (void**)&phits, &pos2) == SUCCESS) { |
---|
208 | long hits = *phits; |
---|
209 | |
---|
210 | if (hits != -1) { |
---|
211 | hits = -1; |
---|
212 | zend_hash_index_update(cov, pos2->h, &hits, sizeof(hits), NULL); |
---|
213 | } |
---|
214 | zend_hash_move_forward_ex(cov, &pos2); |
---|
215 | } |
---|
216 | |
---|
217 | zend_hash_move_forward_ex(XG(coverages), &pos); |
---|
218 | } |
---|
219 | } |
---|
220 | } |
---|
221 | /* }}} */ |
---|
222 | static void xc_coverager_cleanup(TSRMLS_D) /* {{{ */ |
---|
223 | { |
---|
224 | if (XG(coverages)) { |
---|
225 | zend_hash_destroy(XG(coverages)); |
---|
226 | efree(XG(coverages)); |
---|
227 | XG(coverages) = NULL; |
---|
228 | } |
---|
229 | } |
---|
230 | /* }}} */ |
---|
231 | |
---|
232 | static void xc_coverager_enable(TSRMLS_D) /* {{{ */ |
---|
233 | { |
---|
234 | XG(coverage_enabled) = 1; |
---|
235 | } |
---|
236 | /* }}} */ |
---|
237 | static void xc_coverager_disable(TSRMLS_D) /* {{{ */ |
---|
238 | { |
---|
239 | XG(coverage_enabled) = 0; |
---|
240 | } |
---|
241 | /* }}} */ |
---|
242 | |
---|
243 | void xc_coverager_request_init(TSRMLS_D) /* {{{ */ |
---|
244 | { |
---|
245 | if (XG(coverager)) { |
---|
246 | xc_coverager_enable(TSRMLS_C); |
---|
247 | CG(extended_info) = 1; |
---|
248 | } |
---|
249 | else { |
---|
250 | XG(coverage_enabled) = 0; |
---|
251 | } |
---|
252 | } |
---|
253 | /* }}} */ |
---|
254 | static void xc_coverager_autodump(TSRMLS_D) /* {{{ */ |
---|
255 | { |
---|
256 | coverager_t *pcov; |
---|
257 | zstr s; |
---|
258 | char *outfilename; |
---|
259 | int dumpdir_len, outfilelen, alloc_len = 0; |
---|
260 | uint size; |
---|
261 | HashPosition pos; |
---|
262 | |
---|
263 | if (XG(coverages) && xc_coveragedump_dir) { |
---|
264 | dumpdir_len = strlen(xc_coveragedump_dir); |
---|
265 | alloc_len = dumpdir_len + 1 + 128; |
---|
266 | outfilename = emalloc(alloc_len); |
---|
267 | strcpy(outfilename, xc_coveragedump_dir); |
---|
268 | |
---|
269 | zend_hash_internal_pointer_reset_ex(XG(coverages), &pos); |
---|
270 | while (zend_hash_get_current_data_ex(XG(coverages), (void **) &pcov, &pos) == SUCCESS) { |
---|
271 | zend_hash_get_current_key_ex(XG(coverages), &s, &size, NULL, 0, &pos); |
---|
272 | outfilelen = dumpdir_len + size + 5; |
---|
273 | if (alloc_len < outfilelen) { |
---|
274 | alloc_len = outfilelen + 128; |
---|
275 | outfilename = erealloc(outfilename, alloc_len); |
---|
276 | } |
---|
277 | strcpy(outfilename + dumpdir_len, ZSTR_S(s)); |
---|
278 | strcpy(outfilename + dumpdir_len + size - 1, ".pcov"); |
---|
279 | |
---|
280 | TRACE("outfilename %s", outfilename); |
---|
281 | xc_coverager_save_cov(ZSTR_S(s), outfilename, *pcov TSRMLS_CC); |
---|
282 | zend_hash_move_forward_ex(XG(coverages), &pos); |
---|
283 | } |
---|
284 | efree(outfilename); |
---|
285 | } |
---|
286 | } |
---|
287 | /* }}} */ |
---|
288 | static void xc_coverager_dump(zval *return_value TSRMLS_DC) /* {{{ */ |
---|
289 | { |
---|
290 | coverager_t *pcov; |
---|
291 | HashPosition pos; |
---|
292 | |
---|
293 | if (XG(coverages)) { |
---|
294 | array_init(return_value); |
---|
295 | |
---|
296 | zend_hash_internal_pointer_reset_ex(XG(coverages), &pos); |
---|
297 | while (zend_hash_get_current_data_ex(XG(coverages), (void **) &pcov, &pos) == SUCCESS) { |
---|
298 | zval *lines; |
---|
299 | long *phits; |
---|
300 | coverager_t cov; |
---|
301 | HashPosition pos2; |
---|
302 | zstr filename; |
---|
303 | uint size; |
---|
304 | |
---|
305 | cov = *pcov; |
---|
306 | zend_hash_get_current_key_ex(XG(coverages), &filename, &size, NULL, 0, &pos); |
---|
307 | |
---|
308 | MAKE_STD_ZVAL(lines); |
---|
309 | array_init(lines); |
---|
310 | zend_hash_internal_pointer_reset_ex(cov, &pos2); |
---|
311 | while (zend_hash_get_current_data_ex(cov, (void**)&phits, &pos2) == SUCCESS) { |
---|
312 | long hits = *phits; |
---|
313 | add_index_long(lines, pos2->h, hits >= 0 ? hits : 0); |
---|
314 | zend_hash_move_forward_ex(cov, &pos2); |
---|
315 | } |
---|
316 | add_assoc_zval_ex(return_value, ZSTR_S(filename), strlen(ZSTR_S(filename)) + 1, lines); |
---|
317 | |
---|
318 | zend_hash_move_forward_ex(XG(coverages), &pos); |
---|
319 | } |
---|
320 | } |
---|
321 | else { |
---|
322 | RETVAL_NULL(); |
---|
323 | } |
---|
324 | } |
---|
325 | /* }}} */ |
---|
326 | void xc_coverager_request_shutdown(TSRMLS_D) /* {{{ */ |
---|
327 | { |
---|
328 | if (XG(coverager)) { |
---|
329 | xc_coverager_autodump(TSRMLS_C); |
---|
330 | xc_coverager_cleanup(TSRMLS_C); |
---|
331 | } |
---|
332 | } |
---|
333 | /* }}} */ |
---|
334 | |
---|
335 | /* helper func to store hits into coverages */ |
---|
336 | static coverager_t xc_coverager_get(char *filename TSRMLS_DC) /* {{{ */ |
---|
337 | { |
---|
338 | int len = strlen(filename) + 1; |
---|
339 | coverager_t cov, *pcov; |
---|
340 | |
---|
341 | if (zend_hash_find(XG(coverages), filename, len, (void **) &pcov) == SUCCESS) { |
---|
342 | TRACE("got coverage %s %p", filename, *pcov); |
---|
343 | return *pcov; |
---|
344 | } |
---|
345 | else { |
---|
346 | cov = emalloc(sizeof(HashTable)); |
---|
347 | zend_hash_init(cov, 0, NULL, NULL, 0); |
---|
348 | zend_hash_add(XG(coverages), filename, len, (void **) &cov, sizeof(cov), NULL); |
---|
349 | TRACE("new coverage %s %p", filename, cov); |
---|
350 | return cov; |
---|
351 | } |
---|
352 | } |
---|
353 | /* }}} */ |
---|
354 | static void xc_coverager_add_hits(HashTable *cov, long line, long hits TSRMLS_DC) /* {{{ */ |
---|
355 | { |
---|
356 | long *poldhits; |
---|
357 | |
---|
358 | if (line == 0) { |
---|
359 | return; |
---|
360 | } |
---|
361 | if (zend_hash_index_find(cov, line, (void**)&poldhits) == SUCCESS) { |
---|
362 | if (hits == -1) { |
---|
363 | /* OPTIMIZE: -1 == init-ing, but it's already initized */ |
---|
364 | return; |
---|
365 | } |
---|
366 | if (*poldhits != -1) { |
---|
367 | hits += *poldhits; |
---|
368 | } |
---|
369 | } |
---|
370 | zend_hash_index_update(cov, line, &hits, sizeof(hits), NULL); |
---|
371 | } |
---|
372 | /* }}} */ |
---|
373 | |
---|
374 | static int xc_coverager_get_op_array_size_no_tail(zend_op_array *op_array) /* {{{ */ |
---|
375 | { |
---|
376 | zend_uint size; |
---|
377 | |
---|
378 | size = op_array->size; |
---|
379 | do { |
---|
380 | next_op: |
---|
381 | if (size == 0) { |
---|
382 | break; |
---|
383 | } |
---|
384 | switch (op_array->opcodes[size - 1].opcode) { |
---|
385 | #ifdef ZEND_HANDLE_EXCEPTION |
---|
386 | case ZEND_HANDLE_EXCEPTION: |
---|
387 | #endif |
---|
388 | case ZEND_RETURN: |
---|
389 | case ZEND_EXT_STMT: |
---|
390 | size --; |
---|
391 | goto next_op; |
---|
392 | } |
---|
393 | } while (0); |
---|
394 | return size; |
---|
395 | } |
---|
396 | /* }}} */ |
---|
397 | |
---|
398 | /* prefill */ |
---|
399 | static int xc_coverager_init_op_array(zend_op_array *op_array TSRMLS_DC) /* {{{ */ |
---|
400 | { |
---|
401 | zend_uint size; |
---|
402 | coverager_t cov; |
---|
403 | zend_uint i; |
---|
404 | |
---|
405 | if (op_array->type != ZEND_USER_FUNCTION) { |
---|
406 | return 0; |
---|
407 | } |
---|
408 | |
---|
409 | size = xc_coverager_get_op_array_size_no_tail(op_array); |
---|
410 | cov = xc_coverager_get(op_array->filename TSRMLS_CC); |
---|
411 | for (i = 0; i < size; i ++) { |
---|
412 | switch (op_array->opcodes[i].opcode) { |
---|
413 | case ZEND_EXT_STMT: |
---|
414 | #if 0 |
---|
415 | case ZEND_EXT_FCALL_BEGIN: |
---|
416 | case ZEND_EXT_FCALL_END: |
---|
417 | #endif |
---|
418 | xc_coverager_add_hits(cov, op_array->opcodes[i].lineno, -1 TSRMLS_CC); |
---|
419 | break; |
---|
420 | } |
---|
421 | } |
---|
422 | return 0; |
---|
423 | } |
---|
424 | /* }}} */ |
---|
425 | static void xc_coverager_init_compile_result(zend_op_array *op_array TSRMLS_DC) /* {{{ */ |
---|
426 | { |
---|
427 | xc_compile_result_t cr; |
---|
428 | |
---|
429 | xc_compile_result_init_cur(&cr, op_array TSRMLS_CC); |
---|
430 | xc_apply_op_array(&cr, (apply_func_t) xc_coverager_init_op_array TSRMLS_CC); |
---|
431 | xc_compile_result_free(&cr); |
---|
432 | } |
---|
433 | /* }}} */ |
---|
434 | static zend_op_array *xc_compile_file_for_coverage(zend_file_handle *h, int type TSRMLS_DC) /* {{{ */ |
---|
435 | { |
---|
436 | zend_op_array *op_array; |
---|
437 | |
---|
438 | op_array = old_compile_file(h, type TSRMLS_CC); |
---|
439 | if (op_array) { |
---|
440 | if (XG(coverager)) { |
---|
441 | xc_coverager_initenv(TSRMLS_C); |
---|
442 | xc_coverager_init_compile_result(op_array TSRMLS_CC); |
---|
443 | } |
---|
444 | } |
---|
445 | return op_array; |
---|
446 | } |
---|
447 | /* }}} */ |
---|
448 | |
---|
449 | /* hits */ |
---|
450 | void xc_coverager_handle_ext_stmt(zend_op_array *op_array, zend_uchar op) /* {{{ */ |
---|
451 | { |
---|
452 | TSRMLS_FETCH(); |
---|
453 | |
---|
454 | if (XG(coverages) && XG(coverage_enabled)) { |
---|
455 | int size = xc_coverager_get_op_array_size_no_tail(op_array); |
---|
456 | int oplineno = (*EG(opline_ptr)) - op_array->opcodes; |
---|
457 | if (oplineno < size) { |
---|
458 | xc_coverager_add_hits(xc_coverager_get(op_array->filename TSRMLS_CC), (*EG(opline_ptr))->lineno, 1 TSRMLS_CC); |
---|
459 | } |
---|
460 | } |
---|
461 | } |
---|
462 | /* }}} */ |
---|
463 | |
---|
464 | /* init/destroy */ |
---|
465 | int xc_coverager_init(int module_number TSRMLS_DC) /* {{{ */ |
---|
466 | { |
---|
467 | old_compile_file = zend_compile_file; |
---|
468 | zend_compile_file = xc_compile_file_for_coverage; |
---|
469 | |
---|
470 | if (cfg_get_string("xcache.coveragedump_directory", &xc_coveragedump_dir) == SUCCESS && xc_coveragedump_dir) { |
---|
471 | int len = strlen(xc_coveragedump_dir); |
---|
472 | if (len) { |
---|
473 | if (xc_coveragedump_dir[len - 1] == '/') { |
---|
474 | xc_coveragedump_dir[len - 1] = '\0'; |
---|
475 | } |
---|
476 | } |
---|
477 | if (!strlen(xc_coveragedump_dir)) { |
---|
478 | xc_coveragedump_dir = NULL; |
---|
479 | } |
---|
480 | } |
---|
481 | |
---|
482 | return SUCCESS; |
---|
483 | } |
---|
484 | /* }}} */ |
---|
485 | void xc_coverager_destroy() /* {{{ */ |
---|
486 | { |
---|
487 | if (old_compile_file == xc_compile_file_for_coverage) { |
---|
488 | zend_compile_file = old_compile_file; |
---|
489 | } |
---|
490 | if (xc_coveragedump_dir) { |
---|
491 | xc_coveragedump_dir = NULL; |
---|
492 | } |
---|
493 | } |
---|
494 | /* }}} */ |
---|
495 | |
---|
496 | /* user api */ |
---|
497 | /* {{{ proto array xcache_coverager_decode(string data) |
---|
498 | * decode specified data which is saved by auto dumper to array |
---|
499 | */ |
---|
500 | PHP_FUNCTION(xcache_coverager_decode) |
---|
501 | { |
---|
502 | char *str; |
---|
503 | int len; |
---|
504 | long *p; |
---|
505 | |
---|
506 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &len) == FAILURE) { |
---|
507 | return; |
---|
508 | } |
---|
509 | |
---|
510 | array_init(return_value); |
---|
511 | |
---|
512 | p = (long*) str; |
---|
513 | len -= sizeof(long); |
---|
514 | if (len < 0) { |
---|
515 | return; |
---|
516 | } |
---|
517 | if (*p++ != PCOV_HEADER_MAGIC) { |
---|
518 | TRACE("%s", "wrong magic in xcache_coverager_decode"); |
---|
519 | return; |
---|
520 | } |
---|
521 | |
---|
522 | for (; len >= sizeof(long) * 2; len -= sizeof(long) * 2, p += 2) { |
---|
523 | add_index_long(return_value, p[0], p[1] < 0 ? 0 : p[1]); |
---|
524 | } |
---|
525 | } |
---|
526 | /* }}} */ |
---|
527 | /* {{{ proto void xcache_coverager_start([bool clean = true]) |
---|
528 | * starts coverager data collecting |
---|
529 | */ |
---|
530 | PHP_FUNCTION(xcache_coverager_start) |
---|
531 | { |
---|
532 | zend_bool clean = 1; |
---|
533 | |
---|
534 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &clean) == FAILURE) { |
---|
535 | return; |
---|
536 | } |
---|
537 | |
---|
538 | if (clean) { |
---|
539 | xc_coverager_clean(TSRMLS_C); |
---|
540 | } |
---|
541 | |
---|
542 | if (XG(coverager)) { |
---|
543 | xc_coverager_enable(TSRMLS_C); |
---|
544 | } |
---|
545 | else { |
---|
546 | php_error(E_WARNING, "You can only start coverager after you set 'xcache.coverager' to 'On' in ini"); |
---|
547 | } |
---|
548 | } |
---|
549 | /* }}} */ |
---|
550 | /* {{{ proto void xcache_coverager_stop([bool clean = false]) |
---|
551 | * stop coverager data collecting |
---|
552 | */ |
---|
553 | PHP_FUNCTION(xcache_coverager_stop) |
---|
554 | { |
---|
555 | zend_bool clean = 0; |
---|
556 | |
---|
557 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &clean) == FAILURE) { |
---|
558 | return; |
---|
559 | } |
---|
560 | |
---|
561 | xc_coverager_disable(TSRMLS_C); |
---|
562 | if (clean) { |
---|
563 | xc_coverager_clean(TSRMLS_C); |
---|
564 | } |
---|
565 | } |
---|
566 | /* }}} */ |
---|
567 | /* {{{ proto array xcache_coverager_get([bool clean = false]) |
---|
568 | * get coverager data collected |
---|
569 | */ |
---|
570 | PHP_FUNCTION(xcache_coverager_get) |
---|
571 | { |
---|
572 | zend_bool clean = 0; |
---|
573 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &clean) == FAILURE) { |
---|
574 | return; |
---|
575 | } |
---|
576 | |
---|
577 | xc_coverager_dump(return_value TSRMLS_CC); |
---|
578 | if (clean) { |
---|
579 | xc_coverager_clean(TSRMLS_C); |
---|
580 | } |
---|
581 | } |
---|
582 | /* }}} */ |
---|