xref: /illumos-gate/usr/src/cmd/prstat/prstat.h (revision 7c478bd9)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #ifndef	_PRSTAT_H
28*7c478bd9Sstevel@tonic-gate #define	_PRSTAT_H
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*7c478bd9Sstevel@tonic-gate 
32*7c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
33*7c478bd9Sstevel@tonic-gate #include <sys/time.h>
34*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
35*7c478bd9Sstevel@tonic-gate #include <procfs.h>
36*7c478bd9Sstevel@tonic-gate 
37*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
38*7c478bd9Sstevel@tonic-gate extern "C" {
39*7c478bd9Sstevel@tonic-gate #endif
40*7c478bd9Sstevel@tonic-gate 
41*7c478bd9Sstevel@tonic-gate /*
42*7c478bd9Sstevel@tonic-gate  * FRC2PCT macro is used to convert 16-bit binary fractions in the range
43*7c478bd9Sstevel@tonic-gate  * 0.0 to 1.0 with binary point to the right of the high order bit
44*7c478bd9Sstevel@tonic-gate  * (i.e. 1.0 == 0x8000) to percentage value.
45*7c478bd9Sstevel@tonic-gate  */
46*7c478bd9Sstevel@tonic-gate 
47*7c478bd9Sstevel@tonic-gate #define	FRC2PCT(pp)	(((float)(pp))/0x8000*100)
48*7c478bd9Sstevel@tonic-gate 
49*7c478bd9Sstevel@tonic-gate #define	TIME2NSEC(__t)\
50*7c478bd9Sstevel@tonic-gate (hrtime_t)(((hrtime_t)__t.tv_sec * (hrtime_t)NANOSEC) + (hrtime_t)__t.tv_nsec)
51*7c478bd9Sstevel@tonic-gate #define	TIME2SEC(__t)\
52*7c478bd9Sstevel@tonic-gate (hrtime_t)(__t.tv_sec)
53*7c478bd9Sstevel@tonic-gate 
54*7c478bd9Sstevel@tonic-gate /*
55*7c478bd9Sstevel@tonic-gate  * List of available output modes
56*7c478bd9Sstevel@tonic-gate  */
57*7c478bd9Sstevel@tonic-gate #define	OPT_PSINFO	0x0001		/* read process's data from "psinfo" */
58*7c478bd9Sstevel@tonic-gate #define	OPT_LWPS	0x0002		/* report about all lwps */
59*7c478bd9Sstevel@tonic-gate #define	OPT_USERS	0x0004		/* report about most active users */
60*7c478bd9Sstevel@tonic-gate #define	OPT_UNUSED	0x0008		/* reserved for future use */
61*7c478bd9Sstevel@tonic-gate #define	OPT_REALTIME	0x0010		/* real-time scheduling class flag */
62*7c478bd9Sstevel@tonic-gate #define	OPT_MSACCT	0x0020		/* microstate accounting flag */
63*7c478bd9Sstevel@tonic-gate #define	OPT_TERMCAP	0x0040		/* use termcap data to move cursor */
64*7c478bd9Sstevel@tonic-gate #define	OPT_SPLIT	0x0080		/* split-screen mode flag */
65*7c478bd9Sstevel@tonic-gate #define	OPT_TTY		0x0100		/* report results to tty or file */
66*7c478bd9Sstevel@tonic-gate #define	OPT_FULLSCREEN	0x0200		/* full-screen mode flag */
67*7c478bd9Sstevel@tonic-gate #define	OPT_USEHOME	0x0400		/* use 'home' to move cursor up */
68*7c478bd9Sstevel@tonic-gate #define	OPT_TASKS	0x0800		/* report about system tasks */
69*7c478bd9Sstevel@tonic-gate #define	OPT_PROJECTS	0x1000		/* report about system projects */
70*7c478bd9Sstevel@tonic-gate #define	OPT_ZONES	0x2000		/* report about zones */
71*7c478bd9Sstevel@tonic-gate #define	OPT_PSETS	0x4000		/* report for specified psets */
72*7c478bd9Sstevel@tonic-gate 
73*7c478bd9Sstevel@tonic-gate /*
74*7c478bd9Sstevel@tonic-gate  * Flags to keep track of process or lwp status
75*7c478bd9Sstevel@tonic-gate  */
76*7c478bd9Sstevel@tonic-gate #define	LWP_ALIVE	0x0008		/* this pid/lwp still exists */
77*7c478bd9Sstevel@tonic-gate #define	LWP_REPRESENT	0x0010		/* this LWP represents the process */
78*7c478bd9Sstevel@tonic-gate 
79*7c478bd9Sstevel@tonic-gate /*
80*7c478bd9Sstevel@tonic-gate  * Possible list types
81*7c478bd9Sstevel@tonic-gate  */
82*7c478bd9Sstevel@tonic-gate #define	LT_LWPS		0x0001
83*7c478bd9Sstevel@tonic-gate #define	LT_USERS	0x0002
84*7c478bd9Sstevel@tonic-gate #define	LT_TASKS	0x0004
85*7c478bd9Sstevel@tonic-gate #define	LT_PROJECTS	0x0008
86*7c478bd9Sstevel@tonic-gate #define	LT_ZONES	0x0010
87*7c478bd9Sstevel@tonic-gate 
88*7c478bd9Sstevel@tonic-gate /*
89*7c478bd9Sstevel@tonic-gate  * Linked list of per-process or per-lwp statistics
90*7c478bd9Sstevel@tonic-gate  */
91*7c478bd9Sstevel@tonic-gate typedef struct lwp_info {
92*7c478bd9Sstevel@tonic-gate 	psinfo_t	li_info;	/* data read from psinfo file */
93*7c478bd9Sstevel@tonic-gate 	prusage_t	li_usage;	/* data read from usage file */
94*7c478bd9Sstevel@tonic-gate 	ulong_t		li_key;		/* value of the key for this lwp */
95*7c478bd9Sstevel@tonic-gate 	int		li_flags;	/* process/lwp flags */
96*7c478bd9Sstevel@tonic-gate 	float		li_usr;		/* user level CPU time */
97*7c478bd9Sstevel@tonic-gate 	float		li_sys;		/* system call CPU time */
98*7c478bd9Sstevel@tonic-gate 	float		li_trp;		/* other system trap CPU time */
99*7c478bd9Sstevel@tonic-gate 	float		li_tfl;		/* text page fault sleep time */
100*7c478bd9Sstevel@tonic-gate 	float		li_dfl;		/* data page fault sleep time */
101*7c478bd9Sstevel@tonic-gate 	float		li_lck;		/* user lock wait sleep time */
102*7c478bd9Sstevel@tonic-gate 	float		li_slp;		/* all other sleep time */
103*7c478bd9Sstevel@tonic-gate 	float		li_lat;		/* wait-cpu (latency) time */
104*7c478bd9Sstevel@tonic-gate 	ulong_t		li_vcx;		/* voluntary context switches */
105*7c478bd9Sstevel@tonic-gate 	ulong_t		li_icx;		/* involuntary context switches */
106*7c478bd9Sstevel@tonic-gate 	ulong_t		li_scl;		/* system calls */
107*7c478bd9Sstevel@tonic-gate 	ulong_t		li_sig;		/* received signals */
108*7c478bd9Sstevel@tonic-gate 	struct lwp_info *li_next;	/* pointer to next lwp */
109*7c478bd9Sstevel@tonic-gate 	struct lwp_info *li_prev;	/* pointer to previous lwp */
110*7c478bd9Sstevel@tonic-gate } lwp_info_t;
111*7c478bd9Sstevel@tonic-gate 
112*7c478bd9Sstevel@tonic-gate /*
113*7c478bd9Sstevel@tonic-gate  * Linked list of collective per-uid, per-taskid, or per-projid statistics
114*7c478bd9Sstevel@tonic-gate  */
115*7c478bd9Sstevel@tonic-gate typedef struct id_info {
116*7c478bd9Sstevel@tonic-gate 	uid_t		id_uid;		/* user id */
117*7c478bd9Sstevel@tonic-gate 	taskid_t	id_taskid;	/* task id */
118*7c478bd9Sstevel@tonic-gate 	projid_t	id_projid;	/* project id */
119*7c478bd9Sstevel@tonic-gate 	zoneid_t	id_zoneid;	/* zone id */
120*7c478bd9Sstevel@tonic-gate 	uint_t		id_nproc;	/* number of processes */
121*7c478bd9Sstevel@tonic-gate 	size_t		id_size;	/* memory usage */
122*7c478bd9Sstevel@tonic-gate 	size_t		id_rssize;	/* resident set size */
123*7c478bd9Sstevel@tonic-gate 	ulong_t		id_time;	/* cpu time (in secs) */
124*7c478bd9Sstevel@tonic-gate 	float		id_pctcpu;	/* percentage of cpu usage */
125*7c478bd9Sstevel@tonic-gate 	float		id_pctmem;	/* percentage of memory usage */
126*7c478bd9Sstevel@tonic-gate 	ulong_t		id_key;		/* sort key value */
127*7c478bd9Sstevel@tonic-gate 	struct id_info *id_next;	/* pointer to next entry */
128*7c478bd9Sstevel@tonic-gate 	struct id_info *id_prev;	/* pointer to previous entry */
129*7c478bd9Sstevel@tonic-gate } id_info_t;
130*7c478bd9Sstevel@tonic-gate 
131*7c478bd9Sstevel@tonic-gate typedef	ulong_t	(*keyfunc_t)(void *);
132*7c478bd9Sstevel@tonic-gate 
133*7c478bd9Sstevel@tonic-gate /*
134*7c478bd9Sstevel@tonic-gate  * Per-list structure
135*7c478bd9Sstevel@tonic-gate  */
136*7c478bd9Sstevel@tonic-gate typedef struct list {
137*7c478bd9Sstevel@tonic-gate 	int		l_type;		/* list type */
138*7c478bd9Sstevel@tonic-gate 	int		l_count;	/* number of entries in the list */
139*7c478bd9Sstevel@tonic-gate 	void		*l_head;	/* pointer to the head of the list */
140*7c478bd9Sstevel@tonic-gate 	void		*l_tail;	/* pointer to the tail of the list */
141*7c478bd9Sstevel@tonic-gate 
142*7c478bd9Sstevel@tonic-gate 	int		l_size;		/* number of allocated pointers */
143*7c478bd9Sstevel@tonic-gate 	int		l_used;		/* number of used pointers */
144*7c478bd9Sstevel@tonic-gate 	int		l_sortorder;	/* sorting order for the list */
145*7c478bd9Sstevel@tonic-gate 	keyfunc_t	l_func;		/* pointer to key function */
146*7c478bd9Sstevel@tonic-gate 	void		**l_ptrs;	/* pointer to an array of pointers */
147*7c478bd9Sstevel@tonic-gate } list_t;
148*7c478bd9Sstevel@tonic-gate 
149*7c478bd9Sstevel@tonic-gate /*
150*7c478bd9Sstevel@tonic-gate  * Command line options
151*7c478bd9Sstevel@tonic-gate  */
152*7c478bd9Sstevel@tonic-gate typedef	struct optdesc {
153*7c478bd9Sstevel@tonic-gate 	int		o_interval;	/* interval between updates */
154*7c478bd9Sstevel@tonic-gate 	int		o_ntop;		/* number of lines in top half */
155*7c478bd9Sstevel@tonic-gate 	int		o_nbottom;	/* number of lines in bottom half */
156*7c478bd9Sstevel@tonic-gate 	int		o_count;	/* number of iterations */
157*7c478bd9Sstevel@tonic-gate 	int		o_outpmode;	/* selected output mode */
158*7c478bd9Sstevel@tonic-gate 	int		o_sortorder;	/* +1 ascending, -1 descending */
159*7c478bd9Sstevel@tonic-gate } optdesc_t;
160*7c478bd9Sstevel@tonic-gate 
161*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
162*7c478bd9Sstevel@tonic-gate }
163*7c478bd9Sstevel@tonic-gate #endif
164*7c478bd9Sstevel@tonic-gate 
165*7c478bd9Sstevel@tonic-gate #endif	/* _PRSTAT_H */
166