michael@0: /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: var view = michael@0: { michael@0: configUrl: null, michael@0: testArray: null, michael@0: mCurrent: null, michael@0: michael@0: browseForConfig: function() michael@0: { michael@0: enablePrivilege('UniversalXPConnect'); michael@0: var fp = Components.classes["@mozilla.org/filepicker;1"]. michael@0: createInstance(nsIFilePicker); michael@0: fp.init(window,'XSLTMark Description File',nsIFilePicker.modeOpen); michael@0: fp.appendFilter('*.conf', '*.conf'); michael@0: fp.appendFilters(nsIFilePicker.filterAll); michael@0: var res = fp.show(); michael@0: michael@0: if (res == nsIFilePicker.returnOK) { michael@0: this.configUrl = Components.classes[STDURL_CTRID].createInstance(nsIURI); michael@0: this.configUrl.spec = fp.fileURL.spec; michael@0: document.getElementById('config').setAttribute('value', this.configUrl.spec); michael@0: } michael@0: this.parseConfig(); michael@0: return true; michael@0: }, michael@0: michael@0: parseConfig: function() michael@0: { michael@0: this.testArray = new Array(); michael@0: var test; michael@0: if (!this.configUrl) { michael@0: return; michael@0: } michael@0: michael@0: var content = loadFile(this.configUrl.spec); michael@0: michael@0: var lines = content.split("\n"); michael@0: var line, res; michael@0: var head = /^\[(.+)\]$/; michael@0: var instruct = /^(.+)=(.+)$/; michael@0: while (lines.length) { michael@0: line = lines.shift(); michael@0: if (head.test(line)) { michael@0: test = new Object; michael@0: res = head.exec(line); michael@0: test['title'] = res[1]; michael@0: this.testArray.push(test); michael@0: } michael@0: else if (line == '') { michael@0: test = undefined; michael@0: } michael@0: else { michael@0: res = instruct.exec(line); michael@0: test[res[1]] = res[2]; michael@0: } michael@0: } michael@0: }, michael@0: michael@0: onLoad: function() michael@0: { michael@0: this.mCurrentStatus = document.getElementById('currentStatus'); michael@0: this.mCurrentProgress = document.getElementById('currentProgress'); michael@0: this.mTotalProgress = document.getElementById('totalProgress'); michael@0: this.mOutput = document.getElementById('transformOutput'); michael@0: this.mDetailOutput = michael@0: document.getElementById('transformDetailedOutput'); michael@0: this.mDetail = true; michael@0: }, michael@0: michael@0: progress: function(aTitle, aTime, aProgress) michael@0: { michael@0: // dump20(aTitle); michael@0: // dump20(aTime); michael@0: // dump20(aProgress); michael@0: this.mCurrentProgress.value = aProgress; michael@0: this.displayDetailTime(aTime); michael@0: this.mTimes.push(aTime); michael@0: // dump("\n"); michael@0: }, michael@0: michael@0: done: function(aTitle) michael@0: { michael@0: // dump(aTitle + " is finished.\n"); michael@0: this.mCurrent++; michael@0: this.mCurrentProgress.value = 0; michael@0: this.displayTotalTime(); michael@0: if (this.mCurrent >= this.testArray.length) { michael@0: this.mTotalProgress.value = 0; michael@0: this.mCurrentStatus.value = "done"; michael@0: return; michael@0: } michael@0: this.mTotalProgress.value = this.mCurrent*100/this.testArray.length; michael@0: var test = this.testArray[this.mCurrent]; michael@0: enablePrivilege('UniversalXPConnect'); michael@0: this.displayTest(test.title); michael@0: runTest(test.title, this.configUrl.resolve(test.input), michael@0: this.configUrl.resolve(test.stylesheet), michael@0: test.iterations, this); michael@0: }, michael@0: michael@0: onStop: function() michael@0: { michael@0: clearTimeout(gTimeout); michael@0: this.mCurrentProgress.value = 0; michael@0: this.mTotalProgress.value = 0; michael@0: this.mCurrentStatus.value = "stopped"; michael@0: }, michael@0: michael@0: displayTest: function(aTitle) michael@0: { michael@0: this.mTimes = new Array; michael@0: aTitle += "\t"; michael@0: this.mCurrentStatus.value = aTitle; michael@0: this.mOutput.value += aTitle; michael@0: if (this.mDetail) { michael@0: this.mDetailOutput.value += aTitle; michael@0: } michael@0: }, michael@0: michael@0: displayDetailTime: function(aTime) michael@0: { michael@0: if (this.mDetail) { michael@0: this.mDetailOutput.value += aTime + " ms\t"; michael@0: } michael@0: }, michael@0: michael@0: displayTotalTime: function() michael@0: { michael@0: var sum = 0; michael@0: for (k = 0; k < this.mTimes.length; k++) { michael@0: sum += this.mTimes[k]; michael@0: } michael@0: var mean = sum / this.mTimes.length; michael@0: this.mOutput.value += Number(mean).toFixed(2) + " ms\t" + sum + " ms\t"; michael@0: var variance = 0; michael@0: for (k = 0; k < this.mTimes.length; k++) { michael@0: var n = this.mTimes[k] - mean; michael@0: variance += n*n; michael@0: } michael@0: variance = Math.sqrt(variance/this.mTimes.length); michael@0: this.mOutput.value += Number(variance).toFixed(2)+"\n"; michael@0: if (this.mDetail) { michael@0: this.mDetailOutput.value += "\n"; michael@0: } michael@0: }, michael@0: michael@0: runBenchmark: function() michael@0: { michael@0: enablePrivilege('UniversalXPConnect'); michael@0: if (!this.testArray) { michael@0: if (!this.configUrl) { michael@0: this.configUrl = Components.classes[STDURL_CTRID].createInstance(nsIURI); michael@0: this.configUrl.spec = document.getElementById('config').value; michael@0: } michael@0: this.parseConfig(); michael@0: } michael@0: michael@0: this.mCurrent = 0; michael@0: var test = this.testArray[this.mCurrent]; michael@0: this.mOutput.value = ''; michael@0: if (this.mDetail) { michael@0: this.mDetailOutput.value = ''; michael@0: } michael@0: this.displayTest(test.title); michael@0: runTest(test.title, this.configUrl.resolve(test.input), michael@0: this.configUrl.resolve(test.stylesheet), michael@0: test.iterations, this); michael@0: return true; michael@0: } michael@0: } michael@0: