Skip to content

Commit

Permalink
支持函数长度缓冲区设置 #14
Browse files Browse the repository at this point in the history
支持函数长度缓冲区设置 #14
  • Loading branch information
longxinH committed Aug 4, 2021
1 parent 0c59d9d commit 3b78b2f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
2 changes: 2 additions & 0 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ array {
|apm.ignored  | array的可选选项 |忽略性能分析中的某些函数 |
|apm.rate  | 0 - 100 |频率设置,按照0到100的百分比,如果auto设为0,此选项不会生效,如设置大于100会每次开启,等于0则不开启。当不需要此选项时,请注释掉|
|apm.debug  | GET参数名 |此选项可通过特定的GET参数开启性能分析,注释即可关闭。如设置auto = 0,同时GET参数中带有设置值 (例如 http://localhost/?apm_debug) ,也会开启性能分析,优先级高于auto。|
|apm.scratch_buf  | 函数长度缓冲区大小 |默认值:512 |

```
apm.auto = 1
Expand All @@ -146,6 +147,7 @@ apm.ignored[] = md5
;apm.rate = 30
apm.debug = apm_debug
apm.scratch_buf = 1024
```

## 日志管理界面
Expand Down
4 changes: 3 additions & 1 deletion extension/php_xhprof_apm.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ extern zend_module_entry xhprof_apm_module_entry;
*/

/* XHProf_APM version */
#define XHPROF_APM_VERSION "1.0.0"
#define XHPROF_APM_VERSION "1.1.0"

#define APM_FUNC_HASH_COUNTERS_SIZE 1024

Expand Down Expand Up @@ -208,6 +208,8 @@ ZEND_BEGIN_MODULE_GLOBALS(apm)

int debug;

int scratch_buf;

/* counter table indexed by hash value of function names. */
zend_ulong func_hash_counters[APM_FUNC_HASH_COUNTERS_SIZE];

Expand Down
19 changes: 14 additions & 5 deletions extension/xhprof_apm.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ PHP_GINIT_FUNCTION(apm)
apm_globals->trace_callbacks = NULL;
apm_globals->ignored_functions = NULL;
apm_globals->debug = 0;
apm_globals->scratch_buf = SCRATCH_BUF_LEN;

ZVAL_UNDEF(&apm_globals->stats_count);

Expand Down Expand Up @@ -294,6 +295,7 @@ void hp_clean_profiler_state()
APM_G(entries) = NULL;
APM_G(ever_enabled) = 0;
APM_G(debug) = 0;
APM_G(scratch_buf) = SCRATCH_BUF_LEN;

hp_clean_profiler_options_state();
}
Expand Down Expand Up @@ -602,11 +604,11 @@ void hp_mode_hier_beginfn_cb(hp_entry_t **entries, hp_entry_t *current)
void hp_mode_hier_endfn_cb(hp_entry_t **entries)
{
hp_entry_t *top = (*entries);
zval *counts, files_stack;
char symbol[SCRATCH_BUF_LEN];
long int mu_end;
long int pmu_end;
double wt, cpu;
zval *counts, files_stack;
char symbol[APM_G(scratch_buf)];
long int mu_end;
long int pmu_end;
double wt, cpu;

/* Get end tsc counter */
wt = cycle_timer() - top->tsc_start;
Expand Down Expand Up @@ -1494,6 +1496,7 @@ int hp_rshutdown_php(zval *data, int debug)

size_t write_data(void *buffer, size_t size, size_t nmemb, void *userp)
{
return 0;
}

int hp_rshutdown_curl(zval *data, int debug)
Expand Down Expand Up @@ -1643,6 +1646,12 @@ PHP_RINIT_FUNCTION(xhprof_apm)
}
}

pzval = hp_zval_at_key("scratch_buf", apm_config);
if (pzval) {
convert_to_long(pzval);
APM_G(scratch_buf) = Z_LVAL_P(pzval);
}

if (!enable) {
zval_ptr_dtor(&configs);
return SUCCESS;
Expand Down

0 comments on commit 3b78b2f

Please sign in to comment.