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