diff options
Diffstat (limited to 'usr/src')
-rw-r--r-- | usr/src/cmd/ptools/ptime/ptime.c | 112 | ||||
-rw-r--r-- | usr/src/man/man1/proc.1 | 20 |
2 files changed, 84 insertions, 48 deletions
diff --git a/usr/src/cmd/ptools/ptime/ptime.c b/usr/src/cmd/ptools/ptime/ptime.c index bc862cddb8..2da2f8d281 100644 --- a/usr/src/cmd/ptools/ptime/ptime.c +++ b/usr/src/cmd/ptools/ptime/ptime.c @@ -24,6 +24,9 @@ * * Portions Copyright 2008 Chad Mynhier */ +/* + * Copyright 2016 Joyent, Inc. + */ #include <stdio.h> #include <stdlib.h> @@ -55,11 +58,34 @@ static char procname[64]; static int Fflag; static int mflag; static int errflg; +static int pflag; +static int pfirst; + +static int +ptime_pid(const char *pidstr) +{ + struct ps_prochandle *Pr; + pid_t pid; + int gret; + + if ((Pr = proc_arg_grab(pidstr, PR_ARG_PIDS, + Fflag | PGRAB_RDONLY, &gret)) == NULL) { + (void) fprintf(stderr, "%s: cannot examine %s: %s\n", + command, pidstr, Pgrab_error(gret)); + return (1); + } + + pid = Pstatus(Pr)->pr_pid; + (void) sprintf(procname, "%d", (int)pid); /* for perr() */ + (void) look(pid); + Prelease(Pr, 0); + return (0); +} int main(int argc, char **argv) { - int opt; + int opt, exit; pid_t pid; struct siginfo info; int status; @@ -80,6 +106,7 @@ main(int argc, char **argv) mflag = 1; break; case 'p': + pflag = 1; pidarg = optarg; break; default: @@ -93,63 +120,70 @@ main(int argc, char **argv) if (((pidarg != NULL) ^ (argc < 1)) || errflg) { (void) fprintf(stderr, - "usage:\t%s [-mh] [-p pid | command [ args ... ]]\n", + "usage:\t%s [-mh] [-p pidlist | command [ args ... ]]\n", command); (void) fprintf(stderr, " (time a command using microstate accounting)\n"); return (1); } - if (pidarg != NULL) { - if ((Pr = proc_arg_grab(pidarg, PR_ARG_PIDS, - Fflag | PGRAB_RDONLY, &gret)) == NULL) { - (void) fprintf(stderr, "%s: cannot examine %s: %s\n", - command, pidarg, Pgrab_error(gret)); - return (1); - } - } else { - if ((Pr = Pcreate(argv[0], &argv[0], &gret, NULL, 0)) == NULL) { - (void) fprintf(stderr, "%s: failed to exec %s: %s\n", - command, argv[0], Pcreate_error(gret)); + if (pflag) { + char *pp; + + exit = 0; + (void) signal(SIGINT, SIG_IGN); + (void) signal(SIGQUIT, SIG_IGN); + + pp = strtok(pidarg, ", "); + if (pp == NULL) { + (void) fprintf(stderr, "%s: invalid argument for -p\n", + command); return (1); } - if (Psetrun(Pr, 0, 0) == -1) { - (void) fprintf(stderr, "%s: failed to set running %s: " - "%s\n", command, argv[0], strerror(errno)); - return (1); + exit = ptime_pid(pp); + while ((pp = strtok(NULL, ", ")) != NULL) { + exit |= ptime_pid(pp); } + return (exit); + } + + + if ((Pr = Pcreate(argv[0], &argv[0], &gret, NULL, 0)) == NULL) { + (void) fprintf(stderr, "%s: failed to exec %s: %s\n", + command, argv[0], Pcreate_error(gret)); + return (1); + } + if (Psetrun(Pr, 0, 0) == -1) { + (void) fprintf(stderr, "%s: failed to set running %s: " + "%s\n", command, argv[0], strerror(errno)); + return (1); } pid = Pstatus(Pr)->pr_pid; + (void) sprintf(procname, "%d", (int)pid); /* for perr() */ (void) signal(SIGINT, SIG_IGN); (void) signal(SIGQUIT, SIG_IGN); - if (pidarg == NULL) - (void) waitid(P_PID, pid, &info, WEXITED | WNOWAIT); + (void) waitid(P_PID, pid, &info, WEXITED | WNOWAIT); (void) look(pid); - if (pidarg != NULL) { - Prelease(Pr, 0); - return (0); - } else { - (void) waitpid(pid, &status, 0); + (void) waitpid(pid, &status, 0); - if (WIFEXITED(status)) - return (WEXITSTATUS(status)); + if (WIFEXITED(status)) + return (WEXITSTATUS(status)); - if (WIFSIGNALED(status)) { - int sig = WTERMSIG(status); - char name[SIG2STR_MAX]; + if (WIFSIGNALED(status)) { + int sig = WTERMSIG(status); + char name[SIG2STR_MAX]; - (void) fprintf(stderr, "%s: command terminated " - "abnormally by %s\n", command, - proc_signame(sig, name, sizeof (name))); - } - - return (status | WCOREFLG); /* see time(1) */ + (void) fprintf(stderr, "%s: command terminated " + "abnormally by %s\n", command, + proc_signame(sig, name, sizeof (name))); } + + return (status | WCOREFLG); /* see time(1) */ } static int @@ -164,6 +198,8 @@ look(pid_t pid) hrtime_t hrtime; prusage_t *pup = &prusage; + pfirst++; + if (proc_get_psinfo(pid, &psinfo) < 0) return (perr("read psinfo")); @@ -186,7 +222,11 @@ look(pid_t pid) if (!mflag) tsadd(&sys, &sys, &pup->pr_ttime); - (void) fprintf(stderr, "\n"); + if (!pflag || pfirst > 1) + (void) fprintf(stderr, "\n"); + if (pflag) + (void) fprintf(stderr, "%d:\t%.70s\n", + (int)psinfo.pr_pid, psinfo.pr_psargs); prtime("real", &real); prtime("user", &user); prtime("sys", &sys); diff --git a/usr/src/man/man1/proc.1 b/usr/src/man/man1/proc.1 index cd20e215e3..e005535810 100644 --- a/usr/src/man/man1/proc.1 +++ b/usr/src/man/man1/proc.1 @@ -2,10 +2,11 @@ .\" Copyright (c) 2008, Sun Microsystems, Inc. All Rights Reserved .\" Portions Copyright 2008 Chad Mynhier .\" Copyright 2012 DEY Storage Systems, Inc. All rights reserved. +.\" Copyright 2016 Joyent, Inc. .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License. .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner] -.TH PROC 1 "Oct 23, 2012" +.TH PROC 1 "Apr 01, 2013" .SH NAME proc, pflags, pcred, pldd, psig, pstack, pfiles, pwdx, pstop, prun, pwait, ptime \- proc tools @@ -72,7 +73,7 @@ ptime \- proc tools .LP .nf -\fB/usr/bin/ptime\fR [\fB-Fm\fR] [\fB-p\fR] \fIpid\fR... +\fB/usr/bin/ptime\fR [\fB-Fm\fR] \fB-p pidlist\fR .fi .LP @@ -81,7 +82,6 @@ ptime \- proc tools .fi .SH DESCRIPTION -.sp .LP The proc tools are utilities that exercise features of \fB/proc\fR (see \fBproc\fR(4)). Most of them take a list of process-ids (\fIpid\fR). The tools @@ -215,12 +215,14 @@ Time the \fIcommand\fR, like \fBtime\fR(1), but using microstate accounting for reproducible precision. Unlike \fBtime\fR(1), children of the command are not timed. .sp -If the \fB-p\fR \fIpid\fR version is used, display a snapshot of timing -statistics for the specified \fIpid\fR. +If the \fB-p\fR \fIpidlist\fR version is used, display a snapshot of timing +statistics for the specified processes. The \fIpidlist\fR may have a single +process or be a comma or space delineated list. If a space delineated list is +used, callers will need to ensure that it is properly quoted or escaped for +their shell. .RE .SH OPTIONS -.sp .LP The following general options are supported: .sp @@ -452,7 +454,6 @@ privilege to change its user and group ids to those specified according to the rules laid out in \fBsetuid\fR(2) and it must have sufficient privilege to control the target process. .SH USAGE -.sp .LP These proc tools stop their target processes while inspecting them and reporting the results: \fBpfiles\fR, \fBpldd\fR, and \fBpstack\fR. A process @@ -488,7 +489,6 @@ release, the run-time link-editor debugging interface (\fBlibrtld_db\fR) cannot be able to initialize. In this case, symbol information for shared libraries is not available. .SH EXIT STATUS -.sp .LP The following exit values are returned: .sp @@ -510,7 +510,6 @@ An error has occurred. .RE .SH FILES -.sp .ne 2 .na \fB\fB/proc/*\fR\fR @@ -520,7 +519,6 @@ process files .RE .SH ATTRIBUTES -.sp .LP See \fBattributes\fR(5) for descriptions of the following attributes: .sp @@ -539,7 +537,6 @@ Interface Stability See below. .LP The human readable output is Uncommitted. The options are Committed. .SH SEE ALSO -.sp .LP \fBgcore\fR(1), \fBldd\fR(1), \fBpargs\fR(1), \fBpgrep\fR(1), \fBpkill\fR(1), \fBplimit\fR(1), \fBpmap\fR(1), \fBpreap\fR(1), \fBps\fR(1), \fBptree\fR(1), @@ -548,7 +545,6 @@ The human readable output is Uncommitted. The options are Committed. \fBdlopen\fR(3C), \fBsignal.h\fR(3HEAD), \fBcore\fR(4), \fBproc\fR(4), \fBprocess\fR(4), \fBattributes\fR(5), \fBzones\fR(5) .SH WARNINGS -.sp .LP The following \fBproc\fR tools stop their target processes while inspecting them and reporting the results: \fBpfiles\fR, \fBpldd\fR, and \fBpstack\fR. |