/*
* wpm.d - Measure words per minute of typing.
* Written in DTrace (Solaris 10 3/05).
*
* $Id: wpm.d 52 2007-09-24 04:28:01Z brendan $
*
* USAGE: wpm.d commandname
* eg,
* wpm.d bash
* wpm.d vim
*
* This script assumes that keystrokes arrive one at a time on STDIN. This
* isn't the case for all processes that read keyboard input (eg, sh).
*
* COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* See the License for the specific language governing permissions
* and limitations under the License.
*
* CDDL HEADER END
*
* 05-Aug-2007 Brendan Gregg Created this.
*/
#pragma D option defaultargs
inline int STDIN = 0;
enum tracing_state {
};
/$$1 == ""/
{
trace("USAGE: wpm.d commandname\n");
trace(" eg,\n");
trace(" wpm.d bash\n");
trace(" wpm.d vim\n");
exit(1);
}
{
keys = 0;
words = 0;
wordsize = 0;
countdown = 5;
last = 0;
}
/--countdown >= 0/
{
}
{
countdown = 60;
}
{
}
{
}
{
keys++;
wordsize++;
}
wordsize == 1/
{
/* recurring space */
wordsize = 0;
}
{
words++;
wordsize = 0;
}
{
}
{
exit(0);
}