prepend_xhprof.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. register_shutdown_function(
  3. function () {
  4. register_shutdown_function(function () {
  5. $data = xhprof_disable();
  6. echo 'Nodes in report: ' . count($data) . "\n";
  7. $name = getenv('REPORT');
  8. if (empty($name)) {
  9. $name = 'xhprof_report.' . microtime(1) . '.serialized';
  10. }
  11. echo 'Saving report to ' . $name, "\n";
  12. file_put_contents('/code/' . $name,
  13. '.json' === substr($name, -5) ? json_encode($data) : serialize($data));
  14. if (getenv('SVG')) {
  15. include_once "/utils/callgraph_utils.php";
  16. include_once "/utils/xhprof_lib.php";
  17. include_once "/utils/xhprof_runs.php";
  18. echo "Generating dot script\n";
  19. $threshold = 0;
  20. if (count($data) > 1000) {
  21. $threshold = 0.001;
  22. }
  23. $script = xhprof_generate_dot_script($data, $threshold, null, null, null, null);
  24. echo "Generating dot image\n";
  25. $content = xhprof_generate_image_by_dot($script, 'svg');
  26. echo 'Saving graph to ' . $name . '.svg', "\n";
  27. file_put_contents('/code/' . $name . '.svg',
  28. $content);
  29. }
  30. });
  31. }
  32. );
  33. xhprof_enable(XHPROF_FLAGS_MEMORY | XHPROF_FLAGS_CPU);