PageRenderTime 41ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/xhprof_lib/utils/common.php

http://github.com/preinheimer/xhprof
PHP | 127 lines | 106 code | 21 blank | 0 comment | 9 complexity | fd8b90f9c546b9b3cbed72e75bacf959 MD5 | raw file
Possible License(s): Apache-2.0
  1. <?php
  2. function displayRuns($resultSet, $title = "")
  3. {
  4. echo "<h1 class=\"runTitle\">$title</h1>\n";
  5. echo "<table id=\"box-table-a\" class=\"tablesorter\" summary=\"Stats\"><thead><tr><th>Timestamp</th><th>Cpu</th><th>Wall Time</th><th>Peak Memory Usage</th><th>URL</th><th>Simplified URL</th></tr></thead>";
  6. echo "<tbody>\n";
  7. while ($row = XHProfRuns_Default::getNextAssoc($resultSet))
  8. {
  9. $c_url = urlencode($row['c_url']);
  10. $url = urlencode($row['url']);
  11. $html['url'] = htmlentities($row['url'], ENT_QUOTES, 'UTF-8');
  12. $html['c_url'] = htmlentities($row['c_url'], ENT_QUOTES, 'UTF-8');
  13. $date = strtotime($row['timestamp']);
  14. $date = date('M d H:i:s', $date);
  15. echo "\t<tr><td><a href=\"?run={$row['id']}\">$date</a><br /><span class=\"runid\">{$row['id']}</span></td><td>{$row['cpu']}</td><td>{$row['wt']}</td><td>{$row['pmu']}</td><td><a href=\"?geturl={$url}\">{$html['url']}</a></td><td><a href=\"?getcurl={$c_url}\">{$html['c_url']}</a></td></tr>\n";
  16. }
  17. echo "</tbody>\n";
  18. echo "</table>\n";
  19. echo <<<SORTTABLE
  20. <script type="text/javascript">
  21. $(document).ready(function()
  22. {
  23. $("#box-table-a").tablesorter( {sortList: []} );
  24. }
  25. );
  26. </script>
  27. SORTTABLE;
  28. }
  29. function printSeconds($time)
  30. {
  31. $suffix = "microsecond";
  32. if ($time > 1000)
  33. {
  34. $time = $time / 1000;
  35. $suffix = "ms";
  36. }
  37. if ($time > 1000)
  38. {
  39. $time = $time / 1000;
  40. $suffix = "s";
  41. }
  42. if ($time > 60 && $suffix == "s")
  43. {
  44. $time = $time / 60;
  45. $suffix = "minutes!";
  46. }
  47. return sprintf("%.4f {$suffix}", $time);
  48. }
  49. function showChart($rs, $flip = false)
  50. {
  51. $dataPoints = "";
  52. $ids = array();
  53. $arCPU = array();
  54. $arWT = array();
  55. $arPEAK = array();
  56. $arIDS = array();
  57. $arDateIDs = array();
  58. while($row = XHProfRuns_Default::getNextAssoc($rs))
  59. {
  60. $date[] = "'" . date("Y-m-d", $row['timestamp']) . "'" ;
  61. $arCPU[] = $row['cpu'];
  62. $arWT[] = $row['wt'];
  63. $arPEAK[] = $row['pmu'];
  64. $arIDS[] = $row['id'];
  65. $arDateIDs[] = "'" . date("Y-m-d", $row['timestamp']) . " <br/> " . $row['id'] . "'";
  66. }
  67. $date = $flip ? array_reverse($date) : $date;
  68. $arCPU = $flip ? array_reverse($arCPU) : $arCPU;
  69. $arWT = $flip ? array_reverse($arWT) : $arWT;
  70. $arPEAK = $flip ? array_reverse($arPEAK) : $arPEAK;
  71. $arIDS = $flip ? array_reverse($arIDS) : $arIDS;
  72. $arDateIDs = $flip ? array_reverse($arDateIDs) : $arDateIDs;
  73. $dateJS = implode(", ", $date);
  74. $cpuJS = implode(", ", $arCPU);
  75. $wtJS = implode(", ", $arWT);
  76. $pmuJS = implode(", ", $arPEAK);
  77. $idsJS = implode(", ", $arIDS);
  78. $dateidsJS = implode(", ", $arDateIDs);
  79. ob_start();
  80. require ("../xhprof_lib/templates/chart.phtml");
  81. $stuff = ob_get_contents();
  82. ob_end_clean();
  83. return array($stuff, "<div id=\"container\" style=\"width: 1000px; height: 500px; margin: 0 auto\"></div>");
  84. }
  85. function getFilter($filterName)
  86. {
  87. if (isset($_GET[$filterName]))
  88. {
  89. if ($_GET[$filterName] == "None")
  90. {
  91. $serverFilter = null;
  92. setcookie($filterName, null, 0);
  93. }else
  94. {
  95. setcookie($filterName, $_GET[$filterName], (time() + 60 * 60));
  96. $serverFilter = $_GET[$filterName];
  97. }
  98. }elseif(isset($_COOKIE[$filterName]))
  99. {
  100. $serverFilter = $_COOKIE[$filterName];
  101. }else
  102. {
  103. $serverFilter = null;
  104. }
  105. return $serverFilter;
  106. }