| | 315 | static inline zend_uint advance_wrapped(zend_uint val, zend_uint count) /* {{{ */ |
| | 316 | { |
| | 317 | if (val + 1 >= count) { |
| | 318 | return 0; |
| | 319 | } |
| | 320 | return val + 1; |
| | 321 | } |
| | 322 | /* }}} */ |
| | 323 | static void xc_counters_inc(time_t *curtime, zend_uint *curslot, time_t period, zend_ulong *counters, zend_uint count TSRMLS_DC) /* {{{ */ |
| | 324 | { |
| | 325 | time_t n = XG(request_time) / period; |
| | 326 | if (*curtime != n) { |
| | 327 | zend_uint target_slot = n % count; |
| | 328 | if (n - *curtime > period) { |
| | 329 | memset(counters, 0, sizeof(counters[0]) * count); |
| | 330 | } |
| | 331 | else { |
| | 332 | zend_uint slot; |
| | 333 | for (slot = advance_wrapped(*curslot, count); |
| | 334 | slot != target_slot; |
| | 335 | slot = advance_wrapped(slot, count)) { |
| | 336 | counters[slot] = 0; |
| | 337 | } |
| | 338 | counters[target_slot] = 0; |
| | 339 | } |
| | 340 | *curtime = n; |
| | 341 | *curslot = target_slot; |
| | 342 | } |
| | 343 | counters[*curslot] ++; |
| | 344 | } |
| | 345 | /* }}} */ |
| | 346 | static void xc_cache_hit_dmz(xc_cache_t *cache TSRMLS_DC) /* {{{ */ |
| | 347 | { |
| | 348 | cache->hits ++; |
| | 349 | |
| | 350 | xc_counters_inc(&cache->hits_by_hour_cur_time |
| | 351 | , &cache->hits_by_hour_cur_slot, 60 * 60 |
| | 352 | , cache->hits_by_hour |
| | 353 | , sizeof(cache->hits_by_hour) / sizeof(cache->hits_by_hour[0]) |
| | 354 | TSRMLS_CC); |
| | 355 | |
| | 356 | xc_counters_inc(&cache->hits_by_second_cur_time |
| | 357 | , &cache->hits_by_second_cur_slot |
| | 358 | , 1 |
| | 359 | , cache->hits_by_second |
| | 360 | , sizeof(cache->hits_by_second) / sizeof(cache->hits_by_second[0]) |
| | 361 | TSRMLS_CC); |
| | 362 | } |
| | 363 | /* }}} */ |
| | 539 | MAKE_STD_ZVAL(hits); |
| | 540 | array_init(hits); |
| | 541 | for (i = 0; i < sizeof(cache->hits_by_hour) / sizeof(cache->hits_by_hour[0]); i ++) { |
| | 542 | add_next_index_long(hits, (long) cache->hits_by_hour[i]); |
| | 543 | } |
| | 544 | add_assoc_zval_ex(return_value, ZEND_STRS("hits_by_hour"), hits); |
| | 545 | |
| | 546 | MAKE_STD_ZVAL(hits); |
| | 547 | array_init(hits); |
| | 548 | for (i = 0; i < sizeof(cache->hits_by_second) / sizeof(cache->hits_by_second[0]); i ++) { |
| | 549 | add_next_index_long(hits, (long) cache->hits_by_second[i]); |
| | 550 | } |
| | 551 | add_assoc_zval_ex(return_value, ZEND_STRS("hits_by_second"), hits); |