This repository has been archived by the owner on Oct 8, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
simple performance recording for page loads
- Loading branch information
1 parent
cdf1d2c
commit b5d6322
Showing
5 changed files
with
117 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,4 @@ gitstatus.log | |
refreshCDN | ||
*.swp | ||
.gitignore | ||
tests/speed/stats/stats.db |
21 changes: 11 additions & 10 deletions
21
tests/speed/lists-ul.html → tests/speed/lists-ul.php
100755 → 100644
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
$db = new SQLiteDatabase('stats.db'); | ||
|
||
// hand to God I tried CREATE TABLE IF NOT EXISTS and it persisted with | ||
// a syntax error. The IDENTICAL query sans IF NOT EXISTS works perfectly | ||
// http://www.sqlite.org/lang_createtable.html | ||
@$db->query('CREATE TABLE stats (id INTEGER, agent TEXT, point TEXT, value REAL, PRIMARY KEY (id))'); | ||
|
||
// making a sad attempt here to provide a clean REST-respecting url scheme. | ||
// stats with a GET returns - wait for it - the stats, and a post with the | ||
// the right params will create a new entry | ||
if ( $_SERVER['REQUEST_METHOD'] == "GET" ) { | ||
$json = Array(); | ||
$results = $db->query( 'SELECT point, value FROM stats' ); | ||
|
||
// TODO not sure if there's a better way to convert db results into | ||
// a json encodable data structure | ||
while($row = $results->fetch(SQLITE3_ASSOC)){ | ||
array_push($json, $row); | ||
} | ||
|
||
header("Content-Type: application/json"); | ||
echo json_encode($json); | ||
} elseif ( $_POST['datapoint'] && $_POST['value'] && $_POST['agent'] ){ | ||
// TODO it is not clear from the docs if there's an easier way to do the | ||
// escaped query interpolation here. Suggestions welcome :( | ||
$data_point = sqlite_escape_string( $_POST['datapoint'] ); | ||
$value = sqlite_escape_string( $_POST['value'] ); | ||
$agent = sqlite_escape_string( $_POST['agent'] ); | ||
$db->query('INSERT INTO stats (agent, point, value) VALUES ("' . $agent . '", "' . $data_point . '",' . $value . ')'); | ||
|
||
echo "success"; | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
window.Perf = (function($, Perf) { | ||
$.extend(Perf, { | ||
reportUrl: 'stats/', | ||
revUrl: 'stats/rev.php', | ||
|
||
// should be defined before report or poll are run | ||
currentRev: undefined, | ||
|
||
report: function( data, after ) { | ||
var self = this; | ||
|
||
$.post( self.reportUrl, data, after ); | ||
}, | ||
|
||
poll: function() { | ||
var self = this; | ||
|
||
setInterval(function() { | ||
$.get( self.revUrl, function( data ) { | ||
|
||
// if there's a new revision refresh or currentRev isn't being set | ||
if( self.currentRev && self.currentRev !== data ){ | ||
location.href = location.href; | ||
} | ||
}); | ||
}, 60000); | ||
}, | ||
|
||
setCurrentRev: function() { | ||
var self = this; | ||
|
||
$.get( self.revUrl, function( data ) { | ||
self.currentRev = data; | ||
}); | ||
} | ||
}); | ||
|
||
var $listPage = $( "#list-page" ); | ||
|
||
Perf.setCurrentRev(); | ||
Perf.pageLoadStart = Date.now(); | ||
|
||
$listPage.live( "pagebeforecreate", function() { | ||
Perf.pageCreateStart = Date.now(); | ||
}); | ||
|
||
$listPage.live( "pageinit", function(){ | ||
Perf.pageLoadEnd = Date.now(); | ||
|
||
// report the time taken for a full app boot | ||
Perf.report({ | ||
agent: window.navigator.userAgent, | ||
datapoint: "fullboot", | ||
value: Perf.pageLoadEnd - Perf.pageLoadStart | ||
}); | ||
|
||
// record the time taken to load and enhance the page | ||
// start polling for a new revision | ||
Perf.report({ | ||
agent: window.navigator.userAgent, | ||
datapoint: "pageload", | ||
value: Perf.pageCreateStart - Perf.pageLoadStart, | ||
after: function() { | ||
Perf.poll(); | ||
} | ||
}); | ||
}); | ||
|
||
return Perf; | ||
})(jQuery, window.Perf || {}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<?php echo exec('git rev-parse HEAD') ?> |