From owner-svn-src-head@FreeBSD.ORG Sat Aug 21 13:54:34 2010 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 42A9A10656A5; Sat, 21 Aug 2010 13:54:34 +0000 (UTC) (envelope-from rpaulo@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 27B568FC13; Sat, 21 Aug 2010 13:54:34 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o7LDsY6K071128; Sat, 21 Aug 2010 13:54:34 GMT (envelope-from rpaulo@svn.freebsd.org) Received: (from rpaulo@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o7LDsYTd071125; Sat, 21 Aug 2010 13:54:34 GMT (envelope-from rpaulo@svn.freebsd.org) Message-Id: <201008211354.o7LDsYTd071125@svn.freebsd.org> From: Rui Paulo Date: Sat, 21 Aug 2010 13:54:34 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r211562 - in head/cddl: contrib/opensolaris/cmd/plockstat usr.sbin/plockstat X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 21 Aug 2010 13:54:34 -0000 Author: rpaulo Date: Sat Aug 21 13:54:33 2010 New Revision: 211562 URL: http://svn.freebsd.org/changeset/base/211562 Log: Port plockstat to FreeBSD. This will be connected to the build later. Sponsored by: The FreeBSD Foundation Added: head/cddl/usr.sbin/plockstat/ head/cddl/usr.sbin/plockstat/Makefile (contents, props changed) Modified: head/cddl/contrib/opensolaris/cmd/plockstat/plockstat.c Modified: head/cddl/contrib/opensolaris/cmd/plockstat/plockstat.c ============================================================================== --- head/cddl/contrib/opensolaris/cmd/plockstat/plockstat.c Sat Aug 21 13:48:04 2010 (r211561) +++ head/cddl/contrib/opensolaris/cmd/plockstat/plockstat.c Sat Aug 21 13:54:33 2010 (r211562) @@ -24,7 +24,9 @@ * Use is subject to license terms. */ +#if defined(sun) #pragma ident "%Z%%M% %I% %E% SMI" +#endif #include #include @@ -41,6 +43,7 @@ #include #include #include +#include static char *g_pname; static dtrace_hdl_t *g_dtp; @@ -502,7 +505,12 @@ getsym(struct ps_prochandle *P, uintptr_ { char name[256]; GElf_Sym sym; +#if defined(sun) prsyminfo_t info; +#else + prmap_t *map; + int info; /* XXX unused */ +#endif size_t len; if (P == NULL || Pxlookup_by_addr(P, addr, name, sizeof (name), @@ -510,6 +518,7 @@ getsym(struct ps_prochandle *P, uintptr_ (void) snprintf(buf, size, "%#lx", addr); return (0); } +#if defined(sun) if (info.prs_object == NULL) info.prs_object = ""; @@ -520,15 +529,19 @@ getsym(struct ps_prochandle *P, uintptr_ } len = snprintf(buf, size, "%s`%s", info.prs_object, info.prs_name); +#else + map = proc_addr2map(P, addr); + len = snprintf(buf, size, "%s`%s", map->pr_mapname, name); +#endif buf += len; size -= len; if (sym.st_value != addr) len = snprintf(buf, size, "+%#lx", addr - sym.st_value); - if (nolocks && strcmp("libc.so.1", info.prs_object) == 0 && - (strstr("mutex", info.prs_name) == 0 || - strstr("rw", info.prs_name) == 0)) + if (nolocks && strcmp("libc.so.1", map->pr_mapname) == 0 && + (strstr("mutex", name) == 0 || + strstr("rw", name) == 0)) return (-1); return (0); @@ -655,8 +668,13 @@ process_aggregate(const dtrace_aggdata_t static void prochandler(struct ps_prochandle *P, const char *msg, void *arg) { +#if defined(sun) const psinfo_t *prp = Ppsinfo(P); int pid = Pstatus(P)->pr_pid; +#else + int pid = proc_getpid(P); + int wstat = proc_getwstat(P); +#endif char name[SIG2STR_MAX]; if (msg != NULL) { @@ -674,13 +692,13 @@ prochandler(struct ps_prochandle *P, con * When /proc provides a stable pr_wstat in the status file, * this code can be improved by examining this new pr_wstat. */ - if (prp != NULL && WIFSIGNALED(prp->pr_wstat)) { + if (WIFSIGNALED(wstat)) { notice("pid %d terminated by %s\n", pid, - proc_signame(WTERMSIG(prp->pr_wstat), + proc_signame(WTERMSIG(wstat), name, sizeof (name))); - } else if (prp != NULL && WEXITSTATUS(prp->pr_wstat) != 0) { + } else if (WEXITSTATUS(wstat) != 0) { notice("pid %d exited with status %d\n", - pid, WEXITSTATUS(prp->pr_wstat)); + pid, WEXITSTATUS(wstat)); } else { notice("pid %d has exited\n", pid); } @@ -755,7 +773,9 @@ intr(int signo) int main(int argc, char **argv) { +#if defined(sun) ucred_t *ucp; +#endif int err; int opt_C = 0, opt_H = 0, opt_p = 0, opt_v = 0; char c, *p, *end; @@ -764,7 +784,7 @@ main(int argc, char **argv) g_pname = basename(argv[0]); argv[0] = g_pname; /* rewrite argv[0] for getopt errors */ - +#if defined(sun) /* * Make sure we have the required dtrace_proc privilege. */ @@ -777,6 +797,7 @@ main(int argc, char **argv) ucred_free(ucp); } +#endif while ((c = getopt(argc, argv, PLOCKSTAT_OPTSTR)) != EOF) { switch (c) { @@ -907,7 +928,7 @@ main(int argc, char **argv) if (opt_H) { dprog_add(g_hold_init); - if (g_opt_s == NULL) + if (!g_opt_s) dprog_add(g_hold_times); else dprog_add(g_hold_histogram); @@ -915,7 +936,7 @@ main(int argc, char **argv) if (opt_C) { dprog_add(g_ctnd_init); - if (g_opt_s == NULL) + if (!g_opt_s) dprog_add(g_ctnd_times); else dprog_add(g_ctnd_histogram); @@ -941,7 +962,7 @@ main(int argc, char **argv) if ((g_pr = dtrace_proc_grab(g_dtp, (pid_t)pid, 0)) == NULL) dfatal(NULL); } else { - if ((g_pr = dtrace_proc_create(g_dtp, argv[0], argv)) == NULL) + if ((g_pr = dtrace_proc_create(g_dtp, argv[0], argv, NULL, NULL)) == NULL) dfatal(NULL); } @@ -966,7 +987,11 @@ main(int argc, char **argv) if (opt_v) (void) printf("%s: tracing enabled for pid %d\n", g_pname, +#if defined(sun) (int)Pstatus(g_pr)->pr_pid); +#else + (int)proc_getpid(g_pr)); +#endif do { if (!g_intr && !done) Added: head/cddl/usr.sbin/plockstat/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/cddl/usr.sbin/plockstat/Makefile Sat Aug 21 13:54:33 2010 (r211562) @@ -0,0 +1,27 @@ +# $FreeBSD$ + +.PATH: ${.CURDIR}/../../../cddl/contrib/opensolaris/cmd/plockstat + +PROG= plockstat +NO_MAN= +SRCS= plockstat.c +BINDIR?= /usr/sbin + +WARNS?= 1 + +CFLAGS+= -I${.CURDIR}/../../../sys/cddl/compat/opensolaris \ + -I${.CURDIR}/../../../cddl/compat/opensolaris/include \ + -I${OPENSOLARIS_USR_DISTDIR}/head \ + -I${OPENSOLARIS_USR_DISTDIR}/lib/libdtrace/common \ + -I${OPENSOLARIS_USR_DISTDIR}/lib/libproc/common \ + -I${OPENSOLARIS_SYS_DISTDIR}/uts/common \ + -I${OPENSOLARIS_SYS_DISTDIR}/compat \ + -I${.CURDIR}/../../../cddl/lib/libdtrace \ + -I${.CURDIR}/../../../sys + +DPADD= ${LIBPTHREAD} ${LIBDTRACE} ${LIBY} ${LIBL} ${LIBPROC} ${LIBCTF}\ + ${LIBELF} ${LIBZ} ${LIBRT} ${LIBRTLD_DB} ${LIBUTIL} +LDADD= -lpthread -ldtrace -ly -ll -lproc -lctf -lelf -lz -lrt \ + -lrtld_db -lutil + +.include