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