forked from silexlabs/amfphp-2.0
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ABTester.php
297 lines (238 loc) · 11.7 KB
/
ABTester.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
<?php
/**
* This file is part of amfPHP
*
* LICENSE
*
* This source file is subject to the license that is bundled
* with this package in the file license.txt.
*
* note: It would be nice to have logarithmic time rendering, but this doesn't seem to work nicely with horizontal graphs
* @package Amfphp_BackOffice_Profiler
*
*/
/**
* includes
*/
require_once(dirname(__FILE__) . '/ClassLoader.php');
$accessManager = new Amfphp_BackOffice_AccessManager();
$isAccessGranted = $accessManager->isAccessGranted();
$config = new Amfphp_BackOffice_Config();
?>
<html>
<title>Amfphp Back Office - A/B Tester</title>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="css/jquery.jqplot.css" />
<link rel="stylesheet" type="text/css" href="css/style.css" />
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery.cookie.js"></script>
<script type="text/javascript" src="js/amfphp_updates.js"></script>
<!--[if IE]><script language="javascript" type="text/javascript" src="js/excanvas.min.js"></script><![endif]-->
<script language="javascript" type="text/javascript" src="js/jquery.jqplot.js"></script>
<script language="javascript" type="text/javascript" src="js/jqplot.barRenderer.js"></script>
<script language="javascript" type="text/javascript" src="js/jqplot.categoryAxisRenderer.js"></script>
<script language="javascript" type="text/javascript" src="js/jqplot.enhancedLegendRenderer.js"></script>
<script language="javascript" type="text/javascript" src="js/jqplot.pointLabels.js"></script>
<script type="text/javascript" src="js/swfobject.js"></script>
<script type="text/javascript" src="js/services.js"></script>
<script type="text/javascript" src="js/performanceCharting.js"></script>
<script type="text/javascript">
<?php
echo 'var amfphpVersion = "' . AMFPHP_VERSION . "\";\n";
echo 'var amfphpEntryPointUrlA = "' . $config->resolveAmfphpEntryPointUrl() . "\";\n";
if ($config->fetchAmfphpUpdates) {
echo "var shouldFetchUpdates = true;\n";
} else {
echo "var shouldFetchUpdates = false;\n";
}
?>
var amfphpEntryPointUrlB = amfphpEntryPointUrlA + '/with_BaguetteAMF.php';
var serviceMethodUri = "TestService/returnLargeDataSet";
var titleChartA = "Without Baguette AMF(ms)";
var titleChartB = "With Baguette AMF(ms)";
</script>
</head>
<body>
<div class="page-wrap">
<?php
require_once(dirname(__FILE__) . '/Header.inc.php');
?>
<div id='main' >
<?php
if (!$isAccessGranted) {
?>
<script>
window.location = './SignIn.php';
</script>
<?php
return;
}
?>
<div id="performanceDisplay">
<div id="chartDivContainer">
<div id="chartDiv">
<h2 style="padding-top: 150px; text-align: center">Hit Run Test Below to try Baguette AMF</h2>
<img style="margin-left: 500px; padding-top: 100px" src="img/DownArrow.png"></img>
</div>
</div>
<div id="controls">
Choose a number of objects to generate and serialize on the server
<input value="1000" id="numObjectsInput"></input>
<input type="submit" id="runTest" value="Run Test" onclick="runTestClickHandler()"></input>
<div id="statusMessage" class="warning"> </div>
</div>
<div id="amfCallerContainer">
Flash Player is needed to make AMF calls.
<a target="_blank" href="http://www.adobe.com/go/getflashplayer">
<img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
</a>
</div>
</div>
</div>
</div>
<?php
require_once(dirname(__FILE__) . '/Footer.inc.php');
?>
<script>
/**
* the chart
* */
var plot;
/**
* reference to amf caller, set once it is loaded. Used to make AMF calls.
* */
var amfCaller;
/**
* number of generated objects
* */
var numObjects;
$(function () {
//formatting code to embed in an iframe
$("#line1").hide();
$("#line2").hide();
$("#line3").hide();
$("footer").hide();
$("#main").css("width", "100%");
var availableHeight = $( "body" ).height() - $("#chartDiv").offset().top - 100;
$( "#chartDiv" ).css( "height", (availableHeight) + "px" );
var flashvars = {};
var params = {};
params.allowscriptaccess = "sameDomain";
var attributes = {};
attributes.id = "amfCaller";
swfobject.embedSWF("AmfCaller.swf", "amfCallerContainer", "0", "0", "9.0.0", false, flashvars, params, attributes, function (e) {
if(e.success){
amfCaller = e.ref;
}else{
displayStatusMessage("could not load AMF Caller.");
if(console){
console.log(e);
}
}
});
amfphp.entryPointUrl = amfphpEntryPointUrlA + "?contentType=application/json";
});
function displayStatusMessage(html){
$('#statusMessage').html(html);
}
function showErrorMessage(errorMsg){
errorMsg += "<br/>Once you have some data, this is what you should see : ";
displayStatusMessage(errorMsg);
$("#profilerImg").show();
$("#chartDivContainer").hide();
}
/**
* called by amf caller when ready
*/
function onAmfCallerLoaded(){
//don't run test on load, wait for user
//runTest();
}
function runTestClickHandler(){
runTest();
}
/**
* flush, make call then load performance data for A, then B
*/
function runTest(){
if(!amfCaller || !amfCaller.isAlive()){
alert('AMF Caller not available.');
return;
}
numObjects = parseInt($("#numObjectsInput").val());
if(isNaN(numObjects)){
alert("Invalid Number of generated objects.");
$("#numObjectsInput").val(1000);
return;
}
if(numObjects <= 0){
alert('Please enter a strictly positive number of objects to generate');
return;
}
if(numObjects > 3000){
alert('The number of generated objects is limited in this demo to 3000.');
return;
}
displayStatusMessage("Running Test...<br/> Generating and returning " + numObjects + " random objects with and without Baguette AMF");
amfphp.services.AmfphpMonitorService.flush(makeCallA, onServerError);
}
function makeCallA(){
amfCaller.call(amfphpEntryPointUrlA, serviceMethodUri, [numObjects], 'makeCallB');
}
function makeCallB(){
amfCaller.call(amfphpEntryPointUrlB, serviceMethodUri, [numObjects], 'loadPerformanceData');
}
function loadPerformanceData(){
amfphp.services.AmfphpMonitorService.getData(showPerformanceData, onServerError, false);
}
/**
* callback for when performance data loaded from server .
* generates graph with consolidated data
*/
function showPerformanceData(data)
{
if(data.sortedData.length == 0){
showErrorMessage("No data was available. Please make a service call then runTest. This can be done with the <a href='ServiceBrowser.php'>Service Browser</a>.");
return;
}
if(plot){
plot.destroy();
}
displayStatusMessage('');
var seriesData = [];
var orderedTimeNames = [];
var ticks = [];
//data for each target uri
var rawUriData = data.sortedData[serviceMethodUri];
var i = 0;
//look at data for each time
for(var timeName in rawUriData){
var timeData = rawUriData[timeName];
timeData = timeData.slice(0, 20);
orderedTimeNames.push(timeName);
seriesData.push(timeData.reverse());
}
ticks.push(titleChartB);
ticks.push(titleChartA);
plot = buildChart("chartDiv", seriesData, ticks, getLegendLabels(orderedTimeNames), "Comparative Test with " + numObjects + " objects. Values in Milliseconds(ms)", getSeriesColors(orderedTimeNames));
var serializationData = data.sortedData[serviceMethodUri].Serialization;
displayStatusMessage("It took " + serializationData[0] + " ms to serialize " + numObjects + " random objects without Baguette AMF, and " + serializationData[1] + " ms with Baguette AMF.");
}
function onServerError(jqXHR, textStatus ){
var responseText = jqXHR.responseText;
if(responseText.indexOf("AmfphpMonitorService service not found") != -1){
showErrorMessage("The AmfphpMonitorService could not be called. This is most likely because AmfphpMonitor plugin is not enabled. See the <a href='http://www.silexlabs.org/amfphp/documentation/using-the-back-office/profiler/'>documentation</a>.");
return;
}
var errorMessagePos = responseText.indexOf("AmfphpMonitor does not have permission to read and write");
if(errorMessagePos != -1){
var filePathStart = responseText.indexOf("log file: ", errorMessagePos) + 10;
var filePathStop = responseText.indexOf("'", filePathStart);
var filePath = responseText.substring(filePathStart, filePathStop);
showErrorMessage("Could not read or write log file. Please check your webserver has read and write permissions on <br/>" + filePath);
return;
}
showErrorMessage(textStatus + "<br/><br/>" + jqXHR.responseText);
}
</script>