callgraph.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. // Copyright (c) 2009 Facebook
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. /**
  17. *
  18. * A callgraph generator for XHProf.
  19. *
  20. * * This file is part of the UI/reporting component,
  21. * used for viewing results of XHProf runs from a
  22. * browser.
  23. *
  24. * Modification History:
  25. * 02/15/2008 - cjiang - The first version of callgraph visualizer
  26. * based on Graphviz's DOT tool.
  27. *
  28. * @author Changhao Jiang (cjiang@facebook.com)
  29. */
  30. // by default assume that xhprof_html & xhprof_lib directories
  31. // are at the same level.
  32. $GLOBALS['XHPROF_LIB_ROOT'] = dirname(__FILE__) . '/../xhprof_lib';
  33. include_once $GLOBALS['XHPROF_LIB_ROOT'].'/display/xhprof.php';
  34. ini_set('max_execution_time', 100);
  35. $params = array(// run id param
  36. 'run' => array(XHPROF_STRING_PARAM, ''),
  37. // source/namespace/type of run
  38. 'source' => array(XHPROF_STRING_PARAM, 'xhprof'),
  39. // the focus function, if it is set, only directly
  40. // parents/children functions of it will be shown.
  41. 'func' => array(XHPROF_STRING_PARAM, ''),
  42. // image type, can be 'jpg', 'gif', 'ps', 'png'
  43. 'type' => array(XHPROF_STRING_PARAM, 'png'),
  44. // only functions whose exclusive time over the total time
  45. // is larger than this threshold will be shown.
  46. // default is 0.01.
  47. 'threshold' => array(XHPROF_FLOAT_PARAM, 0.01),
  48. // whether to show critical_path
  49. 'critical' => array(XHPROF_BOOL_PARAM, true),
  50. // first run in diff mode.
  51. 'run1' => array(XHPROF_STRING_PARAM, ''),
  52. // second run in diff mode.
  53. 'run2' => array(XHPROF_STRING_PARAM, '')
  54. );
  55. // pull values of these params, and create named globals for each param
  56. xhprof_param_init($params);
  57. // if invalid value specified for threshold, then use the default
  58. if ($threshold < 0 || $threshold > 1) {
  59. $threshold = $params['threshold'][1];
  60. }
  61. // if invalid value specified for type, use the default
  62. if (!array_key_exists($type, $xhprof_legal_image_types)) {
  63. $type = $params['type'][1]; // default image type.
  64. }
  65. $xhprof_runs_impl = new XHProfRuns_Default();
  66. if (!empty($run)) {
  67. // single run call graph image generation
  68. xhprof_render_image($xhprof_runs_impl, $run, $type,
  69. $threshold, $func, $source, $critical);
  70. } else {
  71. // diff report call graph image generation
  72. xhprof_render_diff_image($xhprof_runs_impl, $run1, $run2,
  73. $type, $threshold, $source);
  74. }