xref: /illumos-gate/usr/src/cmd/prstat/prstat.h (revision 0209230b)
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  */
21c6402783Sakolb 
227c478bd9Sstevel@tonic-gate /*
23c6402783Sakolb  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #ifndef	_PRSTAT_H
287c478bd9Sstevel@tonic-gate #define	_PRSTAT_H
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
337c478bd9Sstevel@tonic-gate #include <sys/time.h>
347c478bd9Sstevel@tonic-gate #include <sys/types.h>
357c478bd9Sstevel@tonic-gate #include <procfs.h>
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
387c478bd9Sstevel@tonic-gate extern "C" {
397c478bd9Sstevel@tonic-gate #endif
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate /*
427c478bd9Sstevel@tonic-gate  * FRC2PCT macro is used to convert 16-bit binary fractions in the range
437c478bd9Sstevel@tonic-gate  * 0.0 to 1.0 with binary point to the right of the high order bit
447c478bd9Sstevel@tonic-gate  * (i.e. 1.0 == 0x8000) to percentage value.
457c478bd9Sstevel@tonic-gate  */
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate #define	FRC2PCT(pp)	(((float)(pp))/0x8000*100)
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate #define	TIME2NSEC(__t)\
507c478bd9Sstevel@tonic-gate (hrtime_t)(((hrtime_t)__t.tv_sec * (hrtime_t)NANOSEC) + (hrtime_t)__t.tv_nsec)
517c478bd9Sstevel@tonic-gate #define	TIME2SEC(__t)\
527c478bd9Sstevel@tonic-gate (hrtime_t)(__t.tv_sec)
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate /*
557c478bd9Sstevel@tonic-gate  * List of available output modes
567c478bd9Sstevel@tonic-gate  */
577c478bd9Sstevel@tonic-gate #define	OPT_PSINFO	0x0001		/* read process's data from "psinfo" */
587c478bd9Sstevel@tonic-gate #define	OPT_LWPS	0x0002		/* report about all lwps */
597c478bd9Sstevel@tonic-gate #define	OPT_USERS	0x0004		/* report about most active users */
607c478bd9Sstevel@tonic-gate #define	OPT_UNUSED	0x0008		/* reserved for future use */
617c478bd9Sstevel@tonic-gate #define	OPT_REALTIME	0x0010		/* real-time scheduling class flag */
627c478bd9Sstevel@tonic-gate #define	OPT_MSACCT	0x0020		/* microstate accounting flag */
637c478bd9Sstevel@tonic-gate #define	OPT_TERMCAP	0x0040		/* use termcap data to move cursor */
647c478bd9Sstevel@tonic-gate #define	OPT_SPLIT	0x0080		/* split-screen mode flag */
657c478bd9Sstevel@tonic-gate #define	OPT_TTY		0x0100		/* report results to tty or file */
667c478bd9Sstevel@tonic-gate #define	OPT_FULLSCREEN	0x0200		/* full-screen mode flag */
677c478bd9Sstevel@tonic-gate #define	OPT_USEHOME	0x0400		/* use 'home' to move cursor up */
687c478bd9Sstevel@tonic-gate #define	OPT_TASKS	0x0800		/* report about system tasks */
697c478bd9Sstevel@tonic-gate #define	OPT_PROJECTS	0x1000		/* report about system projects */
707c478bd9Sstevel@tonic-gate #define	OPT_ZONES	0x2000		/* report about zones */
717c478bd9Sstevel@tonic-gate #define	OPT_PSETS	0x4000		/* report for specified psets */
72c6402783Sakolb #define	OPT_LGRP	0x8000		/* report home lgroups */
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate /*
757c478bd9Sstevel@tonic-gate  * Flags to keep track of process or lwp status
767c478bd9Sstevel@tonic-gate  */
777c478bd9Sstevel@tonic-gate #define	LWP_ALIVE	0x0008		/* this pid/lwp still exists */
787c478bd9Sstevel@tonic-gate #define	LWP_REPRESENT	0x0010		/* this LWP represents the process */
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate /*
817c478bd9Sstevel@tonic-gate  * Possible list types
827c478bd9Sstevel@tonic-gate  */
837c478bd9Sstevel@tonic-gate #define	LT_LWPS		0x0001
847c478bd9Sstevel@tonic-gate #define	LT_USERS	0x0002
857c478bd9Sstevel@tonic-gate #define	LT_TASKS	0x0004
867c478bd9Sstevel@tonic-gate #define	LT_PROJECTS	0x0008
877c478bd9Sstevel@tonic-gate #define	LT_ZONES	0x0010
88c6402783Sakolb #define	LT_LGRPS	0x0020
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate /*
917c478bd9Sstevel@tonic-gate  * Linked list of per-process or per-lwp statistics
927c478bd9Sstevel@tonic-gate  */
937c478bd9Sstevel@tonic-gate typedef struct lwp_info {
947c478bd9Sstevel@tonic-gate 	psinfo_t	li_info;	/* data read from psinfo file */
957c478bd9Sstevel@tonic-gate 	prusage_t	li_usage;	/* data read from usage file */
967c478bd9Sstevel@tonic-gate 	ulong_t		li_key;		/* value of the key for this lwp */
977c478bd9Sstevel@tonic-gate 	int		li_flags;	/* process/lwp flags */
987c478bd9Sstevel@tonic-gate 	float		li_usr;		/* user level CPU time */
997c478bd9Sstevel@tonic-gate 	float		li_sys;		/* system call CPU time */
1007c478bd9Sstevel@tonic-gate 	float		li_trp;		/* other system trap CPU time */
1017c478bd9Sstevel@tonic-gate 	float		li_tfl;		/* text page fault sleep time */
1027c478bd9Sstevel@tonic-gate 	float		li_dfl;		/* data page fault sleep time */
1037c478bd9Sstevel@tonic-gate 	float		li_lck;		/* user lock wait sleep time */
1047c478bd9Sstevel@tonic-gate 	float		li_slp;		/* all other sleep time */
1057c478bd9Sstevel@tonic-gate 	float		li_lat;		/* wait-cpu (latency) time */
1067c478bd9Sstevel@tonic-gate 	ulong_t		li_vcx;		/* voluntary context switches */
1077c478bd9Sstevel@tonic-gate 	ulong_t		li_icx;		/* involuntary context switches */
1087c478bd9Sstevel@tonic-gate 	ulong_t		li_scl;		/* system calls */
1097c478bd9Sstevel@tonic-gate 	ulong_t		li_sig;		/* received signals */
1107c478bd9Sstevel@tonic-gate 	struct lwp_info *li_next;	/* pointer to next lwp */
1117c478bd9Sstevel@tonic-gate 	struct lwp_info *li_prev;	/* pointer to previous lwp */
1127c478bd9Sstevel@tonic-gate } lwp_info_t;
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate /*
115c6402783Sakolb  * Linked list of collective per-uid, per-taskid, per-projid or per-lgroup
116c6402783Sakolb  * statistics
1177c478bd9Sstevel@tonic-gate  */
1187c478bd9Sstevel@tonic-gate typedef struct id_info {
1197c478bd9Sstevel@tonic-gate 	uid_t		id_uid;		/* user id */
1207c478bd9Sstevel@tonic-gate 	taskid_t	id_taskid;	/* task id */
1217c478bd9Sstevel@tonic-gate 	projid_t	id_projid;	/* project id */
1227c478bd9Sstevel@tonic-gate 	zoneid_t	id_zoneid;	/* zone id */
123c6402783Sakolb 	int		id_lgroup;	/* lgroup id */
1247c478bd9Sstevel@tonic-gate 	uint_t		id_nproc;	/* number of processes */
125*0209230bSgjelinek 	boolean_t	id_sizematch;	/* size/rssize from getvmusage() */
1267c478bd9Sstevel@tonic-gate 	size_t		id_size;	/* memory usage */
1277c478bd9Sstevel@tonic-gate 	size_t		id_rssize;	/* resident set size */
1287c478bd9Sstevel@tonic-gate 	ulong_t		id_time;	/* cpu time (in secs) */
1297c478bd9Sstevel@tonic-gate 	float		id_pctcpu;	/* percentage of cpu usage */
1307c478bd9Sstevel@tonic-gate 	float		id_pctmem;	/* percentage of memory usage */
1317c478bd9Sstevel@tonic-gate 	ulong_t		id_key;		/* sort key value */
1327c478bd9Sstevel@tonic-gate 	struct id_info *id_next;	/* pointer to next entry */
1337c478bd9Sstevel@tonic-gate 	struct id_info *id_prev;	/* pointer to previous entry */
1347c478bd9Sstevel@tonic-gate } id_info_t;
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate typedef	ulong_t	(*keyfunc_t)(void *);
1377c478bd9Sstevel@tonic-gate 
1387c478bd9Sstevel@tonic-gate /*
1397c478bd9Sstevel@tonic-gate  * Per-list structure
1407c478bd9Sstevel@tonic-gate  */
1417c478bd9Sstevel@tonic-gate typedef struct list {
1427c478bd9Sstevel@tonic-gate 	int		l_type;		/* list type */
1437c478bd9Sstevel@tonic-gate 	int		l_count;	/* number of entries in the list */
1447c478bd9Sstevel@tonic-gate 	void		*l_head;	/* pointer to the head of the list */
1457c478bd9Sstevel@tonic-gate 	void		*l_tail;	/* pointer to the tail of the list */
1467c478bd9Sstevel@tonic-gate 
1477c478bd9Sstevel@tonic-gate 	int		l_size;		/* number of allocated pointers */
1487c478bd9Sstevel@tonic-gate 	int		l_used;		/* number of used pointers */
1497c478bd9Sstevel@tonic-gate 	int		l_sortorder;	/* sorting order for the list */
1507c478bd9Sstevel@tonic-gate 	keyfunc_t	l_func;		/* pointer to key function */
1517c478bd9Sstevel@tonic-gate 	void		**l_ptrs;	/* pointer to an array of pointers */
1527c478bd9Sstevel@tonic-gate } list_t;
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate /*
1557c478bd9Sstevel@tonic-gate  * Command line options
1567c478bd9Sstevel@tonic-gate  */
1577c478bd9Sstevel@tonic-gate typedef	struct optdesc {
1587c478bd9Sstevel@tonic-gate 	int		o_interval;	/* interval between updates */
1597c478bd9Sstevel@tonic-gate 	int		o_ntop;		/* number of lines in top half */
1607c478bd9Sstevel@tonic-gate 	int		o_nbottom;	/* number of lines in bottom half */
1617c478bd9Sstevel@tonic-gate 	int		o_count;	/* number of iterations */
1627c478bd9Sstevel@tonic-gate 	int		o_outpmode;	/* selected output mode */
1637c478bd9Sstevel@tonic-gate 	int		o_sortorder;	/* +1 ascending, -1 descending */
1647c478bd9Sstevel@tonic-gate } optdesc_t;
1657c478bd9Sstevel@tonic-gate 
1667c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1677c478bd9Sstevel@tonic-gate }
1687c478bd9Sstevel@tonic-gate #endif
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate #endif	/* _PRSTAT_H */
171