prepend_v4.php 1.5 KB

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