PageRenderTime 43ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/dist/webpagetest/www/benchmarks/view.php

http://webpagetest.googlecode.com/
PHP | 261 lines | 250 code | 3 blank | 8 comment | 64 complexity | d53ba54a90e1841f392efc010092b1ef MD5 | raw file
Possible License(s): AGPL-1.0, Apache-2.0, GPL-3.0, LGPL-3.0, MIT, BSD-3-Clause, ISC, LGPL-2.1
  1. <?php
  2. chdir('..');
  3. include 'common.inc';
  4. include './benchmarks/data.inc.php';
  5. $page_keywords = array('Benchmarks','Webpagetest','Website Speed Test','Page Speed');
  6. $page_description = "WebPagetest benchmark details";
  7. $aggregate = 'median';
  8. if (array_key_exists('aggregate', $_REQUEST))
  9. $aggregate = $_REQUEST['aggregate'];
  10. $benchmark = '';
  11. if (array_key_exists('benchmark', $_REQUEST)) {
  12. $benchmark = $_REQUEST['benchmark'];
  13. $info = GetBenchmarkInfo($benchmark);
  14. }
  15. if (array_key_exists('f', $_REQUEST)) {
  16. $out_data = array();
  17. } else {
  18. ?>
  19. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  20. <html>
  21. <head>
  22. <title>WebPagetest - Benchmark details</title>
  23. <meta http-equiv="charset" content="iso-8859-1">
  24. <meta name="keywords" content="Performance, Optimization, Pagetest, Page Design, performance site web, internet performance, website performance, web applications testing, web application performance, Internet Tools, Web Development, Open Source, http viewer, debugger, http sniffer, ssl, monitor, http header, http header viewer">
  25. <meta name="description" content="Speed up the performance of your web pages with an automated analysis">
  26. <meta name="author" content="Patrick Meenan">
  27. <?php $gaTemplate = 'About'; include ('head.inc'); ?>
  28. <script type="text/javascript" src="/js/dygraph-combined.js"></script>
  29. <style type="text/css">
  30. .chart-container { clear: both; width: 875px; height: 350px; margin-left: auto; margin-right: auto; padding: 0;}
  31. .benchmark-chart { float: left; width: 700px; height: 350px; }
  32. .benchmark-legend { float: right; width: 150px; height: 350px; }
  33. </style>
  34. </head>
  35. <body>
  36. <div class="page">
  37. <?php
  38. $tab = 'Benchmarks';
  39. include 'header.inc';
  40. ?>
  41. <div class="translucent">
  42. <?php
  43. if (isset($info) && array_key_exists('links', $info)) {
  44. echo '<div style="clear:both; padding-bottom: 0.5em;">Benchmark Information: ';
  45. $link_count = 0;
  46. foreach ($info['links'] as $link_label => $link_url) {
  47. if ($link_count) {
  48. echo " - ";
  49. }
  50. echo "<a href=\"$link_url\">$link_label</a>";
  51. $link_count++;
  52. }
  53. echo '</div>';
  54. }
  55. ?>
  56. <div style="clear:both;">
  57. <div style="float:left;" class="notes">
  58. Click on a data point in the chart to see the scatter plot results for that specific test.<br>
  59. Highlight an area of the chart to zoom in on that area and double-click to zoom out.
  60. <?php
  61. if (isset($info) && array_key_exists('notes', $info)) {
  62. echo '<br>';
  63. echo $info['notes'];
  64. }
  65. ?>
  66. </div>
  67. <div style="float: right;">
  68. <form name="aggregation" method="get" action="view.php">
  69. <?php
  70. echo "<input type=\"hidden\" name=\"benchmark\" value=\"$benchmark\">";
  71. ?>
  72. Aggregation <select name="aggregate" size="1" onchange="this.form.submit();">
  73. <option value="avg" <?php if ($aggregate == 'avg') echo "selected"; ?>>Average</option>
  74. <option value="geo-mean" <?php if ($aggregate == 'geo-mean') echo "selected"; ?>>Geometric Mean</option>
  75. <option value="median" <?php if ($aggregate == 'median') echo "selected"; ?>>Median</option>
  76. <option value="75pct" <?php if ($aggregate == '75pct') echo "selected"; ?>>75th Percentile</option>
  77. <option value="95pct" <?php if ($aggregate == '95pct') echo "selected"; ?>>95th Percentile</option>
  78. <option value="count" <?php if ($aggregate == 'count') echo "selected"; ?>>Count</option>
  79. </select>
  80. <br>
  81. Time Period <select name="days" size="1" onchange="this.form.submit();">
  82. <option value="7" <?php if ($days == 7) echo "selected"; ?>>Week</option>
  83. <option value="31" <?php if ($days == 31) echo "selected"; ?>>Month</option>
  84. <option value="93" <?php if ($days == 93) echo "selected"; ?>>3 Months</option>
  85. <option value="183" <?php if ($days == 183) echo "selected"; ?>>6 Months</option>
  86. <option value="366" <?php if ($days == 366) echo "selected"; ?>>Year</option>
  87. <option value="all" <?php if ($days == 0) echo "selected"; ?>>All</option>
  88. </select>
  89. </form>
  90. </div>
  91. </div>
  92. <div style="clear:both;">
  93. </div>
  94. <script type="text/javascript">
  95. function SelectedPoint(benchmark, metric, series, time, cached) {
  96. time = parseInt(time / 1000, 10);
  97. var isCached = 0;
  98. if (cached)
  99. isCached = 1;
  100. var menu = '<div><h4>View details:</h4>';
  101. var scatter = "viewtest.php?benchmark=" + encodeURIComponent(benchmark) + "&metric=" + encodeURIComponent(metric) + "&cached=" + isCached + "&time=" + time;
  102. var delta = "delta.php?benchmark=" + encodeURIComponent(benchmark) + "&metric=" + encodeURIComponent(metric) + "&time=" + time;
  103. menu += '<a href="' + scatter + '">Scatter Plot</a><br>';
  104. menu += '<a href="' + delta + '">Comparison Distribution</a><br>';
  105. menu += '</div>';
  106. $.modal(menu, {overlayClose:true});
  107. }
  108. </script>
  109. <?php
  110. }
  111. $metrics = array('docTime' => 'Load Time (onload)',
  112. 'SpeedIndex' => 'Speed Index',
  113. 'SpeedIndexDT' => 'Speed Index (Dev Tools)',
  114. 'TTFB' => 'Time to First Byte',
  115. 'titleTime' => 'Time to Title',
  116. 'render' => 'Time to Start Render',
  117. 'visualComplete' => 'Time to Visually Complete',
  118. 'VisuallyCompleteDT' => 'Time to Visually Complete (Dev Tools)',
  119. 'fullyLoaded' => 'Load Time (Fully Loaded)',
  120. 'server_rtt' => 'Estimated RTT to Server',
  121. 'domElements' => 'Number of DOM Elements',
  122. 'connections' => 'Connections',
  123. 'requests' => 'Requests (Fully Loaded)',
  124. 'requestsDoc' => 'Requests (onload)',
  125. 'bytesInDoc' => 'Bytes In (KB - onload)',
  126. 'bytesIn' => 'Bytes In (KB - Fully Loaded)',
  127. 'js_bytes' => 'Javascript Bytes (KB)',
  128. 'js_requests' => 'Javascript Requests',
  129. 'css_bytes' => 'CSS Bytes (KB)',
  130. 'css_requests' => 'CSS Requests',
  131. 'image_bytes' => 'Image Bytes (KB)',
  132. 'image_requests' => 'Image Requests',
  133. 'flash_bytes' => 'Flash Bytes (KB)',
  134. 'flash_requests' => 'Flash Requests',
  135. 'html_bytes' => 'HTML Bytes (KB)',
  136. 'html_requests' => 'HTML Requests',
  137. 'text_bytes' => 'Text Bytes (KB)',
  138. 'text_requests' => 'Text Requests',
  139. 'other_bytes' => 'Other Bytes (KB)',
  140. 'other_requests' => 'Other Requests',
  141. 'browser_version' => 'Browser Version');
  142. // 'responses_404' => 'Not Found Responses (404)',
  143. // 'responses_other' => 'Non-404 Error Responses');
  144. if (isset($info)) {
  145. if (!$info['video']) {
  146. unset($metrics['SpeedIndex']);
  147. }
  148. if (!isset($out_data)) {
  149. echo "<h1>{$info['title']}</h1>";
  150. if (array_key_exists('description', $info))
  151. echo "<p>{$info['description']}</p>\n";
  152. }
  153. foreach( $metrics as $metric => $label) {
  154. if (!isset($out_data)) {
  155. echo "<h2>$label <span class=\"small\">(<a name=\"$metric\" href=\"#$metric\">direct link</a>)</span></h2>\n";
  156. }
  157. if ($info['expand'] && count($info['locations'] > 1)) {
  158. foreach ($info['locations'] as $location => $label) {
  159. if (is_numeric($label))
  160. $label = $location;
  161. DisplayBenchmarkData($info, $metric, $location, $label);
  162. }
  163. } else {
  164. DisplayBenchmarkData($info, $metric);
  165. }
  166. }
  167. }
  168. if (!isset($out_data)) {
  169. ?>
  170. </div>
  171. <?php include('footer.inc'); ?>
  172. </div>
  173. </body>
  174. </html>
  175. <?php
  176. } else {
  177. // spit out the raw data
  178. header ("Content-type: application/json; charset=utf-8");
  179. echo json_encode($out_data);
  180. }
  181. /**
  182. * Display the charts for the given benchmark/metric
  183. *
  184. * @param mixed $benchmark
  185. */
  186. function DisplayBenchmarkData(&$benchmark, $metric, $loc = null, $title = null) {
  187. global $count;
  188. global $aggregate;
  189. global $out_data;
  190. $chart_title = '';
  191. if (isset($title))
  192. $chart_title = "title: \"$title (First View)\",";
  193. $bmname = $benchmark['name'];
  194. if (isset($loc)) {
  195. $bmname .= ".$loc";
  196. }
  197. $tsv = LoadDataTSV($benchmark['name'], 0, $metric, $aggregate, $loc, $annotations);
  198. if (isset($out_data)) {
  199. if (!array_key_exists($bmname, $out_data)) {
  200. $out_data[$bmname] = array();
  201. }
  202. $out_data[$bmname][$metric] = array();
  203. $out_data[$bmname][$metric]['FV'] = TSVEncode($tsv);
  204. }
  205. if (!isset($out_data) && isset($tsv) && strlen($tsv)) {
  206. $count++;
  207. $id = "g$count";
  208. echo "<div class=\"chart-container\"><div id=\"$id\" class=\"benchmark-chart\"></div><div id=\"{$id}_legend\" class=\"benchmark-legend\"></div></div><br>\n";
  209. echo "<script type=\"text/javascript\">
  210. $id = new Dygraph(
  211. document.getElementById(\"$id\"),
  212. \"" . str_replace("\t", '\t', str_replace("\n", '\n', $tsv)) . "\",
  213. {drawPoints: true,
  214. rollPeriod: 1,
  215. showRoller: true,
  216. labelsSeparateLines: true,
  217. labelsDiv: document.getElementById('{$id}_legend'),
  218. pointClickCallback: function(e, p) {SelectedPoint(\"{$benchmark['name']}\", \"$metric\", p.name, p.xval, false);},
  219. $chart_title
  220. legend: \"always\"}
  221. );";
  222. if (isset($annotations) && count($annotations)) {
  223. echo "$id.setAnnotations(" . json_encode($annotations) . ");\n";
  224. }
  225. echo "</script>\n";
  226. }
  227. if (!array_key_exists('fvonly', $benchmark) || !$benchmark['fvonly']) {
  228. if (isset($title))
  229. $chart_title = "title: \"$title (Repeat View)\",";
  230. $tsv = LoadDataTSV($benchmark['name'], 1, $metric, $aggregate, $loc, $annotations);
  231. if (isset($out_data)) {
  232. $out_data[$bmname][$metric]['RV'] = TSVEncode($tsv);
  233. }
  234. if (!isset($out_data) && isset($tsv) && strlen($tsv)) {
  235. $count++;
  236. $id = "g$count";
  237. echo "<br><div class=\"chart-container\"><div id=\"$id\" class=\"benchmark-chart\"></div><div id=\"{$id}_legend\" class=\"benchmark-legend\"></div></div>\n";
  238. echo "<script type=\"text/javascript\">
  239. $id = new Dygraph(
  240. document.getElementById(\"$id\"),
  241. \"" . str_replace("\t", '\t', str_replace("\n", '\n', $tsv)) . "\",
  242. {drawPoints: true,
  243. rollPeriod: 1,
  244. showRoller: true,
  245. labelsSeparateLines: true,
  246. labelsDiv: document.getElementById('{$id}_legend'),
  247. pointClickCallback: function(e, p) {SelectedPoint(\"{$benchmark['name']}\", \"$metric\", p.name, p.xval, true);},
  248. $chart_title
  249. legend: \"always\"}
  250. );";
  251. if (isset($annotations) && count($annotations)) {
  252. echo "$id.setAnnotations(" . json_encode($annotations) . ");\n";
  253. }
  254. echo "</script>\n";
  255. }
  256. }
  257. }
  258. ?>