PageRenderTime 82ms CodeModel.GetById 40ms app.highlight 7ms RepoModel.GetById 33ms app.codeStats 0ms

/details/data_dynatrace.php

http://showslow.googlecode.com/
PHP | 137 lines | 117 code | 20 blank | 0 comment | 22 complexity | 5f075fc0f19777b5b09f4d6cb3350cfe MD5 | raw file
  1<?php 
  2require_once(dirname(dirname(__FILE__)).'/global.php');
  3
  4if (!array_key_exists('url', $_GET) || filter_var($_GET['url'], FILTER_VALIDATE_URL) === false) {
  5	header('HTTP/1.0 400 Bad Request');
  6
  7	?><html>
  8<head>
  9<title>Bad Request: no valid url specified</title>
 10</head>
 11<body>
 12<h1>Bad Request: no valid url specified</h1>
 13<p>You must pass valid URL as 'url' parameter</p>
 14</body></html>
 15<?php 
 16	exit;
 17}
 18
 19$query = sprintf("SELECT id FROM urls WHERE urls.url = '%s'", mysql_real_escape_string($_GET['url']));
 20$result = mysql_query($query);
 21
 22if (!$result) {
 23	error_log(mysql_error());
 24}
 25
 26$row = mysql_fetch_assoc($result);
 27$urlid = $row['id'];
 28mysql_free_result($result);
 29
 30if (array_key_exists('subset', $_REQUEST)) {
 31	if ($_REQUEST['subset'] == 'graph')
 32	{
 33		$query = sprintf("SELECT UNIX_TIMESTAMP(d.timestamp) as time, rank
 34			FROM dynatrace d WHERE d.url_id = %d AND d.timestamp > DATE_SUB(now(),INTERVAL 3 MONTH)
 35			ORDER BY d.timestamp DESC",
 36			mysql_real_escape_string($urlid)
 37		);
 38	}
 39	else if ($_REQUEST['subset'] == 'table')
 40	{
 41		$query = sprintf("SELECT UNIX_TIMESTAMP(d.timestamp) as time,
 42				pagesize, reqnumber, rank, timetoimpression
 43			FROM dynatrace d WHERE d.url_id = %d AND d.timestamp > DATE_SUB(now(),INTERVAL 3 MONTH)
 44			ORDER BY d.timestamp DESC",
 45			mysql_real_escape_string($urlid)
 46		);
 47	}
 48} else {
 49	$query = sprintf("SELECT UNIX_TIMESTAMP(d.timestamp) as time,
 50			rank, cache, net, server, js,
 51			timetoimpression, timetoonload, timetofullload,
 52			reqnumber, xhrnumber,
 53			pagesize, cachablesize, noncachablesize,
 54			timeonnetwork, timeinjs, timeinrendering
 55		FROM dynatrace d WHERE d.url_id = %d AND d.timestamp > DATE_SUB(now(),INTERVAL 3 MONTH)
 56		ORDER BY d.timestamp DESC",
 57		mysql_real_escape_string($urlid)
 58	);
 59}
 60
 61$result = mysql_query($query);
 62
 63if (!$result) {
 64        error_log(mysql_error());
 65}
 66
 67$data = array();
 68
 69header('Content-type: text/plain');
 70if (array_key_exists('ver', $_GET)) {
 71	header('Expires: '.date('r', time() + 315569260));
 72	header('Cache-control: max-age=315569260');
 73}
 74
 75$rows = array();
 76while ($row = mysql_fetch_assoc($result)) {
 77	$rows[] = $row;
 78}
 79
 80mysql_free_result($result);
 81
 82if (array_key_exists('smooth', $_REQUEST)) {
 83	require_once(dirname(__FILE__).'/smooth.php');
 84	smooth($rows, array('rank'));
 85}
 86
 87if (!array_key_exists('subset', $_REQUEST))
 88{
 89	header('Content-disposition: attachment;filename=dynatrace.csv');
 90
 91	echo '# Measurement time';
 92	echo ', Overall Page Rank (Percentage)';
 93	echo ', Caching Rank (Percentage)';
 94	echo ', Network Rank (Percentage)';
 95	echo ', Server-Side Rank (Percentage)';
 96	echo ', JavaScript Rank (Percentage)';
 97	echo ', Time to First Impression (ms)';
 98	echo ', Time to onLoad (ms)';
 99	echo ', Time to Full Page Load (ms)';
100	echo ', Number of Requests';
101	echo ', Number of XHR Requests';
102	echo ', Total Page Size (bytes)';
103	echo ', Total Cachable Size (bytes)';
104	echo ', Total Non-Cachable Size (bytes)';
105	echo ', Total Time on Network (ms)';
106	echo ', Total Time in JavaScript (ms)';
107	echo ', Total Time in Rendering (ms)';
108	echo "\n";
109}
110
111foreach ($rows as $row) {
112
113        echo date('c', $row['time']).',';
114
115	if (array_key_exists('subset', $_REQUEST)) {
116		if ($_REQUEST['subset'] == 'graph')
117		{
118			echo $row['rank'];
119		}
120		else if ($_REQUEST['subset'] == 'table')
121		{
122			echo	$row['pagesize'].','.
123				$row['reqnumber'].','.
124				$row['rank'].','.
125				$row['timetoimpression'];
126		}
127	} else {
128		echo $row['rank'].','.$row['cache'].','.$row['net'].','.$row['server'].','.$row['js'].','.
129		$row['timetoimpression'].','.$row['timetoonload'].','.$row['timetofullload'].','.
130		$row['reqnumber'].','.$row['xhrnumber'].','.
131		$row['pagesize'].','.$row['cachablesize'].','.$row['noncachablesize'].','.
132		$row['timeonnetwork'].','.$row['timeinjs'].','.$row['timeinrendering'];
133	}
134
135	echo "\n";
136}
137