| 1318 |
alexandre_ |
1 |
/*
|
|
|
2 |
Copyright (c) 2004-2006, The Dojo Foundation
|
|
|
3 |
All Rights Reserved.
|
|
|
4 |
|
|
|
5 |
Licensed under the Academic Free License version 2.1 or above OR the
|
|
|
6 |
modified BSD license. For more information on Dojo licensing, see:
|
|
|
7 |
|
|
|
8 |
http://dojotoolkit.org/community/licensing.shtml
|
|
|
9 |
*/
|
|
|
10 |
|
|
|
11 |
dojo.provide("dojo.profile");
|
|
|
12 |
dojo.profile = {_profiles:{}, _pns:[], start:function (name) {
|
|
|
13 |
if (!this._profiles[name]) {
|
|
|
14 |
this._profiles[name] = {iters:0, total:0};
|
|
|
15 |
this._pns[this._pns.length] = name;
|
|
|
16 |
} else {
|
|
|
17 |
if (this._profiles[name]["start"]) {
|
|
|
18 |
this.end(name);
|
|
|
19 |
}
|
|
|
20 |
}
|
|
|
21 |
this._profiles[name].end = null;
|
|
|
22 |
this._profiles[name].start = new Date();
|
|
|
23 |
}, end:function (name) {
|
|
|
24 |
var ed = new Date();
|
|
|
25 |
if ((this._profiles[name]) && (this._profiles[name]["start"])) {
|
|
|
26 |
with (this._profiles[name]) {
|
|
|
27 |
end = ed;
|
|
|
28 |
total += (end - start);
|
|
|
29 |
start = null;
|
|
|
30 |
iters++;
|
|
|
31 |
}
|
|
|
32 |
} else {
|
|
|
33 |
return true;
|
|
|
34 |
}
|
|
|
35 |
}, dump:function (appendToDoc) {
|
|
|
36 |
var tbl = document.createElement("table");
|
|
|
37 |
with (tbl.style) {
|
|
|
38 |
border = "1px solid black";
|
|
|
39 |
borderCollapse = "collapse";
|
|
|
40 |
}
|
|
|
41 |
var hdr = tbl.createTHead();
|
|
|
42 |
var hdrtr = hdr.insertRow(0);
|
|
|
43 |
var cols = ["Identifier", "Calls", "Total", "Avg"];
|
|
|
44 |
for (var x = 0; x < cols.length; x++) {
|
|
|
45 |
var ntd = hdrtr.insertCell(x);
|
|
|
46 |
with (ntd.style) {
|
|
|
47 |
backgroundColor = "#225d94";
|
|
|
48 |
color = "white";
|
|
|
49 |
borderBottom = "1px solid black";
|
|
|
50 |
borderRight = "1px solid black";
|
|
|
51 |
fontFamily = "tahoma";
|
|
|
52 |
fontWeight = "bolder";
|
|
|
53 |
paddingLeft = paddingRight = "5px";
|
|
|
54 |
}
|
|
|
55 |
ntd.appendChild(document.createTextNode(cols[x]));
|
|
|
56 |
}
|
|
|
57 |
for (var x = 0; x < this._pns.length; x++) {
|
|
|
58 |
var prf = this._profiles[this._pns[x]];
|
|
|
59 |
this.end(this._pns[x]);
|
|
|
60 |
if (prf.iters > 0) {
|
|
|
61 |
var bdytr = tbl.insertRow(true);
|
|
|
62 |
var vals = [this._pns[x], prf.iters, prf.total, parseInt(prf.total / prf.iters)];
|
|
|
63 |
for (var y = 0; y < vals.length; y++) {
|
|
|
64 |
var cc = bdytr.insertCell(y);
|
|
|
65 |
cc.appendChild(document.createTextNode(vals[y]));
|
|
|
66 |
with (cc.style) {
|
|
|
67 |
borderBottom = "1px solid gray";
|
|
|
68 |
paddingLeft = paddingRight = "5px";
|
|
|
69 |
if (x % 2) {
|
|
|
70 |
backgroundColor = "#e1f1ff";
|
|
|
71 |
}
|
|
|
72 |
if (y > 0) {
|
|
|
73 |
textAlign = "right";
|
|
|
74 |
borderRight = "1px solid gray";
|
|
|
75 |
} else {
|
|
|
76 |
borderRight = "1px solid black";
|
|
|
77 |
}
|
|
|
78 |
}
|
|
|
79 |
}
|
|
|
80 |
}
|
|
|
81 |
}
|
|
|
82 |
if (appendToDoc) {
|
|
|
83 |
var ne = document.createElement("div");
|
|
|
84 |
ne.id = "profileOutputTable";
|
|
|
85 |
with (ne.style) {
|
|
|
86 |
fontFamily = "Courier New, monospace";
|
|
|
87 |
fontSize = "12px";
|
|
|
88 |
lineHeight = "16px";
|
|
|
89 |
borderTop = "1px solid black";
|
|
|
90 |
padding = "10px";
|
|
|
91 |
}
|
|
|
92 |
if (document.getElementById("profileOutputTable")) {
|
|
|
93 |
dojo.body().replaceChild(ne, document.getElementById("profileOutputTable"));
|
|
|
94 |
} else {
|
|
|
95 |
dojo.body().appendChild(ne);
|
|
|
96 |
}
|
|
|
97 |
ne.appendChild(tbl);
|
|
|
98 |
}
|
|
|
99 |
return tbl;
|
|
|
100 |
}};
|
|
|
101 |
dojo.profile.stop = dojo.profile.end;
|
|
|
102 |
|