3 * wpm.d - Measure words per minute of typing.
4 * Written in DTrace (Solaris 10 3/05).
6 * $Id: wpm.d 52 2007-09-24 04:28:01Z brendan $
8 * USAGE: wpm.d commandname
13 * This script assumes that keystrokes arrive one at a time on STDIN. This
14 * isn't the case for all processes that read keyboard input (eg, sh).
16 * COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
20 * The contents of this file are subject to the terms of the
21 * Common Development and Distribution License, Version 1.0 only
22 * (the "License"). You may not use this file except in compliance
25 * You can obtain a copy of the license at Docs/cddl1.txt
26 * or http://www.opensolaris.org/os/licensing.
27 * See the License for the specific language governing permissions
28 * and limitations under the License.
32 * 05-Aug-2007 Brendan Gregg Created this.
35 #pragma D option quiet
36 #pragma D option switchrate=10
37 #pragma D option defaultargs
49 trace("USAGE: wpm.d commandname\n");
51 trace(" wpm.d bash\n");
52 trace(" wpm.d vim\n");
64 printf("Measuring will start in : %2d seconds", countdown);
70 printf("\b\b\b\b\b\b\b\b\b\b%2d seconds", countdown);
74 /state == BEGIN && countdown == -1/
78 printf("\nMeasuring will stop in : %2d seconds", countdown);
82 /state == TRACING && execname == $$1 && arg0 == STDIN/
90 this->elapsed = (timestamp - last) / 1000000;
91 @dist = quantize(this->elapsed);
92 @avg = avg(this->elapsed);
93 @min = min(this->elapsed);
94 @max = max(this->elapsed);
102 this->key = stringof(copyin(self->buf, arg0));
107 /self->buf && (this->key == " " || this->key == "\n" || this->key == "\r") &&
110 /* recurring space */
116 /self->buf && (this->key == " " || this->key == "\n" || this->key == "\r")/
119 @sizes = lquantize(wordsize - 1, 0, 32, 1);
130 /state == TRACING && countdown == -1/
132 printf("\n\nCharacters typed : %d\n", keys);
133 printf("Words per minute : %d\n\n", words);
135 printa("Minimum keystroke latency : %@d ms\n", @min);
136 printa("Average keystroke latency : %@d ms\n", @avg);
137 printa("Maximum keystroke latency : %@d ms\n\n", @max);
139 printa("Word size distribution (letters),\n%@d\n", @sizes);
140 printa("Keystroke latency distribution (ms),\n%@d\n", @dist);