statcommon.h revision 4944376cd5de3dcd3b4feeaad9cbedbc024d1474
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
* Common routines for acquiring snapshots of kstats for
* iostat, mpstat, and vmstat.
*/
#ifndef _STATCOMMON_H
#define _STATCOMMON_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdio.h>
#include <kstat.h>
#include <sys/processor.h>
/* No CPU present at this CPU position */
#define ID_NO_CPU -1
/* CPU belongs to no pset (we number this as "pset 0") */
#define ID_NO_PSET 0
/* CPU is usable */
/* will the CPU have kstats */
/* IO device has no identified ID */
#define IODEV_NO_ID -1
/* no limit to iodevs to collect */
#define NODATE 0 /* Default: No time stamp */
enum snapshot_types {
/* All CPUs separately */
SNAP_CPUS = 1 << 0,
/* Aggregated processor sets */
/* sys-wide stats including aggregated CPU stats */
/* interrupt sources and counts */
/* cache flushes */
/* disk etc. stats */
/* disk controller aggregates */
/* mpxio L I (multipath) paths: -X: Lun,LunInitiator */
/* mpxio LTI (multipath) paths: -Y: Lun,LunTarget,LunTargetInitiator */
/* disk error stats */
/* pretty names for iodevs */
/* devid for iodevs */
};
struct cpu_snapshot {
/* may be ID_NO_CPU if no CPU present */
/* may be ID_NO_PSET if no pset */
/* as in p_online(2) */
int cs_state;
/* stats for this CPU */
};
struct pset_snapshot {
/* ID may be zero to indicate the "none set" */
/* number of CPUs in set */
/* the CPUs in this set */
struct cpu_snapshot **ps_cpus;
};
struct intr_snapshot {
/* name of interrupt source */
char is_name[KSTAT_STRLEN];
/* total number of interrupts from this source */
};
struct sys_snapshot {
/* ticks since boot */
long ss_deficit;
};
/* order is significant (see sort_before()) */
enum iodev_type {
IODEV_CONTROLLER = 1 << 0,
};
/* identify a disk, partition, etc. */
struct iodev_id {
int id;
/* target id (for disks) */
char tid[KSTAT_STRLEN];
};
/*
* Used for disks, partitions, tapes, nfs, controllers, iopaths
* Each entry can be a branch of a tree; for example, the disks
* of a controller constitute the children of the controller
* iodev_snapshot. This relationship is not strictly maintained
* if is_pretty can't be found.
*/
struct iodev_snapshot {
/* original kstat name */
char is_name[KSTAT_STRLEN];
/* type of kstat */
enum iodev_type is_type;
/* ID if meaningful */
/* parent ID if meaningful */
struct iodev_id is_parent_id;
/* user-friendly name if found */
char *is_pretty;
/* device ID if applicable */
char *is_devid;
/* mount-point if applicable */
char *is_dname;
/* number of direct children */
int is_nr_children;
/* children of this I/O device */
struct iodev_snapshot *is_children;
/* standard I/O stats */
/* iodev error stats */
/* creation time of the stats */
/* time at which iodev snapshot was taken */
/* kstat module */
char is_module[KSTAT_STRLEN];
/* kstat instance */
int is_instance;
/* kstat (only used temporarily) */
struct iodev_snapshot *is_prev;
struct iodev_snapshot *is_next;
/* AVL structures to speedup insertion */
};
/* which iodevs to show. */
struct iodev_filter {
/* nr. of iodevs to choose */
/* bit mask of enum io_types to allow */
int if_allowed_types;
/* should we show floppy ? if_names can override this */
int if_skip_floppy;
/* nr. of named iodevs */
char **if_names;
};
/* The primary structure of a system snapshot. */
struct snapshot {
/* what types were *requested* */
enum snapshot_types s_types;
struct cpu_snapshot *s_cpus;
struct pset_snapshot *s_psets;
struct intr_snapshot *s_intrs;
struct iodev_snapshot *s_iodevs;
struct sys_snapshot s_sys;
struct biostats s_biostats;
struct flushmeter s_flushes;
};
/* print a message and exit with failure */
/* strdup str, or exit with failure */
char *safe_strdup(char *str);
/* malloc successfully, or exit with failure */
/*
* Copy a kstat from src to dst. If the source kstat contains no data,
* then set the destination kstat data to NULL and size to zero.
* Returns 0 on success.
*/
/*
* Look up the named kstat, and give the ui64 difference i.e.
* new - old, or if old is NULL, return new.
*/
/* Return the number of ticks delta between two hrtime_t values. */
/*
* Add the integer-valued stats from "src" to the
* existing ones in "dst". If "dst" does not contain
* stats, then a kstat_copy() is performed.
*/
/* return the number of CPUs with kstats (i.e. present and online) */
/*
* Return the difference in CPU ticks between the two sys
* kstats.
*/
/*
* Open the kstat chain. Cannot fail.
*/
kstat_ctl_t *open_kstat(void);
/*
* Return a struct snapshot based on the snapshot_types parameter
* passed in. iodev_filter may be NULL in which case all iodevs
* are selected if SNAP_IODEVS is passed.
*/
/* free a snapshot */
/*
* Call the call back for each pair of data items of the given type,
* passing the data pointer passed in as well. If an item has been
* added, the first pointer will be NULL; if removed, the second pointer
* will be NULL.
*
* A non-zero return value indicates configuration has changed.
*/
/*
* Output a line detailing any configuration changes such as a CPU
* brought online, etc, bracketed by << >>.
*/
/* Return non-zero if configuration has changed. */
/* free the given iodev */
/* acquire the I/O devices */
struct iodev_filter *df);
/* strcmp-style I/O device comparator */
/* sleep until *wakeup + interval, keeping cadence where desired */
int *caught_cont);
/* signal handler - so we can be aware of SIGCONT */
void cont_handler(int sig_number);
/* Print a timestamp in either Unix or standard format. */
void print_timestamp(void);
#ifdef __cplusplus
}
#endif
#endif /* _STATCOMMON_H */