资讯专栏INFORMATION COLUMN

xhprof 源码分析

2450184176 / 2434人阅读

摘要:下面这四个重新替换封装非常重要,具体的方法作用已经在下面的代码注释中写明了。使输出的性能数据中添加数据。我们这里不考虑和内存,那么发现给每隔设置了一个的起始时钟周期。

XHProf 简要概念

重新封装zend的原生方法

如果要检测CPU的话,会有5ms的延迟,因为需要计算cpu频率

内部使用了链表

源码地址:/root/Downloads/xhprof/extension/xhprof.c

最重要的两个结构体

</>复制代码

  1. /* Xhprof"s global state.
  2. *
  3. * This structure is instantiated once. Initialize defaults for attributes in
  4. * 这个结构体只初始化一次
  5. * hp_init_profiler_state() Cleanup/free attributes in
  6. * hp_clean_profiler_state() */
  7. typedef struct hp_global_t {
  8. /* ---------- Global attributes: ----------- */
  9. /* Indicates if xhprof is currently enabled 是否当前可用 */
  10. int enabled;
  11. /* Indicates if xhprof was ever enabled during this request 在本次请求过程中是否其用过xhprof */
  12. int ever_enabled;
  13. /* Holds all the xhprof statistics */
  14. zval *stats_count;
  15. /* Indicates the current xhprof mode or level 当前的运行模式和等级*/
  16. int profiler_level;
  17. /* Top of the profile stack 堆栈中的第一个*/
  18. hp_entry_t *entries;
  19. /* freelist of hp_entry_t chunks for reuse... */
  20. hp_entry_t *entry_free_list;
  21. /* Callbacks for various xhprof modes 代表不同模式的回调么?*/
  22. hp_mode_cb mode_cb;
  23. /* ---------- Mode specific attributes: ----------- */
  24. /* Global to track the time of the last sample in time and ticks */
  25. struct timeval last_sample_time;
  26. uint64 last_sample_tsc;
  27. /* XHPROF_SAMPLING_INTERVAL in ticks */
  28. uint64 sampling_interval_tsc;
  29. /* This array is used to store cpu frequencies for all available logical
  30. * cpus. For now, we assume the cpu frequencies will not change for power
  31. * saving or other reasons. If we need to worry about that in the future, we
  32. * can use a periodical timer to re-calculate this arrary every once in a
  33. * while (for example, every 1 or 5 seconds). 处理器的执行频率?*/
  34. double *cpu_frequencies;
  35. /* The number of logical CPUs this machine has. 逻辑cpu的数量*/
  36. uint32 cpu_num;
  37. /* The saved cpu affinity. */
  38. cpu_set_t prev_mask;
  39. /* The cpu id current process is bound to. (default 0) 当前进程在的处理器的id*/
  40. uint32 cur_cpu_id;
  41. /* XHProf flags */
  42. uint32 xhprof_flags;
  43. /* counter table indexed by hash value of function names. 方法的调用次数的表*/
  44. uint8 func_hash_counters[256];
  45. /* Table of ignored function names and their filter 忽略统计的方法的表格*/
  46. char **ignored_function_names;
  47. uint8 ignored_function_filter[XHPROF_IGNORED_FUNCTION_FILTER_SIZE];
  48. } hp_global_t;

</>复制代码

  1. typedef struct hp_entry_t {
  2. char *name_hprof; /* function name 方法名称*/
  3. int rlvl_hprof; /* recursion level for function 方法的递归层级*/
  4. uint64 tsc_start; /* start value for TSC counter 开始的时钟周期*/
  5. long int mu_start_hprof; /* memory usage 内存使用量*/
  6. long int pmu_start_hprof; /* peak memory usage 内存使用峰值*/
  7. struct rusage ru_start_hprof; /* user/sys time start */
  8. struct hp_entry_t *prev_hprof; /* ptr to prev entry being profiled 指向上一个被分析的指针*/
  9. uint8 hash_code; /* hash_code for the function name 每个方法名称对应的hash*/
  10. } hp_entry_t;
XHProf 在php中的使用

我们先看下XHProf的使用方法

</>复制代码

  1. save_run($data,"test");
  2. // 我这里直接将可视化的链接地址打印了出来,方便调试
  3. echo "test";
  4. function test() {
  5. $a = range(0,10000);
  6. foreach($a as $item) {
  7. // pass
  8. }
  9. }

执行结果如下:(可以直接跳过结果,看下面,但是要记住有ct、wt这两个值)

</>复制代码

  1. array(7) {
  2. ["test==>range"]=>
  3. array(2) {
  4. ["ct"]=>
  5. int(2)
  6. ["wt"]=>
  7. int(4463)
  8. }
  9. ["main()==>test"]=>
  10. array(2) {
  11. ["ct"]=>
  12. int(1)
  13. ["wt"]=>
  14. int(3069)
  15. }
  16. ["main()==>eval::/var/www/html/index2.php(9) : eval()"d code"]=>
  17. array(2) {
  18. ["ct"]=>
  19. int(1)
  20. ["wt"]=>
  21. int(16)
  22. }
  23. ["eval==>test"]=>
  24. array(2) {
  25. ["ct"]=>
  26. int(1)
  27. ["wt"]=>
  28. int(2614)
  29. }
  30. ["main()==>eval"]=>
  31. array(2) {
  32. ["ct"]=>
  33. int(1)
  34. ["wt"]=>
  35. int(2617)
  36. }
  37. ["main()==>xhprof_disable"]=>
  38. array(2) {
  39. ["ct"]=>
  40. int(1)
  41. ["wt"]=>
  42. int(0)
  43. }
  44. ["main()"]=>
  45. array(2) {
  46. ["ct"]=>
  47. int(1)
  48. ["wt"]=>
  49. int(5716)
  50. }
  51. }
XHProf 源码 xhprof_enable()

首先我们来看xhprof_enable(),这个方法定义了要接受的三个参数,并且将这三个参数分别传递给两个方法使用,其中最重要的是hp_begin()

</>复制代码

  1. /**
  2. * Start XHProf profiling in hierarchical mode.
  3. *
  4. * @param long $flags flags for hierarchical mode
  5. * @return void
  6. * @author kannan
  7. */
  8. PHP_FUNCTION(xhprof_enable) {
  9. long xhprof_flags = 0; /* XHProf flags */
  10. zval *optional_array = NULL; /* optional array arg: for future use */
  11. /*
  12. 获取参数并且允许传递一个l 和z的可选参数 分别代表xhprof_flags 和 optional_array
  13. 关于TSRMLS_CC 可以看http://www.laruence.com/2008/08/03/201.html
  14. 另外关于zend_parse_parameters的返回值failure 代表参数的处理是否成功
  15. */
  16. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
  17. "|lz", &xhprof_flags, &optional_array) == FAILURE) {
  18. return;
  19. }
  20. /*
  21. 从参数中获取需要被忽略的方法
  22. 参照手册参数的说明 http://php.net/manual/zh/function.xhprof-enable.php
  23. */
  24. hp_get_ignored_functions_from_arg(optional_array);
  25. hp_begin(XHPROF_MODE_HIERARCHICAL, xhprof_flags TSRMLS_CC);
  26. }
hp_begin()

这个方法看起来很长,但是世界上逻辑很简单,主要是进行了一些初始化。
下面一共进行了四次replace,用来封装zend的方法。

下面这四个重新替换封装非常重要,具体的方法作用已经在下面的代码注释中写明了。

zend_compile_file => hp_compile_file

zend_compile_string => hp_compile_string

zend_execute => hp_execute

zend_execute_internal => hp_execute_internal

</>复制代码

  1. /**
  2. * This function gets called once when xhprof gets enabled.
  3. * 这个方法在enable的时候调用一次
  4. * It replaces all the functions like zend_execute, zend_execute_internal,
  5. * etc that needs to be instrumented with their corresponding proxies.
  6. * 他用来替换zend的一些需要被代理的方法意思就是xhprof劫持了原生方法
  7. * hp_begin(XHPROF_MODE_HIERARCHICAL, xhprof_flags TSRMLS_CC);
  8. *
  9. * level 等级
  10. * xhprof_flags 运行方式
  11. */
  12. static void hp_begin(long level, long xhprof_flags TSRMLS_DC) {
  13. /*
  14. 如果xhprof 没有开启,也就是没有调用enable方法,那么走这里买的逻辑,这个是通过hp_globals来判断的,
  15. */
  16. if (!hp_globals.enabled) {
  17. int hp_profile_flag = 1;
  18. hp_globals.enabled = 1; /* 这里修改了enbale状态,保证enable在整个请求过程中只会被第一次调用触发 */
  19. hp_globals.xhprof_flags = (uint32)xhprof_flags; /* 格式化为32位的无符号整数 */
  20. /*
  21. 下面一共进行了四次replace,用来封装zend的方法
  22. 1. zend_compile_file => hp_compile_file
  23. zend_compile_file负责将要执行的脚本文件编译成由ZE的基本指令序列构成的op codes , 然后将op codes交由zend_execute执行,从而得到我们脚本的结果。
  24. http://www.laruence.com/2008/08/14/250.html
  25. 2. zend_compile_string => hp_compile_string
  26. 这个是把php代码编译成为opcode的过程
  27. http://www.phpchina.com/portal.php?mod=view&aid=40347
  28. 3. zend_execute => hp_execute
  29. zend_compile_file() zend_compile_file() is the wrapper for the lexer, parser, and code generator. It compiles a file and returns a zend_op_array.
  30. zend_execute() After a file is compiled, its zend_op_array is executed by zend_execute().
  31. http://php.find-info.ru/php/016/ch23lev1sec2.html
  32. 4. zend_execute_internal => hp_execute_internal
  33. There is also a companion zend_execute_internal() function, which executes internal functions.
  34. */
  35. /* Replace zend_compile with our proxy 先对其进行了备份_,通过加入_下划线的方式,然后使用hp_compile_file来替换*/
  36. _zend_compile_file = zend_compile_file;
  37. zend_compile_file = hp_compile_file;
  38. /* Replace zend_compile_string with our proxy */
  39. _zend_compile_string = zend_compile_string;
  40. zend_compile_string = hp_compile_string;
  41. /* Replace zend_execute with our proxy */
  42. #if PHP_VERSION_ID < 50500
  43. _zend_execute = zend_execute;
  44. zend_execute = hp_execute;
  45. #else
  46. _zend_execute_ex = zend_execute_ex;
  47. zend_execute_ex = hp_execute_ex;
  48. #endif
  49. /* Replace zend_execute_internal with our proxy */
  50. _zend_execute_internal = zend_execute_internal;
  51. /*
  52. XHPROF_FLAGS_NO_BUILTINGS 是用来标识,不需要统计内置函数性能
  53. 通过位运算&来判断是否用户传递的flags包含了NO_BUILTINGS
  54. 除此之外还包含一下三种flags
  55. 1. HPROF_FLAGS_NO_BUILTINS (integer) 使得跳过所有内置(内部)函数。
  56. 2. XHPROF_FLAGS_CPU (integer) 使输出的性能数据中添加 CPU 数据。
  57. 3. XHPROF_FLAGS_MEMORY (integer) 使输出的性能数据中添加内存数据。
  58. */
  59. if (!(hp_globals.xhprof_flags & XHPROF_FLAGS_NO_BUILTINS)) {
  60. /* if NO_BUILTINS is not set (i.e. user wants to profile builtins),
  61. * then we intercept internal (builtin) function calls.
  62. * 如果没有设置的话,那么就代表用户想分析内置函数性能,并且我们就会拦截内置的方法请求
  63. */
  64. zend_execute_internal = hp_execute_internal;
  65. }
  66. /* Initialize with the dummy mode first Having these dummy callbacks saves
  67. * us from checking if any of the callbacks are NULL everywhere.
  68. * 首先来初始化一下这些方法,可以避免在回调方法为NULL的时候*/
  69. hp_globals.mode_cb.init_cb = hp_mode_dummy_init_cb;
  70. hp_globals.mode_cb.exit_cb = hp_mode_dummy_exit_cb;
  71. hp_globals.mode_cb.begin_fn_cb = hp_mode_dummy_beginfn_cb;
  72. hp_globals.mode_cb.end_fn_cb = hp_mode_dummy_endfn_cb;
  73. /* Register the appropriate callback functions Override just a subset of
  74. * all the callbacks is OK. 根据不同的处理模式,简单还是详细*/
  75. switch(level) {
  76. /* 一般都是使用的这个模式,所以我们专注看这个mode */
  77. case XHPROF_MODE_HIERARCHICAL:
  78. hp_globals.mode_cb.begin_fn_cb = hp_mode_hier_beginfn_cb;
  79. hp_globals.mode_cb.end_fn_cb = hp_mode_hier_endfn_cb;
  80. break;
  81. case XHPROF_MODE_SAMPLED:
  82. hp_globals.mode_cb.init_cb = hp_mode_sampled_init_cb;
  83. hp_globals.mode_cb.begin_fn_cb = hp_mode_sampled_beginfn_cb;
  84. hp_globals.mode_cb.end_fn_cb = hp_mode_sampled_endfn_cb;
  85. break;
  86. }
  87. /* one time initializations 初始化分析器,内部搞定了cpu频率、initcb、可忽略的方法*/
  88. hp_init_profiler_state(level TSRMLS_CC);
  89. /* start profiling from fictitious main() */
  90. BEGIN_PROFILING(&hp_globals.entries, ROOT_SYMBOL, hp_profile_flag);
  91. }
  92. }
hp_init_profiler_state()

</>复制代码

  1. /**
  2. * Initialize profiler state
  3. * 初始化分析器状态
  4. *
  5. * 这里最开始的时候传递进来的level是XHPROF_MODE_HIERARCHICAL
  6. *
  7. * @author kannan, veeve
  8. */
  9. void hp_init_profiler_state(int level TSRMLS_DC) {
  10. /* Setup globals */
  11. if (!hp_globals.ever_enabled) {
  12. /* 如果之前没有开启过xhprof,那么将这个值初始化为1,现在就算开启了 */
  13. hp_globals.ever_enabled = 1;
  14. /* 堆栈的第一个设置空 */
  15. hp_globals.entries = NULL;
  16. }
  17. /* 分析器的等级 */
  18. hp_globals.profiler_level = (int) level;
  19. /* Init stats_count 初始化统计数量 */
  20. if (hp_globals.stats_count) {
  21. /* 释放这个内存 */
  22. zval_dtor(hp_globals.stats_count);
  23. /* 通知垃圾回收机制来回收这个内存 */
  24. FREE_ZVAL(hp_globals.stats_count);
  25. }
  26. /* 创建一个zval变量,并且初始化为数组 参考 http://www.cunmou.com/phpbook/8.3.md */
  27. MAKE_STD_ZVAL(hp_globals.stats_count);
  28. array_init(hp_globals.stats_count);
  29. /* NOTE(cjiang): some fields such as cpu_frequencies take relatively longer
  30. * to initialize, (5 milisecond per logical cpu right now), therefore we
  31. * calculate them lazily. 一些字段初始化起来要花费非常长的时间,那么我们要懒计算,就是放到后面计算*/
  32. if (hp_globals.cpu_frequencies == NULL) {
  33. get_all_cpu_frequencies();
  34. restore_cpu_affinity(&hp_globals.prev_mask);
  35. }
  36. /* bind to a random cpu so that we can use rdtsc instruction. 这里竟然是随机绑定一个cpu*/
  37. bind_to_cpu((int) (rand() % hp_globals.cpu_num));
  38. /* Call current mode"s init cb 根据不同的模式,调用初始方法,看line:1933*/
  39. hp_globals.mode_cb.init_cb(TSRMLS_C);
  40. /* Set up filter of functions which may be ignored during profiling 设置被过滤的方法*/
  41. hp_ignored_functions_filter_init();
  42. }
get_cpu_frequency()

在上面的方法中调用了一个get_all_cpu_frequencies(),这个方法内部调用了一个get_cpu_frequency很有意思,因为这个方法将导致如果开启CPU的检测,那么会有5ms的延迟

</>复制代码

  1. /**
  2. * This is a microbenchmark to get cpu frequency the process is running on. The
  3. * returned value is used to convert TSC counter values to microseconds.
  4. *
  5. * @return double.
  6. * @author cjiang
  7. */
  8. static double get_cpu_frequency() {
  9. struct timeval start;
  10. struct timeval end;
  11. /* gettimeofday 获取当前的时间,并且放到start中 */
  12. if (gettimeofday(&start, 0)) {
  13. perror("gettimeofday");
  14. return 0.0;
  15. }
  16. uint64 tsc_start = cycle_timer();
  17. /* Sleep for 5 miliseconds. Comparaing with gettimeofday"s few microseconds
  18. * execution time, this should be enough.
  19. * 这个是为了获取CPU的执行频率,用5000微秒的时间中cpu的执行次数,来得到每秒cpu能执行的频率
  20. * TSC 自从启动CPU开始记录的时钟周期
  21. * */
  22. usleep(5000);
  23. if (gettimeofday(&end, 0)) {
  24. perror("gettimeofday");
  25. return 0.0;
  26. }
  27. uint64 tsc_end = cycle_timer();
  28. /* 时钟周期的数量除以微秒时间间隔的数量得到cpu频率 */
  29. return (tsc_end - tsc_start) * 1.0 / (get_us_interval(&start, &end));
  30. }
BEGIN_PROFILING 重要!

这个就是分析的逻辑,他的要点在于生成了一个单项链表。

</>复制代码

  1. /*
  2. * Start profiling - called just before calling the actual function
  3. * 开始分析,只在正式方法调用之前要调用
  4. * NOTE: PLEASE MAKE SURE TSRMLS_CC IS AVAILABLE IN THE CONTEXT
  5. * OF THE FUNCTION WHERE THIS MACRO IS CALLED.
  6. * TSRMLS_CC CAN BE MADE AVAILABLE VIA TSRMLS_DC IN THE
  7. * CALLING FUNCTION OR BY CALLING TSRMLS_FETCH()
  8. * TSRMLS_FETCH() IS RELATIVELY EXPENSIVE.
  9. * entries 这里传递进来的是hp_entry_t的一个指向指针的地址
  10. * 这个地方实际上生成的是一个单链表,都是用prev_hprof 来进行关联
  11. *
  12. * 这里do while(0) 是用来封装宏的
  13. *
  14. */
  15. #define BEGIN_PROFILING(entries, symbol, profile_curr)
  16. do {
  17. /* Use a hash code to filter most of the string comparisons. */
  18. uint8 hash_code = hp_inline_hash(symbol);
  19. /* 判断这个方法是否是需要忽略的方法,如果不是需要被忽略的,那么进行分析 */
  20. profile_curr = !hp_ignore_entry(hash_code, symbol);
  21. if (profile_curr) {
  22. /* 返回一个指针(地址),开辟了一个内存空间给cur_entry,包括了hash_code、方法名称、堆栈指针 */
  23. hp_entry_t *cur_entry = hp_fast_alloc_hprof_entry();
  24. (cur_entry)->hash_code = hash_code;
  25. (cur_entry)->name_hprof = symbol;
  26. /* 这里的*entries 指向的是指针hp_global_t.entires 堆栈的首地址 */
  27. (cur_entry)->prev_hprof = (*(entries));
  28. /* Call the universal callback*/
  29. hp_mode_common_beginfn((entries), (cur_entry) TSRMLS_CC);
  30. /* Call the mode"s beginfn callback 这个方法除却cpu和mem 只是设置了tsc_Start */
  31. hp_globals.mode_cb.begin_fn_cb((entries), (cur_entry) TSRMLS_CC);
  32. /* Update entries linked list */
  33. (*(entries)) = (cur_entry);
  34. }
  35. } while (0)

我们可以看上面的链表在生成的过程中,调用了 hp_globals.mode_cb.begin_fn_cb方法。我们这里不考虑CPU和内存,那么发现给每隔current设置了一个tsc的起始时钟周期。

</>复制代码

  1. /**
  2. * XHPROF_MODE_HIERARCHICAL"s begin function callback
  3. *
  4. * @author kannan
  5. */
  6. void hp_mode_hier_beginfn_cb(hp_entry_t **entries,
  7. hp_entry_t *current TSRMLS_DC) {
  8. /* Get start tsc counter */
  9. current->tsc_start = cycle_timer();
  10. /* Get CPU usage 如果要计算cpu的话*/
  11. if (hp_globals.xhprof_flags & XHPROF_FLAGS_CPU) {
  12. getrusage(RUSAGE_SELF, &(current->ru_start_hprof));
  13. }
  14. /* Get memory usage 如果要计算内存的话*/
  15. if (hp_globals.xhprof_flags & XHPROF_FLAGS_MEMORY) {
  16. current->mu_start_hprof = zend_memory_usage(0 TSRMLS_CC);
  17. current->pmu_start_hprof = zend_memory_peak_usage(0 TSRMLS_CC);
  18. }
  19. }
hp_execute 代码执行部分

每次有代码执行的时候,都会走这个地方,这段代码主要是在执行zend_execute的前后,粉分别调用了BEGIN_PROFILINGEND_PROFILING

</>复制代码

  1. #if PHP_VERSION_ID < 50500
  2. ZEND_DLEXPORT void hp_execute (zend_op_array *ops TSRMLS_DC) {
  3. #else
  4. ZEND_DLEXPORT void hp_execute_ex (zend_execute_data *execute_data TSRMLS_DC) {
  5. zend_op_array *ops = execute_data->op_array;
  6. #endif
  7. char *func = NULL;
  8. int hp_profile_flag = 1;
  9. func = hp_get_function_name(ops TSRMLS_CC);
  10. if (!func) {
  11. #if PHP_VERSION_ID < 50500
  12. _zend_execute(ops TSRMLS_CC);
  13. #else
  14. _zend_execute_ex(execute_data TSRMLS_CC);
  15. #endif
  16. return;
  17. }
  18. BEGIN_PROFILING(&hp_globals.entries, func, hp_profile_flag);
  19. #if PHP_VERSION_ID < 50500
  20. _zend_execute(ops TSRMLS_CC);
  21. #else
  22. _zend_execute_ex(execute_data TSRMLS_CC);
  23. #endif
  24. if (hp_globals.entries) {
  25. END_PROFILING(&hp_globals.entries, hp_profile_flag);
  26. }
  27. efree(func);
  28. }
END_PROFILING

</>复制代码

  1. hp_globals.mode_cb.end_fn_cb((entries) TSRMLS_CC);

这段代码最终指向了hp_mode_hier_endfn_cb,这段代码中主要构成了一个"==>"数据格式,并且计算了每个方法的调用次数。

</>复制代码

  1. void hp_mode_hier_endfn_cb(hp_entry_t **entries TSRMLS_DC) {
  2. /* 整个堆栈的最后一个调用 */
  3. hp_entry_t *top = (*entries);
  4. zval *counts;
  5. struct rusage ru_end;
  6. char symbol[SCRATCH_BUF_LEN];
  7. long int mu_end;
  8. long int pmu_end;
  9. /* Get the stat array */
  10. hp_get_function_stack(top, 2, symbol, sizeof(symbol));
  11. if (!(counts = hp_mode_shared_endfn_cb(top,
  12. symbol TSRMLS_CC))) {
  13. return;
  14. }
  15. if (hp_globals.xhprof_flags & XHPROF_FLAGS_CPU) {
  16. /* Get CPU usage */
  17. getrusage(RUSAGE_SELF, &ru_end);
  18. /* Bump CPU stats in the counts hashtable */
  19. hp_inc_count(counts, "cpu", (get_us_interval(&(top->ru_start_hprof.ru_utime),
  20. &(ru_end.ru_utime)) +
  21. get_us_interval(&(top->ru_start_hprof.ru_stime),
  22. &(ru_end.ru_stime)))
  23. TSRMLS_CC);
  24. }
  25. if (hp_globals.xhprof_flags & XHPROF_FLAGS_MEMORY) {
  26. /* Get Memory usage */
  27. mu_end = zend_memory_usage(0 TSRMLS_CC);
  28. pmu_end = zend_memory_peak_usage(0 TSRMLS_CC);
  29. /* Bump Memory stats in the counts hashtable */
  30. hp_inc_count(counts, "mu", mu_end - top->mu_start_hprof TSRMLS_CC);
  31. hp_inc_count(counts, "pmu", pmu_end - top->pmu_start_hprof TSRMLS_CC);
  32. }
  33. }
hp_mode_shared_endfn_cb

这个方法统计了调用次数和消耗时间,实际上最终所有的数据都存储在hp_entry_t所构造的链表中

</>复制代码

  1. zval * hp_mode_shared_endfn_cb(hp_entry_t *top,
  2. char *symbol TSRMLS_DC) {
  3. zval *counts;
  4. uint64 tsc_end;
  5. /* Get end tsc counter */
  6. tsc_end = cycle_timer();
  7. /* Get the stat array */
  8. if (!(counts = hp_hash_lookup(symbol TSRMLS_CC))) {
  9. return (zval *) 0;
  10. }
  11. /* Bump stats in the counts hashtable */
  12. hp_inc_count(counts, "ct", 1 TSRMLS_CC);
  13. hp_inc_count(counts, "wt", get_us_from_tsc(tsc_end - top->tsc_start,
  14. hp_globals.cpu_frequencies[hp_globals.cur_cpu_id]) TSRMLS_CC);
  15. return counts;
  16. }

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/23171.html

相关文章

  • 使用PHP扩展Xhprof分析项目性能实践

    摘要:一背景项目即将上线,想通过一些工具来分析代码的稳定性和效率,想起在上个团队时使用过的扩展因为换了新电脑,所以需要重新编译此扩展,现将安装与实际排查过程完整记录下来,方便自己回顾和帮助更多的读者。作者汤青松微信日期 一、背景 项目即将上线,想通过一些工具来分析代码的稳定性和效率,想起在上个团队时使用过的xhprof扩展;因为换了新电脑,所以需要重新编译此扩展,现将安装与实际排查过程完整记...

    高胜山 评论0 收藏0
  • PHP 性能追踪及分析工具(XHPROF

    摘要:什么是开源的轻量级性能分析工具。它报告函数级别的请求次数和各种指标,包括阻塞时间,时间和内存使用情况。基于浏览器的性能分析用户界面能更容易查看,或是与同行们分享成果。对于本地开发环境来说,进行性能分析是够用了。 什么是 XHPROF? XHPROF:Facebook 开源的轻量级PHP性能分析工具。 它报告函数级别的请求次数和各种指标,包括阻塞时间,CPU时间和内存使用情况。 XHPr...

    raoyi 评论0 收藏0
  • php xhprof使用

    摘要:性能分析此版本为第三方扩展官房不支持目录为扩展源码安状扩展即可编辑启用扩展性能分析数据文件存放位置需要用户有可写可读权限对项目入口文件添加代码在第一步后的文件夹里面生成数据文件后缀或者创建网占目录为例在第一步后的文件夹里面访问上面虚拟主机 xhprof php性能分析 1.clone xhprof 此版本为github第三方扩展 (php官房不支持 php 7) https://git...

    superw 评论0 收藏0
  • 使用XHProf查找PHP性能瓶颈

    摘要:是开发的一个测试性能的扩展,本文记录了在应用中使用对进行性能优化,查找性能瓶颈的方法。函数用于停止性能分析,并返回分析的数据。该参数用于为剖析结果添加额外的信息,该参数的值使用以下宏,如果需要提供多个值,使用进行分隔。 XHProf是facebook 开发的一个测试php性能的扩展,本文记录了在PHP应用中使用XHProf对PHP进行性能优化,查找性能瓶颈的方法。 安装Xhprof扩展...

    Xufc 评论0 收藏0

发表评论

0条评论

最新活动
阅读需要支付1元查看
<