Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Replace local copy of Measviz with submodule.

  • Loading branch information...
commit aad9e63205bcab0700b3183bc6a10b9e521b1b45 1 parent 4938b1c
@kpreid authored
View
3  .gitmodules
@@ -10,3 +10,6 @@
[submodule "deps/jshint"]
path = deps/jshint
url = git://github.com/jshint/jshint.git
+[submodule "deps/measviz"]
+ path = deps/measviz
+ url = git://github.com/kpreid/measviz.git
1  deps/measviz
@@ -0,0 +1 @@
+Subproject commit 182f0ef3c45b30b72d7240efd7a2301efcd89f38
View
122 deps/measviz/demo/testbed.html
@@ -1,122 +0,0 @@
-<!doctype html>
-<!--
- Except as noted,
- Copyright 2011-2012 Kevin Reid under the terms of the MIT License as detailed
- in the accompanying file README.md or <http://opensource.org/licenses/MIT>.
--->
-<html><head>
- <title>Cubes Measuring Testbed</title>
- <meta http-equiv="content-type" content="text/html; charset=UTF-8">
- <meta name="viewport" content="width=device-width">
- <link rel="stylesheet" href="../src/measviz.css" type="text/css">
-
- <script type="text/javascript" src="../../../deps/gl-matrix/gl-matrix.js"></script>
- <script type="text/javascript" src="../../../deps/game-shim/game-shim.js"></script>
- <script type="text/javascript" src="../../../module-initial.js"></script>
- <script type="text/javascript" src="../../../util.js"></script>
- <script type="text/javascript" src="../../../storage.js"></script>
- <script type="text/javascript" src="../src/measviz.js"></script>
-</head>
-<body>
-
-<script type="text/javascript">
-
- var TopGroup = measviz.TopGroup;
- var ViewGroup = measviz.ViewGroup;
- var TaskGroup = measviz.TaskGroup;
- var Counter = measviz.Counter;
-
- // TODO: Make up a demo-relevant example
- var measuring = {};
- measuring.all = new TopGroup("Performance", [
- measuring.second = new ViewGroup("Per second", [
- measuring.simCount = new Counter("Steps"),
- measuring.frameCount = new Counter("Frames"),
- measuring.chunkCount = new Counter("Chunk calcs"),
- measuring.lightUpdateCount = new Counter("Light updates")
- ]),
- measuring.sim = new TaskGroup("Simulation", [
- measuring.collisionTests = new Counter("Collision tests"),
- measuring.blockEvals = new Counter("Block evals")
- ]),
- measuring.chunk = new TaskGroup("Chunk calc", []),
- measuring.frame = new TaskGroup("Frame", [
- measuring.bundles = new Counter("Bundles"),
- measuring.vertices = new Counter("Vertices")
- ]),
- measuring.queues = new ViewGroup("Queue sizes", [
- measuring.chunkQueueSize = new Counter("Chunks"),
- measuring.lightingQueueSize = new Counter("Lights"),
- measuring.persistenceQueueSize = new Counter("Dirty objs")
- ])
- ]);
-
-
- // Fast callbacks
- // Source: http://dbaron.org/log/20100309-faster-timeouts
- (function() {
- var timeouts = [];
- var messageName = "zero-timeout-message";
-
- // Like setTimeout, but only takes a function argument. There's
- // no time argument (always zero) and no arguments (you have to
- // use a closure).
- function setZeroTimeout(fn) {
- timeouts.push(fn);
- window.postMessage(messageName, "*");
- }
-
- function handleMessage(event) {
- if (event.source == window && event.data == messageName) {
- event.stopPropagation();
- if (timeouts.length > 0) {
- var fn = timeouts.shift();
- fn();
- }
- }
- }
-
- window.addEventListener("message", handleMessage, true);
-
- // Add the one thing we want added to the window object.
- window.setZeroTimeout = setZeroTimeout;
- })();
-
-
- var measureDisplay = measuring.all.createDisplay(document, "cubes.measurement-ui");
-
- document.body.appendChild(measureDisplay.element);
-
- measuring.second.start();
- setInterval(function () {
- measuring.second.end();
- measuring.second.start();
- if (measureDisplay) measureDisplay.updateIfVisible();
- }, 1000);
-
- function loop() {
- measuring.frameCount.inc(); // count overall performance
-
- // fake some data
- measuring.frame.start();
- measuring.bundles.inc(Math.floor((Math.sin(Date.now()) + 1) * 1000));
-
- // update everything
- measuring.sim.start();
- measuring.sim.end();
- measuring.chunk.start();
- measuring.chunk.end();
- measuring.queues.start();
- measuring.queues.end();
-
- measureDisplay.updateIfVisible();
- setZeroTimeout(loop);
-
- measuring.frame.end();
- }
- setZeroTimeout(loop);
-</script>
-
-<p>This file is designed to test the performance of Measviz, to ensure it does not place excessive load on that which it measures.</p>
-
-</body></html>
View
59 deps/measviz/src/measviz.css
@@ -1,59 +0,0 @@
-.measviz-item {
- display: table;
- font-family: "Geneva", "Verdana", sans-serif;
- font-size: 9px;
- color: white;
- white-space: nowrap; /* work around spurious wrap in ~ Chrome 22.0.1207.1 dev */
-
- pointer-events: none;
-
- /* root-only styles */
- background: black;
- background: rgba(80,80,80,0.5);
- padding: 3px;
-}
-.measviz-item .measviz-item {
- /* non-roots */
- padding: 0;
- background: none;
-}
-.measviz-label, .measviz-group-header {
- display: inline-block;
- min-width: 16ex;
- text-align: left;
-}
-.measviz-value {
- display: inline-block;
- min-width: 13ex;
- text-align: right;
-}
-.measviz-group-header {
- background: none;
- color: #CCC;
- font-weight: bold;
-}
-ul.measviz-group-contents, ol.measviz-group-contents {
- margin: 0 0 0 0;
- padding: 0 0 0 1em;
- list-style-type: none;
-}
-.measviz-sparkline {
- vertical-align: baseline;
-}
-.measviz-hide-sparklines .measviz-sparkline {
- display: none;
-}
-.measviz-toggle {
- /* reset <button> style */
- margin: 0;
- border: none;
- padding: 0;
- color: inherit;
- background: none;
- font: inherit;
-
- /* specific style */
- font-weight: bold;
-
- pointer-events: auto;
-}
View
288 deps/measviz/src/measviz.js
@@ -1,288 +0,0 @@
-// Copyright 2011-2012 Kevin Reid under the terms of the MIT License as detailed
-// in the accompanying file README.md or <http://opensource.org/licenses/MIT>.
-
-var measviz;
-(function () {
- "use strict";
-
- // --- Imports and utilities ---
-
- var max = Math.max;
- var min = Math.min;
-
- var classPrefix = "measviz-";
-
- function numberWithCommas(x) {
- // source: http://stackoverflow.com/a/2901298/99692
- return (+x).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
- }
-
- // Tests whether an element may be visible to the user.
- function elementIsVisible(element) {
- // Note: The offsetWidth test tests for display:none; it does not test for obscuration.
- return element.offsetWidth > 0;
- }
-
- // Helper for constructing DOM.
- function mkelement(name, classes/* , child, child, ... */) {
- var element = document.createElement(name);
- classes.forEach(function (c) {
- element.classList.add(classPrefix + c);
- })
- var i;
- for (i = 2; i < arguments.length; i++) {
- var childDes = arguments[i];
- if (typeof childDes === "string") {
- childDes = document.createTextNode(childDes);
- }
- element.appendChild(childDes);
- }
- return element;
- }
-
- // --- Implementation ---
-
- function createToggle(storageName, callback) {
- var toggleState = true;
- try {
- toggleState = !!JSON.parse(localStorage.getItem(storageName));
- } catch (e) {}
- var toggler = mkelement("button", ["toggle"]);
- function update() {
- if (toggleState) {
- toggler.textContent = "[−]" /* minus sign */;
- } else {
- toggler.textContent = "[+]";
- }
- callback(toggleState);
- return true;
- }
- update();
- toggler.addEventListener("click", function () {
- toggleState = !toggleState;
- try {
- localStorage.setItem(storageName, JSON.stringify(toggleState));
- } catch (e) {}
- update();
- return false;
- }, false);
- return toggler;
- }
-
- function ViewGroup(label, elements) {
- this.label = label;
- this.elements = elements;
- }
- ViewGroup.prototype.createDisplay = function (document, stateContext) {
- var subContext = stateContext + "." + this.label;
- var container = mkelement("div", ["item", "group"]);
- var list = mkelement("ul", ["group-contents"]);
- var header = null;
- if (this.label) {
- header = mkelement("div", ["group-header"],
- createToggle(subContext + ".visible", function (visible) {
- if (visible) {
- list.style.removeProperty("display");
- } else {
- list.style.display = "none";
- }
- }),
- document.createTextNode(" " + this.label)
- );
- container.appendChild(header);
- }
- container.appendChild(list);
- var updaters = [];
- this.elements.forEach(function (thing) {
- var subdisplay = thing.createDisplay(document, subContext);
- list.appendChild(mkelement("li", ["group-element"], subdisplay.element));
- updaters.push(subdisplay.update.bind(subdisplay));
- });
-
- var animFrameWasRequested = false;
- return {
- element: container,
- header: header,
- update: function () {
- if (elementIsVisible(list)) {
- updaters.forEach(function (f) { f(); });
- }
- },
- updateIfVisible: function () {
- if (!animFrameWasRequested) {
- window.requestAnimationFrame/*shimmed*/(function () {
- animFrameWasRequested = false;
- this.update();
- }.bind(this), container);
- animFrameWasRequested = true;
- }
- }
- };
- };
- ViewGroup.prototype.start = function () {
- this.elements.forEach(function (e) { e.start(); });
- };
- ViewGroup.prototype.end = function () {
- this.elements.forEach(function (e) { e.end(); });
- };
-
- function TopGroup(label, elements) {
- ViewGroup.call(this, label, elements);
- }
- TopGroup.prototype = Object.create(ViewGroup);
- TopGroup.prototype.constructor = TopGroup;
- TopGroup.prototype.createDisplay = function (document, stateContext) {
- var d = ViewGroup.prototype.createDisplay.call(this, document, stateContext);
- var toggle = createToggle(stateContext + ".graphsVisible", function (visible) {
- d.element.classList[visible ? "remove" : "add"](["hide-sparklines"]);
- });
- var bogusval = mkelement("span", ["value"]); // strictly for layout :(
- d.header.parentNode.insertBefore(toggle, d.header.nextSibling);
- d.header.parentNode.insertBefore(bogusval, d.header.nextSibling);
- return d;
- };
-
- function Quantity(label) {
- this.label = label;
- this.value = null;
- this.history = new Float32Array(100); // TODO magic number
- this.historyIndex = 0;
- }
- Quantity.prototype.createDisplay = function (document, stateContext) {
- var labelElem, valueText, sparkCanvas;
- var container = mkelement("div", ["item", "quantity"],
- labelElem = mkelement("span", ["label"], this.label + ": "),
- mkelement("span", ["value"],
- valueText = document.createTextNode("")),
- sparkCanvas = mkelement("canvas", ["sparkline"])
- );
-
- // sparkline
- var sparkLength = sparkCanvas.width = this.history.length;
- var sparkHeight = sparkCanvas.height = 1; // updated later via computed style
- var sparkContext = sparkCanvas.getContext("2d");
- var lastUpdateIndex = 0;
-
- var fillColor = "rgba(127,127,127,0.5)";
-
- return {
- element: container,
- update: function () {
- valueText.data = String(this.show());
-
- var indexOffset = this.historyIndex;
- if (elementIsVisible(sparkCanvas) &&
- lastUpdateIndex !== indexOffset /* there is new data */) {
- lastUpdateIndex = indexOffset;
-
- sparkHeight = parseInt(window.getComputedStyle(labelElem, null).height, 10) - 3;
- if (sparkHeight != sparkCanvas.height) sparkCanvas.height = sparkHeight;
-
- var history = this.history;
- var fgColor = window.getComputedStyle(sparkCanvas, null).color;
-
- sparkContext.clearRect(0, 0, sparkLength, sparkHeight);
-
- // Find maximum and minimum of graph
- var miny = 0 /* Infinity */; // assume 0 is a meaningful minimum
- var maxy = -Infinity;
- var i;
- for (i = sparkLength - 1; i >= 0; i--) {
- var y = history[i];
- miny = min(y, miny);
- maxy = max(y, maxy);
- }
-
- // Establish viewport of graph. The maximum zoom is 1 value unit = 1px.
- var viewScale = -min(1, (sparkHeight - 1)/(maxy - miny));
- var viewOffset = -miny * viewScale + sparkHeight - 1;
-
- // Draw graph: first background fill, then line
- sparkContext.fillStyle = fillColor;
- var scaley;
- for (i = sparkLength - 1; i >= 0; i--) {
- scaley = history[(i + indexOffset) % sparkLength] * viewScale + viewOffset;
- sparkContext.fillRect(i, scaley, 1, sparkHeight);
- }
- sparkContext.fillStyle = fgColor;
- for (i = sparkLength - 1; i >= 0; i--) {
- scaley = history[(i + indexOffset) % sparkLength] * viewScale + viewOffset;
- sparkContext.fillRect(i, scaley, 1, 1);
- }
- }
- }.bind(this)
- };
- };
- Quantity.prototype.start = function () {};
- Quantity.prototype.end = function () {
- var hi = this.historyIndex;
- this.history[hi] = this.value;
- this.historyIndex = (hi + 1) % this.history.length;
- };
-
-
- function Timer(label) {
- Quantity.call(this, label);
- var souper = Object.getPrototypeOf(this);
-
- var t0 = null;
- this.start = function () {
- t0 = Date.now();
- souper.start.call(this);
- };
- this.end = function () {
- var t1 = Date.now();
- this.value = t1 - t0;
- souper.end.call(this);
- };
- }
- Timer.prototype = Object.create(Quantity.prototype);
- Timer.prototype.show = function () {
- return this.value + " ms";
- };
-
- function Counter(label) {
- Quantity.call(this, label);
- var souper = Object.getPrototypeOf(this);
-
- // TODO it might be interesting to note out-of-bracket incs
-
- var counter = 0;
- this.inc = function (amount) {
- if (amount === undefined) amount = 1;
- counter += amount;
- };
- this.start = function () {
- souper.start.call(this);
- };
- this.end = function () {
- this.value = counter;
- counter = 0;
- souper.end.call(this);
- };
- }
- Counter.prototype = Object.create(Quantity.prototype);
- Counter.prototype.show = function () {
- return numberWithCommas(this.value);
- };
-
- function TaskGroup(label, elements) {
- var timer = new Timer("Time");
- ViewGroup.call(this, label, [timer].concat(elements));
-
- this.start = function () {
- Object.getPrototypeOf(this).start.call(this);
- };
- this.end = function () {
- Object.getPrototypeOf(this).end.call(this);
- };
- }
- TaskGroup.prototype = Object.create(ViewGroup.prototype);
-
- measviz = Object.freeze({
- Counter: Counter,
- TaskGroup: TaskGroup,
- TopGroup: TopGroup,
- ViewGroup: ViewGroup
- });
-}());
Please sign in to comment.
Something went wrong with that request. Please try again.