xref: /illumos-gate/usr/src/cmd/prstat/prstat.h (revision ab618543)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5c6402783Sakolb  * Common Development and Distribution License (the "License").
6c6402783Sakolb  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
230a1278f2SGary Mills  * Copyright (c) 2013 Gary Mills
240a1278f2SGary Mills  *
254944376cSJohn Levon  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
267c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
277166d658SMenno Lageman  *
287166d658SMenno Lageman  * Portions Copyright 2009 Chad Mynhier
29*ab618543SJohn Levon  * Copyright 2018 Joyent, Inc.  All rights reserved.
307c478bd9Sstevel@tonic-gate  */
327c478bd9Sstevel@tonic-gate #ifndef	_PRSTAT_H
337c478bd9Sstevel@tonic-gate #define	_PRSTAT_H
357c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
367c478bd9Sstevel@tonic-gate #include <sys/time.h>
377c478bd9Sstevel@tonic-gate #include <sys/types.h>
387c478bd9Sstevel@tonic-gate #include <procfs.h>
407c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
417c478bd9Sstevel@tonic-gate extern "C" {
427c478bd9Sstevel@tonic-gate #endif
447c478bd9Sstevel@tonic-gate /*
457c478bd9Sstevel@tonic-gate  * FRC2PCT macro is used to convert 16-bit binary fractions in the range
467c478bd9Sstevel@tonic-gate  * 0.0 to 1.0 with binary point to the right of the high order bit
477c478bd9Sstevel@tonic-gate  * (i.e. 1.0 == 0x8000) to percentage value.
487c478bd9Sstevel@tonic-gate  */
507c478bd9Sstevel@tonic-gate #define	FRC2PCT(pp)	(((float)(pp))/0x8000*100)
527c478bd9Sstevel@tonic-gate #define	TIME2NSEC(__t)\
537c478bd9Sstevel@tonic-gate (hrtime_t)(((hrtime_t)__t.tv_sec * (hrtime_t)NANOSEC) + (hrtime_t)__t.tv_nsec)
547c478bd9Sstevel@tonic-gate #define	TIME2SEC(__t)\
557c478bd9Sstevel@tonic-gate (hrtime_t)(__t.tv_sec)
577c478bd9Sstevel@tonic-gate /*
587c478bd9Sstevel@tonic-gate  * List of available output modes
597c478bd9Sstevel@tonic-gate  */
607c478bd9Sstevel@tonic-gate #define	OPT_PSINFO	0x0001		/* read process's data from "psinfo" */
617c478bd9Sstevel@tonic-gate #define	OPT_LWPS	0x0002		/* report about all lwps */
627c478bd9Sstevel@tonic-gate #define	OPT_USERS	0x0004		/* report about most active users */
637c478bd9Sstevel@tonic-gate #define	OPT_UNUSED	0x0008		/* reserved for future use */
647c478bd9Sstevel@tonic-gate #define	OPT_REALTIME	0x0010		/* real-time scheduling class flag */
657c478bd9Sstevel@tonic-gate #define	OPT_MSACCT	0x0020		/* microstate accounting flag */
667c478bd9Sstevel@tonic-gate #define	OPT_TERMCAP	0x0040		/* use termcap data to move cursor */
677c478bd9Sstevel@tonic-gate #define	OPT_SPLIT	0x0080		/* split-screen mode flag */
687c478bd9Sstevel@tonic-gate #define	OPT_TTY		0x0100		/* report results to tty or file */
697c478bd9Sstevel@tonic-gate #define	OPT_FULLSCREEN	0x0200		/* full-screen mode flag */
707c478bd9Sstevel@tonic-gate #define	OPT_USEHOME	0x0400		/* use 'home' to move cursor up */
717c478bd9Sstevel@tonic-gate #define	OPT_TASKS	0x0800		/* report about system tasks */
727c478bd9Sstevel@tonic-gate #define	OPT_PROJECTS	0x1000		/* report about system projects */
737c478bd9Sstevel@tonic-gate #define	OPT_ZONES	0x2000		/* report about zones */
747c478bd9Sstevel@tonic-gate #define	OPT_PSETS	0x4000		/* report for specified psets */
75c6402783Sakolb #define	OPT_LGRP	0x8000		/* report home lgroups */
764944376cSJohn Levon #define	OPT_UDATE	0x20000		/* print unix timestamp */
774944376cSJohn Levon #define	OPT_DDATE	0x40000		/* print timestamp in date(1) format */
787166d658SMenno Lageman #define	OPT_NORESOLVE	0x80000		/* no nsswitch lookups */
790a1278f2SGary Mills #define	OPT_TRUNC	0x100000	/* truncate long names */
817c478bd9Sstevel@tonic-gate /*
827c478bd9Sstevel@tonic-gate  * Flags to keep track of process or lwp status
837c478bd9Sstevel@tonic-gate  */
847c478bd9Sstevel@tonic-gate #define	LWP_ALIVE	0x0008		/* this pid/lwp still exists */
857c478bd9Sstevel@tonic-gate #define	LWP_REPRESENT	0x0010		/* this LWP represents the process */
877c478bd9Sstevel@tonic-gate /*
887c478bd9Sstevel@tonic-gate  * Possible list types
897c478bd9Sstevel@tonic-gate  */
907c478bd9Sstevel@tonic-gate #define	LT_LWPS		0x0001
917c478bd9Sstevel@tonic-gate #define	LT_USERS	0x0002
927c478bd9Sstevel@tonic-gate #define	LT_TASKS	0x0004
937c478bd9Sstevel@tonic-gate #define	LT_PROJECTS	0x0008
947c478bd9Sstevel@tonic-gate #define	LT_ZONES	0x0010
95c6402783Sakolb #define	LT_LGRPS	0x0020
977c478bd9Sstevel@tonic-gate /*
987c478bd9Sstevel@tonic-gate  * Linked list of per-process or per-lwp statistics
997c478bd9Sstevel@tonic-gate  */
1007c478bd9Sstevel@tonic-gate typedef struct lwp_info {
1017c478bd9Sstevel@tonic-gate 	psinfo_t	li_info;	/* data read from psinfo file */
1027c478bd9Sstevel@tonic-gate 	prusage_t	li_usage;	/* data read from usage file */
1037c478bd9Sstevel@tonic-gate 	ulong_t		li_key;		/* value of the key for this lwp */
1047c478bd9Sstevel@tonic-gate 	int		li_flags;	/* process/lwp flags */
1057c478bd9Sstevel@tonic-gate 	float		li_usr;		/* user level CPU time */
1067c478bd9Sstevel@tonic-gate 	float		li_sys;		/* system call CPU time */
1077c478bd9Sstevel@tonic-gate 	float		li_trp;		/* other system trap CPU time */
1087c478bd9Sstevel@tonic-gate 	float		li_tfl;		/* text page fault sleep time */
1097c478bd9Sstevel@tonic-gate 	float		li_dfl;		/* data page fault sleep time */
1107c478bd9Sstevel@tonic-gate 	float		li_lck;		/* user lock wait sleep time */
1117c478bd9Sstevel@tonic-gate 	float		li_slp;		/* all other sleep time */
1127c478bd9Sstevel@tonic-gate 	float		li_lat;		/* wait-cpu (latency) time */
1137c478bd9Sstevel@tonic-gate 	ulong_t		li_vcx;		/* voluntary context switches */
1147c478bd9Sstevel@tonic-gate 	ulong_t		li_icx;		/* involuntary context switches */
1157c478bd9Sstevel@tonic-gate 	ulong_t		li_scl;		/* system calls */
1167c478bd9Sstevel@tonic-gate 	ulong_t		li_sig;		/* received signals */
117*ab618543SJohn Levon 	char		li_lwpname[THREAD_NAME_MAX];
1187c478bd9Sstevel@tonic-gate 	struct lwp_info *li_next;	/* pointer to next lwp */
1197c478bd9Sstevel@tonic-gate 	struct lwp_info *li_prev;	/* pointer to previous lwp */
1207c478bd9Sstevel@tonic-gate } lwp_info_t;
1227c478bd9Sstevel@tonic-gate /*
123c6402783Sakolb  * Linked list of collective per-uid, per-taskid, per-projid or per-lgroup
124c6402783Sakolb  * statistics
1257c478bd9Sstevel@tonic-gate  */
1267c478bd9Sstevel@tonic-gate typedef struct id_info {
1277c478bd9Sstevel@tonic-gate 	uid_t		id_uid;		/* user id */
1287c478bd9Sstevel@tonic-gate 	taskid_t	id_taskid;	/* task id */
1297c478bd9Sstevel@tonic-gate 	projid_t	id_projid;	/* project id */
1307c478bd9Sstevel@tonic-gate 	zoneid_t	id_zoneid;	/* zone id */
131c6402783Sakolb 	int		id_lgroup;	/* lgroup id */
1327c478bd9Sstevel@tonic-gate 	uint_t		id_nproc;	/* number of processes */
1330209230bSgjelinek 	boolean_t	id_sizematch;	/* size/rssize from getvmusage() */
1347c478bd9Sstevel@tonic-gate 	size_t		id_size;	/* memory usage */
1357c478bd9Sstevel@tonic-gate 	size_t		id_rssize;	/* resident set size */
1367c478bd9Sstevel@tonic-gate 	ulong_t		id_time;	/* cpu time (in secs) */
1377c478bd9Sstevel@tonic-gate 	float		id_pctcpu;	/* percentage of cpu usage */
1387c478bd9Sstevel@tonic-gate 	float		id_pctmem;	/* percentage of memory usage */
1397c478bd9Sstevel@tonic-gate 	ulong_t		id_key;		/* sort key value */
1407c478bd9Sstevel@tonic-gate 	struct id_info *id_next;	/* pointer to next entry */
1417c478bd9Sstevel@tonic-gate 	struct id_info *id_prev;	/* pointer to previous entry */
1427c478bd9Sstevel@tonic-gate } id_info_t;
1447c478bd9Sstevel@tonic-gate typedef	ulong_t	(*keyfunc_t)(void *);
1467c478bd9Sstevel@tonic-gate /*
1477c478bd9Sstevel@tonic-gate  * Per-list structure
1487c478bd9Sstevel@tonic-gate  */
1497c478bd9Sstevel@tonic-gate typedef struct list {
1507c478bd9Sstevel@tonic-gate 	int		l_type;		/* list type */
1517c478bd9Sstevel@tonic-gate 	int		l_count;	/* number of entries in the list */
1527c478bd9Sstevel@tonic-gate 	void		*l_head;	/* pointer to the head of the list */
1537c478bd9Sstevel@tonic-gate 	void		*l_tail;	/* pointer to the tail of the list */
1557c478bd9Sstevel@tonic-gate 	int		l_size;		/* number of allocated pointers */
1567c478bd9Sstevel@tonic-gate 	int		l_used;		/* number of used pointers */
1577c478bd9Sstevel@tonic-gate 	int		l_sortorder;	/* sorting order for the list */
1587c478bd9Sstevel@tonic-gate 	keyfunc_t	l_func;		/* pointer to key function */
1597c478bd9Sstevel@tonic-gate 	void		**l_ptrs;	/* pointer to an array of pointers */
1607c478bd9Sstevel@tonic-gate } list_t;
1627c478bd9Sstevel@tonic-gate /*
1637c478bd9Sstevel@tonic-gate  * Command line options
1647c478bd9Sstevel@tonic-gate  */
1657c478bd9Sstevel@tonic-gate typedef	struct optdesc {
1667c478bd9Sstevel@tonic-gate 	int		o_interval;	/* interval between updates */
1677c478bd9Sstevel@tonic-gate 	int		o_ntop;		/* number of lines in top half */
1687c478bd9Sstevel@tonic-gate 	int		o_nbottom;	/* number of lines in bottom half */
1697c478bd9Sstevel@tonic-gate 	int		o_count;	/* number of iterations */
1707c478bd9Sstevel@tonic-gate 	int		o_outpmode;	/* selected output mode */
1717c478bd9Sstevel@tonic-gate 	int		o_sortorder;	/* +1 ascending, -1 descending */
172*ab618543SJohn Levon 	int		o_cols;		/* number of columns */
1737c478bd9Sstevel@tonic-gate } optdesc_t;
175*ab618543SJohn Levon extern optdesc_t opts;
176*ab618543SJohn Levon 
1777c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1787c478bd9Sstevel@tonic-gate }
1797c478bd9Sstevel@tonic-gate #endif
1817c478bd9Sstevel@tonic-gate #endif	/* _PRSTAT_H */