2017-11-22 11:00:31 +03:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html lang="en">
|
2018-05-29 23:32:39 +03:00
|
|
|
|
2017-11-22 11:00:31 +03:00
|
|
|
<head>
|
|
|
|
<meta charset="UTF-8">
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
2017-12-30 05:15:12 +03:00
|
|
|
<title>speedscope</title>
|
2018-05-29 23:32:39 +03:00
|
|
|
<link href="https://fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet">
|
2018-04-05 10:15:42 +03:00
|
|
|
<script>
|
2018-05-29 23:32:39 +03:00
|
|
|
// https://github.com/evanw/webgl-recorder
|
|
|
|
false && (function () {
|
|
|
|
var getContext = HTMLCanvasElement.prototype.getContext;
|
|
|
|
var requestAnimationFrame = window.requestAnimationFrame;
|
|
|
|
var frameSincePageLoad = 0;
|
|
|
|
|
|
|
|
function countFrames() {
|
|
|
|
frameSincePageLoad++;
|
|
|
|
requestAnimationFrame(countFrames);
|
|
|
|
}
|
|
|
|
|
|
|
|
window.requestAnimationFrame = function () {
|
|
|
|
return requestAnimationFrame.apply(window, arguments);
|
2018-04-05 10:15:42 +03:00
|
|
|
};
|
|
|
|
|
2018-05-29 23:32:39 +03:00
|
|
|
HTMLCanvasElement.prototype.getContext = function (type) {
|
|
|
|
var canvas = this;
|
|
|
|
var context = getContext.apply(canvas, arguments);
|
|
|
|
|
|
|
|
if (type === 'webgl' || type === 'experimental-webgl') {
|
|
|
|
var oldWidth = canvas.width;
|
|
|
|
var oldHeight = canvas.height;
|
|
|
|
var oldFrameCount = frameSincePageLoad;
|
|
|
|
var trace = [];
|
|
|
|
var variables = {};
|
|
|
|
var fakeContext = {
|
|
|
|
trace: trace,
|
|
|
|
compileTrace: compileTrace,
|
|
|
|
downloadTrace: downloadTrace,
|
|
|
|
};
|
|
|
|
|
|
|
|
trace.push(' gl.canvas.width = ' + oldWidth + ';');
|
|
|
|
trace.push(' gl.canvas.height = ' + oldHeight + ';');
|
|
|
|
|
|
|
|
function compileTrace() {
|
|
|
|
var text = 'function* render(gl) {\n';
|
|
|
|
text += ' // Recorded using https://github.com/evanw/webgl-recorder\n';
|
|
|
|
for (var key in variables) {
|
|
|
|
text += ' var ' + key + 's = [];\n';
|
|
|
|
}
|
|
|
|
text += trace.join('\n');
|
|
|
|
text += '\n}\n';
|
|
|
|
return text;
|
|
|
|
}
|
2018-04-05 10:15:42 +03:00
|
|
|
|
2018-05-29 23:32:39 +03:00
|
|
|
function downloadTrace() {
|
|
|
|
var text = compileTrace();
|
|
|
|
var link = document.createElement('a');
|
|
|
|
link.href = URL.createObjectURL(new Blob([text], { type: 'application/javascript' }));
|
|
|
|
link.download = 'trace.js';
|
|
|
|
document.body.appendChild(link);
|
|
|
|
link.click();
|
|
|
|
document.body.removeChild(link);
|
|
|
|
}
|
2018-04-05 10:15:42 +03:00
|
|
|
|
2018-05-29 23:32:39 +03:00
|
|
|
function getVariable(value) {
|
|
|
|
if (value instanceof WebGLActiveInfo ||
|
|
|
|
value instanceof WebGLBuffer ||
|
|
|
|
value instanceof WebGLFramebuffer ||
|
|
|
|
value instanceof WebGLProgram ||
|
|
|
|
value instanceof WebGLRenderbuffer ||
|
|
|
|
value instanceof WebGLShader ||
|
|
|
|
value instanceof WebGLShaderPrecisionFormat ||
|
|
|
|
value instanceof WebGLTexture ||
|
|
|
|
value instanceof WebGLUniformLocation) {
|
|
|
|
var name = value.constructor.name;
|
|
|
|
var list = variables[name] || (variables[name] = []);
|
|
|
|
var index = list.indexOf(value);
|
|
|
|
|
|
|
|
if (index === -1) {
|
|
|
|
index = list.length;
|
|
|
|
list.push(value);
|
|
|
|
}
|
2018-04-05 10:15:42 +03:00
|
|
|
|
2018-05-29 23:32:39 +03:00
|
|
|
return name + 's[' + index + ']';
|
|
|
|
}
|
2018-04-05 10:15:42 +03:00
|
|
|
|
2018-05-29 23:32:39 +03:00
|
|
|
return null;
|
|
|
|
}
|
2018-04-05 10:15:42 +03:00
|
|
|
|
2018-05-29 23:32:39 +03:00
|
|
|
console.timeStamp('start')
|
|
|
|
var start = performance.now()
|
|
|
|
for (var key in context) {
|
|
|
|
var value = context[key];
|
|
|
|
|
|
|
|
if (typeof value === 'function') {
|
|
|
|
fakeContext[key] = function (key, value) {
|
|
|
|
return function () {
|
|
|
|
trace.push(`// ${performance.now() - start}`)
|
|
|
|
var result = value.apply(context, arguments);
|
|
|
|
var args = [];
|
|
|
|
|
|
|
|
if (frameSincePageLoad !== oldFrameCount) {
|
|
|
|
oldFrameCount = frameSincePageLoad;
|
|
|
|
trace.push(' yield;');
|
|
|
|
}
|
2018-04-05 10:15:42 +03:00
|
|
|
|
2018-05-29 23:32:39 +03:00
|
|
|
if (canvas.width !== oldWidth || canvas.height !== oldHeight) {
|
|
|
|
oldWidth = canvas.width;
|
|
|
|
oldHeight = canvas.height;
|
|
|
|
trace.push(' gl.canvas.width = ' + oldWidth + ';');
|
|
|
|
trace.push(' gl.canvas.height = ' + oldHeight + ';');
|
|
|
|
}
|
2018-04-05 10:15:42 +03:00
|
|
|
|
2018-05-29 23:32:39 +03:00
|
|
|
for (var i = 0; i < arguments.length; i++) {
|
|
|
|
var arg = arguments[i];
|
2018-04-05 10:15:42 +03:00
|
|
|
|
2018-05-29 23:32:39 +03:00
|
|
|
if (typeof arg === 'number' || typeof arg === 'boolean' || typeof arg === 'string' || arg === null) {
|
|
|
|
args.push(JSON.stringify(arg));
|
|
|
|
}
|
2018-04-05 10:15:42 +03:00
|
|
|
|
2018-05-29 23:32:39 +03:00
|
|
|
else if (ArrayBuffer.isView(arg)) {
|
|
|
|
args.push('new ' + arg.constructor.name + '([' + Array.prototype.slice.call(arg) + '])');
|
|
|
|
}
|
2018-04-05 10:15:42 +03:00
|
|
|
|
2018-05-29 23:32:39 +03:00
|
|
|
else {
|
|
|
|
var variable = getVariable(arg);
|
|
|
|
if (variable !== null) {
|
|
|
|
args.push(variable);
|
|
|
|
}
|
2018-04-05 10:15:42 +03:00
|
|
|
|
2018-05-29 23:32:39 +03:00
|
|
|
else {
|
|
|
|
console.log('unsupported value:', arg);
|
|
|
|
args.push('null');
|
|
|
|
}
|
|
|
|
}
|
2018-04-05 10:15:42 +03:00
|
|
|
}
|
|
|
|
|
2018-05-29 23:32:39 +03:00
|
|
|
var text = 'gl.' + key + '(' + args.join(', ') + ');';
|
|
|
|
var variable = getVariable(result);
|
|
|
|
if (variable !== null) text = variable + ' = ' + text;
|
|
|
|
trace.push(' ' + text);
|
2018-04-05 10:15:42 +03:00
|
|
|
|
2018-05-29 23:32:39 +03:00
|
|
|
return result;
|
|
|
|
};
|
|
|
|
}(key, value);
|
|
|
|
}
|
2018-04-05 10:15:42 +03:00
|
|
|
|
2018-05-29 23:32:39 +03:00
|
|
|
else {
|
|
|
|
fakeContext[key] = value;
|
|
|
|
}
|
|
|
|
}
|
2018-04-05 10:15:42 +03:00
|
|
|
|
2018-05-29 23:32:39 +03:00
|
|
|
return fakeContext;
|
2018-04-05 10:15:42 +03:00
|
|
|
}
|
|
|
|
|
2018-05-29 23:32:39 +03:00
|
|
|
return context;
|
|
|
|
};
|
2018-04-05 10:15:42 +03:00
|
|
|
|
2018-05-29 23:32:39 +03:00
|
|
|
countFrames();
|
|
|
|
})();
|
2018-04-05 10:15:42 +03:00
|
|
|
</script>
|
2018-05-29 23:32:39 +03:00
|
|
|
<link rel="stylesheet" href="reset.css">
|
2018-01-14 08:05:58 +03:00
|
|
|
<link rel="icon" type="image/png" sizes="32x32" href="favicon-32x32.png">
|
|
|
|
<link rel="icon" type="image/png" sizes="16x16" href="favicon-16x16.png">
|
2017-11-22 11:00:31 +03:00
|
|
|
</head>
|
2018-05-29 23:32:39 +03:00
|
|
|
|
2017-11-22 11:00:31 +03:00
|
|
|
<body>
|
2018-08-01 10:41:45 +03:00
|
|
|
<script src="../src/speedscope.tsx"></script>
|
2017-11-22 11:00:31 +03:00
|
|
|
</body>
|
2018-05-29 23:32:39 +03:00
|
|
|
|
|
|
|
</html>
|