Fix replayprofile/ graphing tool for Profiler1
All modern browsers block ajax request to local file. This changes extract.pl to generate a single HTML file with data embedded. This is now the default behaviour, --to-json to export, --from-json to load exported. Patch by: nwtour Reviewed By: wraitii Differential Revision: https://code.wildfiregames.com/D3621 This was SVN commit r24975.
This commit is contained in:
parent
23aa59e3d4
commit
5e5ea5cba5
@ -3,13 +3,21 @@
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Getopt::Long;
|
||||
use File::Basename qw(dirname);
|
||||
chdir(dirname(__FILE__));
|
||||
|
||||
# Run the game normally to generate a replay.
|
||||
# Run the non-visual replay like:
|
||||
# ./pyrogenesis -mod=public -replay=$HOME/.local/share/0ad/replays/0.0.23/2018-03-23_0010/commands.txt
|
||||
# to generate profile.txt.
|
||||
# Then run:
|
||||
# perl extract.pl > data.json
|
||||
# then open graph.html.
|
||||
# perl extract.pl
|
||||
# OR
|
||||
# perl extract.pl --to-json > data.json ... [manipulation with data.json] ... perl extract.pl --from-json
|
||||
# then open graph_onepage.html.
|
||||
|
||||
my ($to_json, $from_json); GetOptions ("to-json" => \$to_json, "from-json" => \$from_json);
|
||||
|
||||
open my $f, '../../../binaries/system/profile.txt' or die $!;
|
||||
my $turn = 0;
|
||||
@ -33,15 +41,55 @@ while (<$f>) {
|
||||
}
|
||||
}
|
||||
|
||||
print "[\n";
|
||||
my $json = "[\n";
|
||||
my $n = 0;
|
||||
for my $k (sort keys %s) {
|
||||
print ",\n" if $n++;
|
||||
print "{label: '$k', data:[";
|
||||
$json .= ",\n" if $n++;
|
||||
$json .= "{label: '$k', data:[";
|
||||
for my $t (0..$#{$s{$k}}) {
|
||||
print "," if $t;
|
||||
print "[$t,".($s{$k}[$t] || 0)."]";
|
||||
$json .= "," if $t;
|
||||
$json .= "[$t,".($s{$k}[$t] || 0)."]";
|
||||
}
|
||||
print "]}";
|
||||
$json .= "]}";
|
||||
}
|
||||
print "\n]\n";
|
||||
$json .= "\n]\n";
|
||||
|
||||
my $onepage = "graph_onepage.html";
|
||||
|
||||
sub recursive_file_slurp {
|
||||
my $filename = shift;
|
||||
my $output = '';
|
||||
open my $fd, $filename or die "Open $filename : $!";
|
||||
$output .= "<script>\n" if $filename =~ /\.js$/;
|
||||
while(<$fd>){
|
||||
if(/-- include js --/) {
|
||||
$output .= recursive_file_slurp("jquery.js");
|
||||
$output .= recursive_file_slurp("jquery.flot.js");
|
||||
$output .= recursive_file_slurp("jquery.flot.navigate.js");
|
||||
}
|
||||
elsif(/-- include graph js --/) {
|
||||
$output .= recursive_file_slurp("graph.js");
|
||||
}
|
||||
elsif(/-- include data json --/) {
|
||||
$output .= $json;
|
||||
}
|
||||
else {
|
||||
$output .= $_;
|
||||
}
|
||||
}
|
||||
$output .= "</script>\n" if $filename =~ /\.js$/;
|
||||
close($fd);
|
||||
return $output;
|
||||
}
|
||||
|
||||
if($to_json) {
|
||||
print $json;
|
||||
exit;
|
||||
}
|
||||
elsif($from_json) {
|
||||
$json = recursive_file_slurp("data.json");
|
||||
}
|
||||
|
||||
open my $opfd, '>', $onepage or die $!;
|
||||
print $opfd recursive_file_slurp("graph.html");
|
||||
close($opfd);
|
||||
|
@ -3,16 +3,11 @@
|
||||
<head>
|
||||
<meta charset="UTF-8"/>
|
||||
<title>0 A.D. Simulation Profiling</title>
|
||||
<script src="jquery.js"></script>
|
||||
<script src="jquery.flot.js"></script>
|
||||
<script src="jquery.flot.navigate.js"></script>
|
||||
<script src="graph.js"></script>
|
||||
<!-- include js -->
|
||||
<!-- include graph js -->
|
||||
</head>
|
||||
<body>
|
||||
<body onload="showReplayData();">
|
||||
<div>
|
||||
<label>File:
|
||||
<input type="text" id="filename" value="data.json" onKeyUp="loadReplayGraphData()"></input>
|
||||
</label>
|
||||
<label>Graph:
|
||||
<select id="replayGraphSelection" size="1" onChange="showReplayData()">
|
||||
<option value="time" selected="selected">Performance</option>
|
||||
@ -21,7 +16,6 @@
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
<div id="errorMsg">File does not exist!</div>
|
||||
<div id="replayGraphContainer">
|
||||
<div id="replayGraphLegend" style="width:300px;float:left"></div>
|
||||
<div>
|
||||
|
@ -50,6 +50,7 @@ var graphFormat = {
|
||||
|
||||
function showReplayData()
|
||||
{
|
||||
loadReplayGraphData();
|
||||
var displayedColumn = $("#replayGraphSelection").val();
|
||||
|
||||
$.plot($("#replayGraph"), getReplayGraphData(displayedColumn), {
|
||||
@ -137,20 +138,8 @@ function showTooltip(x, y, displayedColumn, label, turn, value)
|
||||
|
||||
function loadReplayGraphData()
|
||||
{
|
||||
$.ajax({
|
||||
"dataType": "json",
|
||||
"url": $("#filename").val(),
|
||||
"success": function(data) {
|
||||
$("#errorMsg").hide();
|
||||
$("#replayGraphContainer").show();
|
||||
replayData = data;
|
||||
showReplayData();
|
||||
},
|
||||
"error": function() {
|
||||
$("#replayGraphContainer").hide();
|
||||
$("#errorMsg").show();
|
||||
}
|
||||
});
|
||||
replayData =
|
||||
<!-- include data json -->
|
||||
}
|
||||
|
||||
$(loadReplayGraphData);
|
||||
|
Loading…
Reference in New Issue
Block a user