xref: /onnv-gate/usr/src/cmd/prstat/prstat.h (revision 9966:d4ba9662e3c8)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
52685Sakolb  * Common Development and Distribution License (the "License").
62685Sakolb  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
212685Sakolb 
220Sstevel@tonic-gate /*
239123Sjohn.levon@sun.com  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
25*9966SMenno.Lageman@Sun.COM  *
26*9966SMenno.Lageman@Sun.COM  * Portions Copyright 2009 Chad Mynhier
270Sstevel@tonic-gate  */
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #ifndef	_PRSTAT_H
300Sstevel@tonic-gate #define	_PRSTAT_H
310Sstevel@tonic-gate 
320Sstevel@tonic-gate #include <sys/sysmacros.h>
330Sstevel@tonic-gate #include <sys/time.h>
340Sstevel@tonic-gate #include <sys/types.h>
350Sstevel@tonic-gate #include <procfs.h>
360Sstevel@tonic-gate 
370Sstevel@tonic-gate #ifdef	__cplusplus
380Sstevel@tonic-gate extern "C" {
390Sstevel@tonic-gate #endif
400Sstevel@tonic-gate 
410Sstevel@tonic-gate /*
420Sstevel@tonic-gate  * FRC2PCT macro is used to convert 16-bit binary fractions in the range
430Sstevel@tonic-gate  * 0.0 to 1.0 with binary point to the right of the high order bit
440Sstevel@tonic-gate  * (i.e. 1.0 == 0x8000) to percentage value.
450Sstevel@tonic-gate  */
460Sstevel@tonic-gate 
470Sstevel@tonic-gate #define	FRC2PCT(pp)	(((float)(pp))/0x8000*100)
480Sstevel@tonic-gate 
490Sstevel@tonic-gate #define	TIME2NSEC(__t)\
500Sstevel@tonic-gate (hrtime_t)(((hrtime_t)__t.tv_sec * (hrtime_t)NANOSEC) + (hrtime_t)__t.tv_nsec)
510Sstevel@tonic-gate #define	TIME2SEC(__t)\
520Sstevel@tonic-gate (hrtime_t)(__t.tv_sec)
530Sstevel@tonic-gate 
540Sstevel@tonic-gate /*
550Sstevel@tonic-gate  * List of available output modes
560Sstevel@tonic-gate  */
570Sstevel@tonic-gate #define	OPT_PSINFO	0x0001		/* read process's data from "psinfo" */
580Sstevel@tonic-gate #define	OPT_LWPS	0x0002		/* report about all lwps */
590Sstevel@tonic-gate #define	OPT_USERS	0x0004		/* report about most active users */
600Sstevel@tonic-gate #define	OPT_UNUSED	0x0008		/* reserved for future use */
610Sstevel@tonic-gate #define	OPT_REALTIME	0x0010		/* real-time scheduling class flag */
620Sstevel@tonic-gate #define	OPT_MSACCT	0x0020		/* microstate accounting flag */
630Sstevel@tonic-gate #define	OPT_TERMCAP	0x0040		/* use termcap data to move cursor */
640Sstevel@tonic-gate #define	OPT_SPLIT	0x0080		/* split-screen mode flag */
650Sstevel@tonic-gate #define	OPT_TTY		0x0100		/* report results to tty or file */
660Sstevel@tonic-gate #define	OPT_FULLSCREEN	0x0200		/* full-screen mode flag */
670Sstevel@tonic-gate #define	OPT_USEHOME	0x0400		/* use 'home' to move cursor up */
680Sstevel@tonic-gate #define	OPT_TASKS	0x0800		/* report about system tasks */
690Sstevel@tonic-gate #define	OPT_PROJECTS	0x1000		/* report about system projects */
700Sstevel@tonic-gate #define	OPT_ZONES	0x2000		/* report about zones */
710Sstevel@tonic-gate #define	OPT_PSETS	0x4000		/* report for specified psets */
722685Sakolb #define	OPT_LGRP	0x8000		/* report home lgroups */
739123Sjohn.levon@sun.com #define	OPT_UDATE	0x20000		/* print unix timestamp */
749123Sjohn.levon@sun.com #define	OPT_DDATE	0x40000		/* print timestamp in date(1) format */
75*9966SMenno.Lageman@Sun.COM #define	OPT_NORESOLVE	0x80000		/* no nsswitch lookups */
760Sstevel@tonic-gate 
770Sstevel@tonic-gate /*
780Sstevel@tonic-gate  * Flags to keep track of process or lwp status
790Sstevel@tonic-gate  */
800Sstevel@tonic-gate #define	LWP_ALIVE	0x0008		/* this pid/lwp still exists */
810Sstevel@tonic-gate #define	LWP_REPRESENT	0x0010		/* this LWP represents the process */
820Sstevel@tonic-gate 
830Sstevel@tonic-gate /*
840Sstevel@tonic-gate  * Possible list types
850Sstevel@tonic-gate  */
860Sstevel@tonic-gate #define	LT_LWPS		0x0001
870Sstevel@tonic-gate #define	LT_USERS	0x0002
880Sstevel@tonic-gate #define	LT_TASKS	0x0004
890Sstevel@tonic-gate #define	LT_PROJECTS	0x0008
900Sstevel@tonic-gate #define	LT_ZONES	0x0010
912685Sakolb #define	LT_LGRPS	0x0020
920Sstevel@tonic-gate 
930Sstevel@tonic-gate /*
940Sstevel@tonic-gate  * Linked list of per-process or per-lwp statistics
950Sstevel@tonic-gate  */
960Sstevel@tonic-gate typedef struct lwp_info {
970Sstevel@tonic-gate 	psinfo_t	li_info;	/* data read from psinfo file */
980Sstevel@tonic-gate 	prusage_t	li_usage;	/* data read from usage file */
990Sstevel@tonic-gate 	ulong_t		li_key;		/* value of the key for this lwp */
1000Sstevel@tonic-gate 	int		li_flags;	/* process/lwp flags */
1010Sstevel@tonic-gate 	float		li_usr;		/* user level CPU time */
1020Sstevel@tonic-gate 	float		li_sys;		/* system call CPU time */
1030Sstevel@tonic-gate 	float		li_trp;		/* other system trap CPU time */
1040Sstevel@tonic-gate 	float		li_tfl;		/* text page fault sleep time */
1050Sstevel@tonic-gate 	float		li_dfl;		/* data page fault sleep time */
1060Sstevel@tonic-gate 	float		li_lck;		/* user lock wait sleep time */
1070Sstevel@tonic-gate 	float		li_slp;		/* all other sleep time */
1080Sstevel@tonic-gate 	float		li_lat;		/* wait-cpu (latency) time */
1090Sstevel@tonic-gate 	ulong_t		li_vcx;		/* voluntary context switches */
1100Sstevel@tonic-gate 	ulong_t		li_icx;		/* involuntary context switches */
1110Sstevel@tonic-gate 	ulong_t		li_scl;		/* system calls */
1120Sstevel@tonic-gate 	ulong_t		li_sig;		/* received signals */
1130Sstevel@tonic-gate 	struct lwp_info *li_next;	/* pointer to next lwp */
1140Sstevel@tonic-gate 	struct lwp_info *li_prev;	/* pointer to previous lwp */
1150Sstevel@tonic-gate } lwp_info_t;
1160Sstevel@tonic-gate 
1170Sstevel@tonic-gate /*
1182685Sakolb  * Linked list of collective per-uid, per-taskid, per-projid or per-lgroup
1192685Sakolb  * statistics
1200Sstevel@tonic-gate  */
1210Sstevel@tonic-gate typedef struct id_info {
1220Sstevel@tonic-gate 	uid_t		id_uid;		/* user id */
1230Sstevel@tonic-gate 	taskid_t	id_taskid;	/* task id */
1240Sstevel@tonic-gate 	projid_t	id_projid;	/* project id */
1250Sstevel@tonic-gate 	zoneid_t	id_zoneid;	/* zone id */
1262685Sakolb 	int		id_lgroup;	/* lgroup id */
1270Sstevel@tonic-gate 	uint_t		id_nproc;	/* number of processes */
1283247Sgjelinek 	boolean_t	id_sizematch;	/* size/rssize from getvmusage() */
1290Sstevel@tonic-gate 	size_t		id_size;	/* memory usage */
1300Sstevel@tonic-gate 	size_t		id_rssize;	/* resident set size */
1310Sstevel@tonic-gate 	ulong_t		id_time;	/* cpu time (in secs) */
1320Sstevel@tonic-gate 	float		id_pctcpu;	/* percentage of cpu usage */
1330Sstevel@tonic-gate 	float		id_pctmem;	/* percentage of memory usage */
1340Sstevel@tonic-gate 	ulong_t		id_key;		/* sort key value */
1350Sstevel@tonic-gate 	struct id_info *id_next;	/* pointer to next entry */
1360Sstevel@tonic-gate 	struct id_info *id_prev;	/* pointer to previous entry */
1370Sstevel@tonic-gate } id_info_t;
1380Sstevel@tonic-gate 
1390Sstevel@tonic-gate typedef	ulong_t	(*keyfunc_t)(void *);
1400Sstevel@tonic-gate 
1410Sstevel@tonic-gate /*
1420Sstevel@tonic-gate  * Per-list structure
1430Sstevel@tonic-gate  */
1440Sstevel@tonic-gate typedef struct list {
1450Sstevel@tonic-gate 	int		l_type;		/* list type */
1460Sstevel@tonic-gate 	int		l_count;	/* number of entries in the list */
1470Sstevel@tonic-gate 	void		*l_head;	/* pointer to the head of the list */
1480Sstevel@tonic-gate 	void		*l_tail;	/* pointer to the tail of the list */
1490Sstevel@tonic-gate 
1500Sstevel@tonic-gate 	int		l_size;		/* number of allocated pointers */
1510Sstevel@tonic-gate 	int		l_used;		/* number of used pointers */
1520Sstevel@tonic-gate 	int		l_sortorder;	/* sorting order for the list */
1530Sstevel@tonic-gate 	keyfunc_t	l_func;		/* pointer to key function */
1540Sstevel@tonic-gate 	void		**l_ptrs;	/* pointer to an array of pointers */
1550Sstevel@tonic-gate } list_t;
1560Sstevel@tonic-gate 
1570Sstevel@tonic-gate /*
1580Sstevel@tonic-gate  * Command line options
1590Sstevel@tonic-gate  */
1600Sstevel@tonic-gate typedef	struct optdesc {
1610Sstevel@tonic-gate 	int		o_interval;	/* interval between updates */
1620Sstevel@tonic-gate 	int		o_ntop;		/* number of lines in top half */
1630Sstevel@tonic-gate 	int		o_nbottom;	/* number of lines in bottom half */
1640Sstevel@tonic-gate 	int		o_count;	/* number of iterations */
1650Sstevel@tonic-gate 	int		o_outpmode;	/* selected output mode */
1660Sstevel@tonic-gate 	int		o_sortorder;	/* +1 ascending, -1 descending */
1670Sstevel@tonic-gate } optdesc_t;
1680Sstevel@tonic-gate 
1690Sstevel@tonic-gate #ifdef	__cplusplus
1700Sstevel@tonic-gate }
1710Sstevel@tonic-gate #endif
1720Sstevel@tonic-gate 
1730Sstevel@tonic-gate #endif	/* _PRSTAT_H */
174