diff options
author | wosch <wosch@FreeBSD.org> | 1996-06-30 11:58:20 +0000 |
---|---|---|
committer | wosch <wosch@FreeBSD.org> | 1996-06-30 11:58:20 +0000 |
commit | 662bf44fe275c34ca357cbfb3bccb1ec9b3a9bda (patch) | |
tree | c24230199b182a22e7f311e47eb703a54c037139 | |
parent | fdfd212c01a8039095632c5a6ed0efcf0b969d28 (diff) | |
download | FreeBSD-src-662bf44fe275c34ca357cbfb3bccb1ec9b3a9bda.zip FreeBSD-src-662bf44fe275c34ca357cbfb3bccb1ec9b3a9bda.tar.gz |
Add some options which makes lastcomm(1) a better debug tool.
-rw-r--r-- | usr.bin/lastcomm/lastcomm.1 | 34 | ||||
-rw-r--r-- | usr.bin/lastcomm/lastcomm.c | 98 |
2 files changed, 119 insertions, 13 deletions
diff --git a/usr.bin/lastcomm/lastcomm.1 b/usr.bin/lastcomm/lastcomm.1 index 1542b0d..de63367 100644 --- a/usr.bin/lastcomm/lastcomm.1 +++ b/usr.bin/lastcomm/lastcomm.1 @@ -30,6 +30,7 @@ .\" SUCH DAMAGE. .\" .\" @(#)lastcomm.1 8.1 (Berkeley) 6/6/93 +.\" $Id: $ .\" .Dd June 6, 1993 .Dt LASTCOMM 1 @@ -39,6 +40,7 @@ .Nd show last commands executed in reverse order .Sh SYNOPSIS .Nm lastcomm +.Op Fl EScesu .Op Fl f Ar file .Op Ar command ... .Op Ar user ... @@ -50,8 +52,35 @@ With no arguments, .Nm lastcomm prints information about all the commands recorded during the current accounting file's lifetime. + .Pp -Option: +The following options are available: +.Pp +.Bl -tag -width Fl +.Pp +.It Fl E +The time the process exited. +.Pp +.It Fl S +The time the process started, default. + +.It Fl c +The amount of cpu time used by the process (in seconds), default. +.It Fl e +The amount of elapsed time used by the process (in seconds). +.It Fl s +The amount of system time used by the process (in seconds). +.It Fl u +The amount of user time used by the process (in seconds). +.El + +.Pp +Use +.Op Fl cS +as default if no one of these previous options called. +.Pp +.Pp + .Pp .Bl -tag -width Fl .It Fl f Ar file @@ -95,7 +124,8 @@ The command name under which the process was called. .It The amount of cpu time used by the process (in seconds). .It -The time the process exited. +.\" Wrong: The time the process exited. +The time the process started. .El .Pp The flags are encoded as follows: ``S'' indicates the command was diff --git a/usr.bin/lastcomm/lastcomm.c b/usr.bin/lastcomm/lastcomm.c index 08f971d..267216a 100644 --- a/usr.bin/lastcomm/lastcomm.c +++ b/usr.bin/lastcomm/lastcomm.c @@ -29,6 +29,8 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. + * + * $Id: $ */ #ifndef lint @@ -63,6 +65,16 @@ int requested __P((char *[], struct acct *)); void usage __P((void)); char *user_from_uid(); +#define AC_UTIME 1 /* user */ +#define AC_STIME 2 /* system */ +#define AC_ETIME 4 /* elapsed */ +#define AC_CTIME 8 /* user + system time, default */ + +#define AC_BTIME 16 /* starting time */ +#define AC_FTIME 32 /* exit time (starting time + elapsed time )*/ + +#define AC_HZ ((double)AHZ) + int main(argc, argv) int argc; @@ -76,17 +88,46 @@ main(argc, argv) time_t t; int ch; char *acctfile; + int time = 0; acctfile = _PATH_ACCT; - while ((ch = getopt(argc, argv, "f:")) != EOF) + while ((ch = getopt(argc, argv, "f:usecSE")) != EOF) switch((char)ch) { case 'f': acctfile = optarg; break; + + case 'u': + time |= AC_UTIME; /* user time */ + break; + case 's': + time |= AC_STIME; /* system time */ + break; + case 'e': + time |= AC_ETIME; /* elapsed time */ + break; + case 'c': + time |= AC_CTIME; /* user + system time */ + break; + + case 'S': + time |= AC_BTIME; /* starting time */ + break; + case 'E': + /* exit time (starting time + elapsed time )*/ + time |= AC_FTIME; + break; + case '?': default: usage(); } + + /* default user + system time and starting time */ + if (!time) { + time = AC_CTIME | AC_BTIME; + } + argc -= optind; argv += optind; @@ -134,15 +175,50 @@ main(argc, argv) if (*argv && !requested(argv, &ab)) continue; - t = expand(ab.ac_utime) + expand(ab.ac_stime); - (void)printf("%-*.*s %-7s %-*s %-*s %6.2f secs %.16s\n", - fldsiz(acct, ac_comm), fldsiz(acct, ac_comm), - ab.ac_comm, flagbits(ab.ac_flag), - UT_NAMESIZE, user_from_uid(ab.ac_uid, 0), - UT_LINESIZE, getdev(ab.ac_tty), - t / (double)AHZ, ctime(&ab.ac_btime)); - } - exit(0); + (void)printf("%-*s %-7s %-*s %-*s ", + fldsiz(acct, ac_comm), ab.ac_comm, + flagbits(ab.ac_flag), + UT_NAMESIZE, user_from_uid(ab.ac_uid, 0), + UT_LINESIZE, getdev(ab.ac_tty)); + + + /* user + system time */ + if (time & AC_CTIME) { + (void)printf("%6.2f secs ", + (expand(ab.ac_utime) + + expand(ab.ac_stime))/AC_HZ); + } + + /* usr time */ + if (time & AC_UTIME) { + (void)printf("%6.2f us ", expand(ab.ac_utime)/AC_HZ); + } + + /* system time */ + if (time & AC_STIME) { + (void)printf("%6.2f sy ", expand(ab.ac_stime)/AC_HZ); + } + + /* elapsed time */ + if (time & AC_ETIME) { + (void)printf("%8.2f es ", expand(ab.ac_etime)/AC_HZ); + } + + /* starting time */ + if (time & AC_BTIME) { + (void)printf("%.16s ", ctime(&ab.ac_btime)); + } + + /* exit time (starting time + elapsed time )*/ + if (time & AC_FTIME) { + t = ab.ac_btime; + t += (time_t)(expand(ab.ac_etime)/AC_HZ); + (void)printf("%.16s ", + ctime(&t)); + } + printf("\n"); + } + exit(0); } time_t @@ -218,6 +294,6 @@ void usage() { (void)fprintf(stderr, - "lastcomm [ -f file ] [command ...] [user ...] [tty ...]\n"); + "lastcomm [-EScesu] [ -f file ] [command ...] [user ...] [tty ...]\n"); exit(1); } |