Add some options which makes lastcomm(1) a better debug tool.

This commit is contained in:
Wolfram Schneider 1996-06-30 11:58:20 +00:00
parent 141f35e88e
commit 0309b92baf
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=16849
2 changed files with 119 additions and 13 deletions

View File

@ -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

View File

@ -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);
}