|
1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 var view = |
|
7 { |
|
8 configUrl: null, |
|
9 testArray: null, |
|
10 mCurrent: null, |
|
11 |
|
12 browseForConfig: function() |
|
13 { |
|
14 enablePrivilege('UniversalXPConnect'); |
|
15 var fp = Components.classes["@mozilla.org/filepicker;1"]. |
|
16 createInstance(nsIFilePicker); |
|
17 fp.init(window,'XSLTMark Description File',nsIFilePicker.modeOpen); |
|
18 fp.appendFilter('*.conf', '*.conf'); |
|
19 fp.appendFilters(nsIFilePicker.filterAll); |
|
20 var res = fp.show(); |
|
21 |
|
22 if (res == nsIFilePicker.returnOK) { |
|
23 this.configUrl = Components.classes[STDURL_CTRID].createInstance(nsIURI); |
|
24 this.configUrl.spec = fp.fileURL.spec; |
|
25 document.getElementById('config').setAttribute('value', this.configUrl.spec); |
|
26 } |
|
27 this.parseConfig(); |
|
28 return true; |
|
29 }, |
|
30 |
|
31 parseConfig: function() |
|
32 { |
|
33 this.testArray = new Array(); |
|
34 var test; |
|
35 if (!this.configUrl) { |
|
36 return; |
|
37 } |
|
38 |
|
39 var content = loadFile(this.configUrl.spec); |
|
40 |
|
41 var lines = content.split("\n"); |
|
42 var line, res; |
|
43 var head = /^\[(.+)\]$/; |
|
44 var instruct = /^(.+)=(.+)$/; |
|
45 while (lines.length) { |
|
46 line = lines.shift(); |
|
47 if (head.test(line)) { |
|
48 test = new Object; |
|
49 res = head.exec(line); |
|
50 test['title'] = res[1]; |
|
51 this.testArray.push(test); |
|
52 } |
|
53 else if (line == '') { |
|
54 test = undefined; |
|
55 } |
|
56 else { |
|
57 res = instruct.exec(line); |
|
58 test[res[1]] = res[2]; |
|
59 } |
|
60 } |
|
61 }, |
|
62 |
|
63 onLoad: function() |
|
64 { |
|
65 this.mCurrentStatus = document.getElementById('currentStatus'); |
|
66 this.mCurrentProgress = document.getElementById('currentProgress'); |
|
67 this.mTotalProgress = document.getElementById('totalProgress'); |
|
68 this.mOutput = document.getElementById('transformOutput'); |
|
69 this.mDetailOutput = |
|
70 document.getElementById('transformDetailedOutput'); |
|
71 this.mDetail = true; |
|
72 }, |
|
73 |
|
74 progress: function(aTitle, aTime, aProgress) |
|
75 { |
|
76 // dump20(aTitle); |
|
77 // dump20(aTime); |
|
78 // dump20(aProgress); |
|
79 this.mCurrentProgress.value = aProgress; |
|
80 this.displayDetailTime(aTime); |
|
81 this.mTimes.push(aTime); |
|
82 // dump("\n"); |
|
83 }, |
|
84 |
|
85 done: function(aTitle) |
|
86 { |
|
87 // dump(aTitle + " is finished.\n"); |
|
88 this.mCurrent++; |
|
89 this.mCurrentProgress.value = 0; |
|
90 this.displayTotalTime(); |
|
91 if (this.mCurrent >= this.testArray.length) { |
|
92 this.mTotalProgress.value = 0; |
|
93 this.mCurrentStatus.value = "done"; |
|
94 return; |
|
95 } |
|
96 this.mTotalProgress.value = this.mCurrent*100/this.testArray.length; |
|
97 var test = this.testArray[this.mCurrent]; |
|
98 enablePrivilege('UniversalXPConnect'); |
|
99 this.displayTest(test.title); |
|
100 runTest(test.title, this.configUrl.resolve(test.input), |
|
101 this.configUrl.resolve(test.stylesheet), |
|
102 test.iterations, this); |
|
103 }, |
|
104 |
|
105 onStop: function() |
|
106 { |
|
107 clearTimeout(gTimeout); |
|
108 this.mCurrentProgress.value = 0; |
|
109 this.mTotalProgress.value = 0; |
|
110 this.mCurrentStatus.value = "stopped"; |
|
111 }, |
|
112 |
|
113 displayTest: function(aTitle) |
|
114 { |
|
115 this.mTimes = new Array; |
|
116 aTitle += "\t"; |
|
117 this.mCurrentStatus.value = aTitle; |
|
118 this.mOutput.value += aTitle; |
|
119 if (this.mDetail) { |
|
120 this.mDetailOutput.value += aTitle; |
|
121 } |
|
122 }, |
|
123 |
|
124 displayDetailTime: function(aTime) |
|
125 { |
|
126 if (this.mDetail) { |
|
127 this.mDetailOutput.value += aTime + " ms\t"; |
|
128 } |
|
129 }, |
|
130 |
|
131 displayTotalTime: function() |
|
132 { |
|
133 var sum = 0; |
|
134 for (k = 0; k < this.mTimes.length; k++) { |
|
135 sum += this.mTimes[k]; |
|
136 } |
|
137 var mean = sum / this.mTimes.length; |
|
138 this.mOutput.value += Number(mean).toFixed(2) + " ms\t" + sum + " ms\t"; |
|
139 var variance = 0; |
|
140 for (k = 0; k < this.mTimes.length; k++) { |
|
141 var n = this.mTimes[k] - mean; |
|
142 variance += n*n; |
|
143 } |
|
144 variance = Math.sqrt(variance/this.mTimes.length); |
|
145 this.mOutput.value += Number(variance).toFixed(2)+"\n"; |
|
146 if (this.mDetail) { |
|
147 this.mDetailOutput.value += "\n"; |
|
148 } |
|
149 }, |
|
150 |
|
151 runBenchmark: function() |
|
152 { |
|
153 enablePrivilege('UniversalXPConnect'); |
|
154 if (!this.testArray) { |
|
155 if (!this.configUrl) { |
|
156 this.configUrl = Components.classes[STDURL_CTRID].createInstance(nsIURI); |
|
157 this.configUrl.spec = document.getElementById('config').value; |
|
158 } |
|
159 this.parseConfig(); |
|
160 } |
|
161 |
|
162 this.mCurrent = 0; |
|
163 var test = this.testArray[this.mCurrent]; |
|
164 this.mOutput.value = ''; |
|
165 if (this.mDetail) { |
|
166 this.mDetailOutput.value = ''; |
|
167 } |
|
168 this.displayTest(test.title); |
|
169 runTest(test.title, this.configUrl.resolve(test.input), |
|
170 this.configUrl.resolve(test.stylesheet), |
|
171 test.iterations, this); |
|
172 return true; |
|
173 } |
|
174 } |
|
175 |