kstat.h revision e633f2d79475b51f0a4d46972282225abf851733
/*
* 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 2006 Sun Microsystems, Inc. All rights reserved.
* Copyright 2013 David Hoeppner. All rights reserved.
* Copyright 2013 Nexenta Systems, Inc. All rights reserved.
*/
#ifndef _STAT_KSTAT_H
#define _STAT_KSTAT_H
/*
* Structures needed by the kstat reader functions.
*/
#include <regex.h>
#include <nfs/nfs_clnt.h>
#ifdef __sparc
#include <vm/hat_sfmmu.h>
#include <sys/simmstat.h>
#endif
typedef union ks_value {
char c[16];
struct {
union {
char *ptr;
char __pad[8];
} addr;
} str;
} ks_value_t;
#define SAVE_HRTIME(I, S, N) \
{ \
ks_value_t v; \
v.ui64 = S->N; \
nvpair_insert(I, #N, &v, KSTAT_DATA_UINT64); \
}
#define SAVE_INT32(I, S, N) \
{ \
ks_value_t v; \
v.i32 = S->N; \
nvpair_insert(I, #N, &v, KSTAT_DATA_INT32); \
}
#define SAVE_UINT32(I, S, N) \
{ \
ks_value_t v; \
v.ui32 = S->N; \
nvpair_insert(I, #N, &v, KSTAT_DATA_UINT32); \
}
#define SAVE_INT64(I, S, N) \
{ \
ks_value_t v; \
v.i64 = S->N; \
nvpair_insert(I, #N, &v, KSTAT_DATA_INT64); \
}
#define SAVE_UINT64(I, S, N) \
{ \
ks_value_t v; \
v.ui64 = S->N; \
nvpair_insert(I, #N, &v, KSTAT_DATA_UINT64); \
}
/*
* We dont want const "strings" because we free
* the instances later.
*/
#define SAVE_STRING(I, S, N) \
{ \
ks_value_t v; \
nvpair_insert(I, #N, &v, KSTAT_DATA_STRING); \
}
#define SAVE_HRTIME_X(I, N, V) \
{ \
ks_value_t v; \
v.ui64 = V; \
nvpair_insert(I, N, &v, KSTAT_DATA_HRTIME); \
}
#define SAVE_INT32_X(I, N, V) \
{ \
ks_value_t v; \
v.i32 = V; \
nvpair_insert(I, N, &v, KSTAT_DATA_INT32); \
}
#define SAVE_UINT32_X(I, N, V) \
{ \
ks_value_t v; \
v.ui32 = V; \
nvpair_insert(I, N, &v, KSTAT_DATA_UINT32); \
}
#define SAVE_UINT64_X(I, N, V) \
{ \
ks_value_t v; \
v.ui64 = V; \
nvpair_insert(I, N, &v, KSTAT_DATA_UINT64); \
}
#define SAVE_STRING_X(I, N, V) \
{ \
ks_value_t v; \
nvpair_insert(I, N, &v, KSTAT_DATA_STRING); \
}
#define SAVE_CHAR_X(I, N, V) \
{ \
ks_value_t v; \
nvpair_insert(I, N, &v, KSTAT_DATA_STRING); \
}
#define DFLT_FMT \
"module: %-30.30s instance: %-6d\n" \
"name: %-30.30s class: %-.30s\n"
#define JSON_FMT \
"{\n\t\"module\": \"%s\",\n" \
"\t\"instance\": %d,\n" \
"\t\"name\": \"%s\",\n" \
"\t\"class\": \"%s\",\n" \
"\t\"type\": %d,\n"
#define KS_DFMT "\t%-30s "
#define KS_JFMT "\t\t\"%s\": "
#define KS_PFMT "%s:%d:%s:%s"
typedef struct ks_instance {
char ks_name[KSTAT_STRLEN];
char ks_module[KSTAT_STRLEN];
char ks_class[KSTAT_STRLEN];
int ks_instance;
typedef struct ks_nvpair {
char name[KSTAT_STRLEN];
} ks_nvpair_t;
typedef struct ks_pattern {
char *pstr;
} ks_pattern_t;
typedef struct ks_selector {
static void usage(void);
static ks_selector_t *new_selector(void);
static void ks_instances_read(kstat_ctl_t *);
static void ks_value_print(ks_nvpair_t *);
static void ks_instances_print(void);
static char *ks_safe_strdup(char *);
/* Raw kstat readers */
#ifdef __sparc
/* Helper function for save_temperature() */
static char *short_array_to_string(short *, int);
#endif
/* Named kstat readers */
/* Typedef for raw kstat reader functions */
static struct {
char *name;
} ks_raw_lookup[] = {
/* Function name kstat name */
{save_cpu_stat, "cpu_stat:cpu_stat"},
{save_var, "unix:var"},
{save_ncstats, "unix:ncstats"},
{save_sysinfo, "unix:sysinfo"},
{save_vminfo, "unix:vminfo"},
{save_nfs, "nfs:mntinfo"},
#ifdef __sparc
{save_sfmmu_global_stat, "unix:sfmmu_global_stat"},
{save_sfmmu_tsbsize_stat, "unix:sfmmu_tsbsize_stat"},
{save_simmstat, "unix:simm-status"},
{save_temperature, "unix:temperature"},
{save_temp_over, "unix:temperature override"},
{save_ps_shadow, "unix:ps_shadow"},
{save_fault_list, "unix:fault_list"},
#endif
};
static kstat_raw_reader_t lookup_raw_kstat_fn(char *, char *);
#endif /* _STAT_KSTAT_H */