sdbc_stats.c revision fcf3ce441efd61da9bb2884968af01cb7c1452cc
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The contents of this file are subject to the terms of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Common Development and Distribution License (the "License").
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You may not use this file except in compliance with the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If applicable, add the following below this CDDL HEADER, with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid center(int, char *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbc_discover() - looks for new statistics to be monitored.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Verifies that any statistics found are now already being
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * monitored.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte static int validated = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ksp = kc->kc_chain; ksp; ksp = ksp->ks_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strcmp(ksp->ks_module, SDBC_KSTAT_MODULE) != 0 ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strncmp(ksp->ks_name, SDBC_KSTAT_CDSTATS, 2) != 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Validate kstat structure
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Duplicate check
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strncmp(cur_vname, tst_vname, NAMED_LEN) == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Initialize new record
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbcstat = (sdbcstat_t *)calloc(1, sizeof (sdbcstat_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sprintf(kname, "%s%d", SDBC_IOKSTAT_CDSTATS, kinst);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte io_ksp = kstat_lookup(kc, SDBC_KSTAT_MODULE, kinst, kname);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Check if we got a complete set of stats
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbc_update() - updates all of the statistics currently being monitored.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Update global kstat information */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ksp = kstat_lookup(kc, SDBC_KSTAT_MODULE, -1, SDBC_KSTAT_GSTATS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (cur = sdbc_top; cur != NULL; cur = cur->next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Age off old stats
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Update set kstat
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte set_ksp = kstat_lookup(kc, SDBC_KSTAT_MODULE, kinst, kname);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((cur->cur_set = kstat_retrieve(kc, set_ksp)) == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Validate set
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pname = kstat_value(cur->pre_set, SDBC_CDKSTAT_VOL_NAME);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cname = kstat_value(cur->cur_set, SDBC_CDKSTAT_VOL_NAME);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Update I/O kstat
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte io_ksp = kstat_lookup(kc, SDBC_KSTAT_MODULE, kinst, kname);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((cur->cur_io = kstat_retrieve(kc, io_ksp)) == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbc_report() - outputs statistics for the statistics currently being
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * monitored. Deletes statistics for volumes that have been disabled.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (cur = sdbc_top; cur != NULL; ) { /* CSTYLED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Parse volume name */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check to see if the user specified this volume */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (vslist = vs_top; vslist != NULL; vslist = vslist->next)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check if volume is offline and zflag applies */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Output volume name */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte offline = kstat_value(cur->cur_set, SDBC_CDKSTAT_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dhint = kstat_value(cur->cur_set, SDBC_CDKSTAT_CDHINTS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nhint = kstat_value(sdbc_global, SDBC_GKSTAT_NODEHINTS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hints &= (NSC_FORCED_WRTHRU | NSC_NO_FORCED_WRTHRU |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((hints & NSC_FORCED_WRTHRU) || (hints & NSC_WRTHRU))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Output set information */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbc_header() - outputs an appropriate header by referencing the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * global variables dflsgs
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* first line header */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* second line header */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbc_getstat() - find cache stat by name matching
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * paraemters
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * char *vn - the volume name to match against
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbcstat_t * - the matching strcture, NULL if not found
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_value(cur->pre_set, SDBC_CDKSTAT_VOL_NAME);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbc_addstat() - adds a fully populated sdbcstat_t structure
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to the linked list of currently monitored kstats. The structure
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * will be added in alphabetical order, using the volume name as the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * parameters
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbcstat_t *sdbcstat - to be added to the list.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (cur = sdbc_top; cur != NULL; cur = cur->next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strncmp(cur_vname, tst_vname, NAMED_LEN) > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If we get to the last item in the list, then just
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * add this one to the end
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strncmp(nxt_vname, tst_vname, NAMED_LEN) > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbc_delstat() - deallocate memory for the structure being
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * passed in.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * parameters
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbcstat_t *sdbcstat - structure to be deallocated
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbcstat_t * - pointer to the "next" structures in the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * linked list. May be NULL if we are removing the last
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * structure in the linked list.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbc_value_check() - Checks for activity, supports -z switch
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * parameters
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbcstat_t *sdbcstat - structure to be checked
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 1 - activity
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 - no activity
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_getdelta(sdbcstat, SDBC_CDKSTAT_CACHE_READ) != 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_getdelta(sdbcstat, SDBC_CDKSTAT_DISK_READ) != 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_getdelta(sdbcstat, SDBC_CDKSTAT_CACHE_WRITE) != 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_getdelta(sdbcstat, SDBC_CDKSTAT_DISK_WRITE) != 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_getdelta(sdbcstat, SDBC_CDKSTAT_WRCANCELNS) != 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbc_validate() - validates the structure of the kstats by attempting to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * lookup fields used by this module
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * parameters
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * kstat_t *ksp - kstat to be examined
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 1 - one or more fields missing
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 - all fields present
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbc_getvalues() - populates a values structure with data obtained from the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * parameters
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbcstat_t *sdbcstat - pointer to the structure containing the kstats
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbcvals_t *vals - pointer to the structure that will receive the values
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * int flags - flags that describe adjustments made to the values
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 1 - failure
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 - success
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_getvalues(sdbcstat_t *sdbcstat, sdbcvals_t *vals, int flags)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hr_etime = hrtime_delta(pre->rlastupdate, cur->rlastupdate);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* read data */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte FBA_SIZE(sdbc_getdelta(sdbcstat, SDBC_CDKSTAT_CACHE_READ));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte FBA_SIZE(sdbc_getdelta(sdbcstat, SDBC_CDKSTAT_DISK_READ));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vals->total_reads = vals->cache_read + vals->disk_read;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((float)vals->cache_read / vals->total_reads) * 100.0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* write data */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte FBA_SIZE(sdbc_getdelta(sdbcstat, SDBC_CDKSTAT_CACHE_WRITE));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte FBA_SIZE(sdbc_getdelta(sdbcstat, SDBC_CDKSTAT_DISK_WRITE));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vals->total_writes = vals->cache_write + vals->disk_write;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte FBA_SIZE(sdbc_getdelta(sdbcstat, SDBC_CDKSTAT_DESTAGED));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* miscellaneous */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte FBA_SIZE(sdbc_getdelta(sdbcstat, SDBC_CDKSTAT_WRCANCELNS));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vals->total_cache = vals->cache_read + vals->cache_write;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vals->total_disk = vals->disk_read + vals->disk_write;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* total cache hit calculation */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* adjustments */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbc_getdelta() - calculates the difference between two kstat fields
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * parameters
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbcstat_t *sdbcstat - the SDBC stat strcture containing the two fields
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * char *name - the name of the fields
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * uint32_t value of the differences adjusted for overflow of the data type
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sprintf(fmt, "%%%ds%%s%%%ds", lpad, rpad);