-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
212 lines (164 loc) · 6.36 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<!doctype html>
<html>
<head>
<title>PerfHerder 0.2</title>
<link rel="stylesheet" href="assets/bootstrap-1.2.0.css" />
<style type='text/css'>
section {
padding: 60px 0;
}
</style>
<script type='text/javascript'>_prf_start = new Date().getTime()</script>
<script type='text/javascript' src='perfherder.js'></script>
<script type="text/javascript">
_prf = new Perfherder({
debug : true
});
</script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.3/jquery.min.js"></script>
<script type='text/javascript' src='http://www.google-analytics.com/u/ga_debug.js'></script>
<script type='text/javascript'>
_gaq.push(
// ['_setAccount','UA-22711654-2'],
['_setAccount','UA-00000000-1'],
['_trackPageview']
);
</script>
</head>
<body>
<div class="container">
<section>
<div class="pageheader">
<h1>PerfHerder 0.2</h1>
</div>
<h3>Adding PerfHerder to your site</h3>
<p>For best results, set <code>_prf_start</code> (start time) in the <head> before you load any other scripts:</p>
<pre>
<script type='text/javascript'>_prf_start = new Date().getTime()</script>
</pre>
<p>Load the perfherder script later; anytime before you actually need to track something. Then, instantiate it with "new".</p>
<pre>
<script type='text/javascript' src='perfherder.js'></script>
<script type='text/javascript'>
_prf = new Perfherder();
</script>
</pre>
<hr />
<h3>Tracking time since pageload with _prf</h3>
<p>Calling <code>_prf.record('Foo')</code> will track three GA events with:</p>
<ul>
<li>Category: <strong>Perf</strong></li>
<li>Action: <strong>Foo</strong></li>
<li>Opt_label: <strong>Time</strong></li>
<li>Opt_value: <strong>[milliseconds since pageload]</strong></li>
</ul>
<ul>
<li>Category: <strong>Perf By URI</strong></li>
<li>Action: <strong>Foo</strong></li>
<li>Opt_label: <strong>[URI]</strong></li>
<li>Opt_value: <strong>[milliseconds since pageload]</strong></li>
</ul>
<ul>
<li>Category: <strong>Perf By Browser</strong></li>
<li>Action: <strong>Foo</strong></li>
<li>Opt_label: <strong>[browsername/version]</strong></li>
<li>Opt_value: <strong>[milliseconds since pageload]</strong></li>
</ul>
<pre class="execute">
_prf.record('Something happened');
</pre>
<p>This is useful for checking your total pageload and execution time, or seeing how long your users wait on average before they can interact with a feature.</p>
<hr />
<h3>Tracking specific ranges </h3>
<p><code>_prf(name, mark_name) and _prf_mark(name)</code></p>
<p>You can also track how much time elapsed between two events by 'marking' a time and tracking against that mark. This is useful for watching potentially slow methods, or clocking your end-to-end execution time.</p>
<pre class="execute">
function slowMethod(){
for(i = 0; i < 20000; i++){
$('<div></div>').appendTo('body').remove();
}
};
_prf.mark('Slow Method');
slowMethod();
_prf.record('Slow method finished', 'Slow Method')
</pre>
<hr />
<h2>Automatic error catching</h2>
<p>When errors occur, Perfherder automatically records three events:</p>
<ul>
<li>Category: <strong>Error By Type</strong></li>
<li>Action: <strong>[error message]</strong></li>
<li>Opt_label: <strong>[page URI and filename if available]</strong></li>
<li>Opt_value: <strong>[line number if available]</strong></li>
</ul>
<ul>
<li>Category: <strong>Error By Browser</strong></li>
<li>Action: <strong>[browsername/version]</strong></li>
<li>Opt_label: <strong>[page URI and filename if available]</strong></li>
<li>Opt_value: <strong>[line number if available]</strong></li>
</ul>
<pre class="execute">
alort('hello');
</pre>
<hr />
<h3>Manual error catching</h3>
<p>If you'd rather manually track errors, pass your error objects to _prf_error(). "Caught" exceptions generally have less accurate information than window.onerror ones.</p>
<pre class="execute">
try {
alert(hello);
} catch(err){
_prf.error(err);
}
</pre>
<h3>Tracking window dimensions</h3>
<p>
GA tracks screen size, but a more valuable statistic is the actual browser window size.
Since size is wildly variable, the best way to measure it is one dimension at a time, averaged.
For example, you can use this method to learn that the average width of a window is 1145, but the average height is 768
- a metric you couldn't derive from the default GA statistics.
</p>
<p>Using <code>_prf.window</code>, you can record this information.</p>
<pre class="execute">
_prf.window();
</pre>
<p>
Note that this method executes by default on pageload - to avoid it, you need to set
<code>track_window</code> to false when you initialize Perfherder.
</p>
<ul>
<li>Category: <strong>Window</strong></li>
<li>Action: <strong>Dimension</strong></li>
<li>Opt_label: <strong>[Height/Width/Total pixels]</strong></li>
<li>Opt_value: <strong>[Pixels]</strong></li>
</ul>
<hr />
<h2>Settings</h2>
<ul>
<li><code>debug:</code> (boolean) Toggles console logging.</li>
<li><code>track_errors:</code> (boolean) Should window.onerror events automatically track?</li>
<li><code>track_window:</code> (boolean) Should window dimensions be tracked?</li>
<li><code>sample_rate:</code> (integer) Default is 1. If you set this to 0.1, Perfherder will randomly send only 10% of the data it collects to GA. This is a good way to cut down on GA events on a very highly-trafficked site.</li>
</ul>
<p>You can also track how much time elapsed between two events by 'marking' a time and tracking against that mark. This is useful for watching potentially slow methods, or clocking your end-to-end execution time.</p>
<pre>
_prf = new Perfherder({
debug : true
});
</pre>
<p>...or, you can set them directly on your object.</p>
<pre>
_prf.debug = false;
_prf.track_errors = false;
</pre>
</section>
</script>
<script type="text/javascript">
$('pre.execute').each(function(){
$(this).after('<a href="#" class="btn" style="margin-bottom: 10px">Execute</a><br />').next().click(function(event){
event.preventDefault();
eval($(this).prev().text());
});
});
</script>
</body>
</html>