Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

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