Skip to content

Commit 4836205

Browse files
author
renyongquan
committed
Add heartbeat support
1 parent 906e5d5 commit 4836205

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

phpext/php_phptrace.h

+2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ PHP_FUNCTION(phptrace_mmap_test);
5454
typedef struct phptrace_context_s{
5555
pid_t pid;
5656
int cli;
57+
unsigned long long heartbeat;
58+
int heartbeat_timedout;
5759
phptrace_segment_t ctrl;
5860
phptrace_segment_t tracelog;
5961
void *shmoffset;

phpext/phptrace.c

+16-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333

3434
#define PID_MAX 0x8000 /*32768*/
3535
#define PHPTRACE_LOG_DIR "/tmp"
36+
#define HEARTBEAT_TIMEDOUT 30 /*30 seconds*/
37+
#define HEARTBEAT_FLAG 1<<1
3638

3739
#if PHP_VERSION_ID < 50500
3840
void (*phptrace_old_execute)(zend_op_array *op_array TSRMLS_DC);
@@ -152,6 +154,7 @@ PHP_MINIT_FUNCTION(phptrace)
152154
sapi_module.name[2]=='i'){
153155
ctx->cli = 1;
154156
}
157+
ctx->heartbeat_timedout = HEARTBEAT_TIMEDOUT;
155158
return SUCCESS;
156159
}
157160
/* }}} */
@@ -443,7 +446,7 @@ void phptrace_print_call_result(phptrace_file_record_t *record){
443446

444447
void phptrace_execute_core(zend_execute_data *ex, phptrace_execute_data *px)
445448
{
446-
uint64_t now;
449+
uint64_t now, heartbeat;
447450
uint8_t *ctrl;
448451
void * retoffset;
449452
char filename[256];
@@ -480,6 +483,18 @@ void phptrace_execute_core(zend_execute_data *ex, phptrace_execute_data *px)
480483

481484
}
482485

486+
if(ctrl[ctx->pid] & HEARTBEAT_FLAG){
487+
ctrl[ctx->pid] &= ~HEARTBEAT_FLAG;
488+
ctx->heartbeat = phptrace_time_usec();
489+
}
490+
if((ctrl[ctx->pid] & HEARTBEAT_FLAG == 0) && ctx->heartbeat){
491+
now = phptrace_time_usec();
492+
if(now - ctx->heartbeat > ctx->heartbeat_timedout * 1000000){
493+
phptrace_reset_tracelog(ctx);
494+
goto exec;
495+
}
496+
}
497+
483498
/*do trace*/
484499
/*first startup*/
485500
if(ctx->tracelog.shmaddr == NULL){

0 commit comments

Comments
 (0)