summaryrefslogtreecommitdiffstats
path: root/usr.sbin/sa
diff options
context:
space:
mode:
authordds <dds@FreeBSD.org>2007-05-18 12:36:10 +0000
committerdds <dds@FreeBSD.org>2007-05-18 12:36:10 +0000
commitef91577059eef3218a7be70aaa4f40f9461c1557 (patch)
treeaa1a9d4e9bc0bd39ea085c8ce6a40568d756af92 /usr.sbin/sa
parent3be5d73f3d1c92dd592d30ddfcf7d342c48cb971 (diff)
downloadFreeBSD-src-ef91577059eef3218a7be70aaa4f40f9461c1557.zip
FreeBSD-src-ef91577059eef3218a7be70aaa4f40f9461c1557.tar.gz
Add -U and -P options that allow the specification of the per-user
and per-process summary file location. These make the program more flexible, and also make it possible to write sane regression tests.
Diffstat (limited to 'usr.sbin/sa')
-rw-r--r--usr.sbin/sa/extern.h1
-rw-r--r--usr.sbin/sa/main.c14
-rw-r--r--usr.sbin/sa/pdb.c4
-rw-r--r--usr.sbin/sa/sa.816
-rw-r--r--usr.sbin/sa/usrdb.c4
5 files changed, 32 insertions, 7 deletions
diff --git a/usr.sbin/sa/extern.h b/usr.sbin/sa/extern.h
index bc5f199..ccdd763 100644
--- a/usr.sbin/sa/extern.h
+++ b/usr.sbin/sa/extern.h
@@ -82,6 +82,7 @@ extern int aflag, bflag, cflag, dflag, Dflag, fflag, iflag, jflag, kflag;
extern int Kflag, lflag, mflag, qflag, rflag, sflag, tflag, uflag, vflag;
extern u_quad_t cutoff;
extern cmpf_t sa_cmp;
+extern const char *pdb_file, *usrdb_file;
/* some #defines to help with db's stupidity */
diff --git a/usr.sbin/sa/main.c b/usr.sbin/sa/main.c
index 1796c9c..3e10c1b 100644
--- a/usr.sbin/sa/main.c
+++ b/usr.sbin/sa/main.c
@@ -71,6 +71,8 @@ static void usage(void);
int aflag, bflag, cflag, dflag, Dflag, fflag, iflag, jflag, kflag;
int Kflag, lflag, mflag, qflag, rflag, sflag, tflag, uflag, vflag;
u_quad_t cutoff = 1;
+const char *pdb_file = _PATH_SAVACCT;
+const char *usrdb_file = _PATH_USRACCT;
static char *dfltargv[] = { NULL };
static int dfltargc = (sizeof dfltargv/sizeof(char *));
@@ -86,7 +88,7 @@ main(int argc, char **argv)
dfltargv[0] = pathacct;
- while ((ch = getopt(argc, argv, "abcdDfijkKlmnqrstuv:")) != -1)
+ while ((ch = getopt(argc, argv, "abcdDfijkKlmnP:qrstuU:v:")) != -1)
switch (ch) {
case 'a':
/* print all commands */
@@ -145,6 +147,10 @@ main(int argc, char **argv)
/* sort by number of calls */
sa_cmp = cmp_calls;
break;
+ case 'P':
+ /* specify program database summary file */
+ pdb_file = optarg;
+ break;
case 'q':
/* quiet; error messages only */
qflag = 1;
@@ -165,6 +171,10 @@ main(int argc, char **argv)
/* first, print uid and command name */
uflag = 1;
break;
+ case 'U':
+ /* specify user database summary file */
+ usrdb_file = optarg;
+ break;
case 'v':
/* cull junk */
vflag = 1;
@@ -294,7 +304,7 @@ static void
usage()
{
(void)fprintf(stderr,
- "usage: sa [-abcdDfijkKlmnqrstu] [-v cutoff] [file ...]\n");
+ "usage: sa [-abcdDfijkKlmnqrstu] [-P file] [-U file] [-v cutoff] [file ...]\n");
exit(1);
}
diff --git a/usr.sbin/sa/pdb.c b/usr.sbin/sa/pdb.c
index 4dd9d27..0c92d34 100644
--- a/usr.sbin/sa/pdb.c
+++ b/usr.sbin/sa/pdb.c
@@ -63,7 +63,7 @@ pacct_init()
DBT key, data;
int serr, nerr;
- saved_pacct_db = dbopen(_PATH_SAVACCT, O_RDONLY, 0, DB_BTREE,
+ saved_pacct_db = dbopen(pdb_file, O_RDONLY, 0, DB_BTREE,
NULL);
if (saved_pacct_db == NULL) {
error = errno == ENOENT ? 0 : -1;
@@ -161,7 +161,7 @@ pacct_update()
DBT key, data;
int error, serr, nerr;
- saved_pacct_db = dbopen(_PATH_SAVACCT, O_RDWR|O_CREAT|O_TRUNC, 0644,
+ saved_pacct_db = dbopen(pdb_file, O_RDWR|O_CREAT|O_TRUNC, 0644,
DB_BTREE, NULL);
if (saved_pacct_db == NULL) {
warn("creating process accounting summary");
diff --git a/usr.sbin/sa/sa.8 b/usr.sbin/sa/sa.8
index c122098..e763064 100644
--- a/usr.sbin/sa/sa.8
+++ b/usr.sbin/sa/sa.8
@@ -29,7 +29,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd February 25, 1994
+.Dd May 18, 2007
.Dt SA 8
.Os
.Sh NAME
@@ -38,6 +38,8 @@
.Sh SYNOPSIS
.Nm
.Op Fl abcdDfijkKlmnqrstu
+.Op Fl P Ar file
+.Op Fl U Ar file
.Op Fl v Ar cutoff
.Op Ar
.Sh DESCRIPTION
@@ -143,6 +145,12 @@ Separate system and user time; normally they are combined.
Print per-user statistics rather than per-command statistics.
.It Fl n
Sort by number of calls.
+.It Fl P Ar file
+Use the specified
+.Ar file
+for accessing the per-command accounting summary database,
+instead of the default
+.Pa /var/account/savacct .
.It Fl q
Create no output other than error messages.
.It Fl r
@@ -155,6 +163,12 @@ For each command, report the ratio of real time to the sum
of user and system cpu times.
If the cpu time is too small to report, ``*ignore*'' appears in
this field.
+.It Fl U Ar file
+Use the specified
+.Ar file
+for accessing the per-user accounting summary database,
+instead of the default
+.Pa /var/account/usracct .
.It Fl u
Superseding all other flags, for each entry
in the accounting file, print the user ID, total seconds of cpu usage,
diff --git a/usr.sbin/sa/usrdb.c b/usr.sbin/sa/usrdb.c
index 991fc90..2f76d65 100644
--- a/usr.sbin/sa/usrdb.c
+++ b/usr.sbin/sa/usrdb.c
@@ -68,7 +68,7 @@ usracct_init()
DBT key, data;
int serr, nerr;
- saved_usracct_db = dbopen(_PATH_USRACCT, O_RDONLY, 0, DB_BTREE,
+ saved_usracct_db = dbopen(usrdb_file, O_RDONLY, 0, DB_BTREE,
&bti);
if (saved_usracct_db == NULL) {
error = (errno == ENOENT) ? 0 : -1;
@@ -180,7 +180,7 @@ usracct_update()
bzero(&bti, sizeof bti);
bti.compare = uid_compare;
- saved_usracct_db = dbopen(_PATH_USRACCT, O_RDWR|O_CREAT|O_TRUNC, 0644,
+ saved_usracct_db = dbopen(usrdb_file, O_RDWR|O_CREAT|O_TRUNC, 0644,
DB_BTREE, &bti);
if (saved_usracct_db == NULL) {
warn("creating user accounting summary");
OpenPOWER on IntegriCloud