From b89a7ee8b956c96a1dcee995ea840feddc5d4b27 Mon Sep 17 00:00:00 2001 From: Pierre Frisch Date: Thu, 22 Dec 2011 07:25:50 -0800 Subject: First commit of Ninja to ninja-internal Signed-off-by: Valerio Virgillito --- .../RDGE/src/core/script/util/fpsTracker.js | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 js/helper-classes/RDGE/src/core/script/util/fpsTracker.js (limited to 'js/helper-classes/RDGE/src/core/script/util/fpsTracker.js') diff --git a/js/helper-classes/RDGE/src/core/script/util/fpsTracker.js b/js/helper-classes/RDGE/src/core/script/util/fpsTracker.js new file mode 100644 index 00000000..0b6cdd84 --- /dev/null +++ b/js/helper-classes/RDGE/src/core/script/util/fpsTracker.js @@ -0,0 +1,51 @@ +/* +This file contains proprietary software owned by Motorola Mobility, Inc.
+No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.
+(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. +
*/ + +fpsTracker = function (id) { + this.id = id; + this.fpsRaw = new stat(id + "_fps", "raw", 0, null, false); + this.fpsAvg = new stat(id + "_fps", "avg", 0, null, false); + this.fpsMin = new stat(id + "_fps", "min", 0, null, false); + this.fpsMax = new stat(id + "_fps", "max", 0, null, false); + this.samples = []; + this.maxSamples = 10; + this.timeStampMS = 0.0; + this.reportInterval = 500; + + this.close = function() { + stat.pages[id + "_fps"] = null; + } + + this.sample = function() { + var currMS = new Date().getTime(); + this.samples.push(currMS - this.timeStampMS); + if (this.samples.length > this.maxSamples) { + this.samples.shift(); + } + this.timeStampMS = currMS; + var accum = 0.0; + var fmin = -1e10; + var fmax = 1e10; + var i = this.samples.length - 1; + while (i >= 0) { + accum += this.samples[i]; + fmin = Math.max(fmin, this.samples[i]); + fmax = Math.min(fmax, this.samples[i]); + i--; + } + var denom = this.samples.length > 0 ? accum / this.samples.length : 0; + var avgFPS = denom > 0 ? 1000 / denom : 0; + var minFPS = fmin > 0 ? 1000 / fmin : 0; + var maxFPS = fmax > 0 ? 1000 / fmax : 0; + var lastSample = this.samples[this.samples.length - 1]; + var rawFPS = (lastSample > 0) ? 1000 / lastSample : 0; + + this.fpsRaw.value = rawFPS.toFixed(2); + this.fpsAvg.value = avgFPS.toFixed(2); + this.fpsMin.value = minFPS.toFixed(2); + this.fpsMax.value = maxFPS.toFixed(2); + } +} \ No newline at end of file -- cgit v1.2.3