da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * CDDL HEADER START
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The contents of this file are subject to the terms of the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Common Development and Distribution License (the "License").
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * You may not use this file except in compliance with the License.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * See the License for the specific language governing permissions
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * and limitations under the License.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * When distributing Covered Code, include this CDDL HEADER in each
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * If applicable, add the following below this CDDL HEADER, with the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * fields enclosed by brackets "[]" replaced with your own identifying
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * information: Portions Copyright [yyyy] [name of copyright owner]
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * CDDL HEADER END
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smbstat: Server Message Block File System statistics
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * The statistics this CLI displays come from two sources:
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * 1) The kernel module 'smbsrv'.
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * 2) The SMB workers task queue statistics the task queue manager of Solaris
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * maintains.
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * The flow of the code is the following:
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * +----------------+
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * | Initialization |
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * +----------------+
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * +--------------------------*
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * | Take a snapshot the data | <--------+
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * +--------------------------+ |
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * +----------------------+ |
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * | Process the snapshot | |
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * +----------------------+ |
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * +------------------------------------+ |
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * | Print the result of the processing | |
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * +------------------------------------+ |
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * Yes --------------- |
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * +------------ < interval == 0 ? > |
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * | --------------- |
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * | +------------------------+ |
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * | | Sleep for the duration | ----------+
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * | | of the interval. |
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * | +------------------------+
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * +---------------------+
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * There are two sets of snapshots. One set for the smbsrv module and the other
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * for the task queue (SMB workers). Each set contains 2 snapshots. One is
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * labeled 'current' the other one 'previous'. Their role changes after each
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * snapshot. The 'current' becomes 'previous' and vice versa.
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * The first snapshot taken is compared against the data gathered since the
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * smbsrv module was loaded. Subsequent snapshots will be compared against the
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * previous snapshot.
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright#endif /* TEXT_DOMAIN */
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright#define SMBSTAT_SNAPSHOT_COUNT 2 /* Must be a power of 2 */
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright#define SMBSTAT_SNAPSHOT_MASK (SMBSTAT_SNAPSHOT_COUNT - 1)
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright "Usage: smbstat [-acnrtuz] [interval]\n" \
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright " -c: display counters\n" \
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright " -t: display throughput\n" \
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright " -u: display utilization\n" \
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright " -r: display requests\n" \
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright " -a: all the requests (supported and unsupported)\n" \
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright " -z: skip the requests not received\n" \
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright " -n: display in alphabetic order\n" \
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright " interval: refresh cycle in seconds\n"
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright#define SMBSRV_COUNTERS_BANNER "\n nbt tcp users trees files pipes\n"
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright#define SMBSRV_COUNTERS_FORMAT "%5d %5d %5d %5d %5d %5d\n"
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright "\nrbytes/s tbytes/s reqs/s reads/s writes/s\n"
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright "%1.3e %1.3e %1.3e %1.3e %1.3e\n"
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright "\n wcnt rcnt wtime rtime" \
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright " w%% r%% u%% sat usr%% sys%% idle%%\n"
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright "%1.3e %1.3e %1.3e %1.3e %3.0f %3.0f %3.0f %s " \
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright "%3.0f %3.0f %3.0f\n"
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright "\n%30s code %% rbytes/s tbytes/s req/s rt-mean" \
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright " rt-stddev\n"
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright "%30s %02X %3.0f %1.3e %1.3e %1.3e %1.3e %1.3e\n"
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wrighttypedef enum {
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * Throughput of the server
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * Utilization of the server
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright double si_avw; /* Average number of requests waiting */
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright double si_avr; /* Average number of requests running */
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * Latency & Throughput per request
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2easstatic void smbstat_init(void);
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2easstatic void smbstat_fini(void);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wrightstatic void smbstat_kstat_snapshot(void);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wrightstatic void smbstat_kstat_process(void);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wrightstatic void smbstat_kstat_print(void);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wrightstatic void smbstat_print_counters(void);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wrightstatic void smbstat_print_throughput(void);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wrightstatic void smbstat_print_utilization(void);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wrightstatic void smbstat_print_requests(void);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wrightstatic void smbstat_cpu_init(void);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wrightstatic void smbstat_cpu_fini(void);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wrightstatic smbstat_cpu_snapshot_t *smbstat_cpu_current_snapshot(void);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wrightstatic smbstat_cpu_snapshot_t *smbstat_cpu_previous_snapshot(void);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wrightstatic void smbstat_cpu_snapshot(void);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wrightstatic void smbstat_cpu_process(void);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wrightstatic void smbstat_wrk_init(void);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wrightstatic void smbstat_wrk_fini(void);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wrightstatic void smbstat_wrk_snapshot(void);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wrightstatic void smbstat_wrk_process(void);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wrightstatic smbstat_wrk_snapshot_t *smbstat_wrk_current_snapshot(void);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wrightstatic void smbstat_srv_init(void);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wrightstatic void smbstat_srv_fini(void);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wrightstatic void smbstat_srv_snapshot(void);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wrightstatic void smbstat_srv_process(void);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wrightstatic void smbstat_srv_process_counters(smbstat_srv_snapshot_t *);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wrightstatic void smbstat_srv_process_throughput(smbstat_srv_snapshot_t *,
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wrightstatic void smbstat_srv_process_utilization(smbstat_srv_snapshot_t *,
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wrightstatic void smbstat_srv_process_requests(smbstat_srv_snapshot_t *,
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Rossstatic void smbstat_srv_process_one_req(smbstat_req_info_t *,
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross smb_kstat_req_t *, smb_kstat_req_t *, boolean_t);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wrightstatic smbstat_srv_snapshot_t *smbstat_srv_current_snapshot(void);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wrightstatic smbstat_srv_snapshot_t *smbstat_srv_previous_snapshot(void);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic void smbstat_fail(int, char *, ...);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wrightstatic void smbstat_snapshot_inc_idx(void);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wrightstatic uint_t smbstat_strtoi(char const *, char *);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wrightstatic double smbstat_hrtime_delta(hrtime_t, hrtime_t);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wrightstatic double smbstat_sub_64(uint64_t, uint64_t);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wrightstatic void smbstat_req_order(void);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wrightstatic double smbstat_zero(double);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wrightstatic void smbstat_termio_init(void);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright#pragma does_not_return(smbstat_fail, smbstat_usage)
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wrightstatic char *smbstat_cpu_states[CPU_TICKS_SENTINEL] = {
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright "cpu_ticks_idle",
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright "cpu_ticks_user",
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright "cpu_ticks_kernel"
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wrightstatic boolean_t smbstat_opt_a = B_FALSE; /* all */
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wrightstatic boolean_t smbstat_opt_c = B_FALSE; /* counters */
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wrightstatic boolean_t smbstat_opt_n = B_FALSE; /* by name */
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wrightstatic boolean_t smbstat_opt_u = B_FALSE; /* utilization */
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wrightstatic boolean_t smbstat_opt_t = B_FALSE; /* throughput */
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wrightstatic boolean_t smbstat_opt_r = B_FALSE; /* requests */
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wrightstatic boolean_t smbstat_opt_z = B_FALSE; /* non-zero requests */
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wrightstatic smbstat_cpu_snapshot_t *smbstat_cpu_snapshots[SMBSTAT_SNAPSHOT_COUNT];
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wrightstatic smbstat_srv_snapshot_t smbstat_srv_snapshots[SMBSTAT_SNAPSHOT_COUNT];
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wrightstatic smbstat_wrk_snapshot_t smbstat_wrk_snapshots[SMBSTAT_SNAPSHOT_COUNT];
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright while ((c = getopt(argc, argv, "achnrtuz")) != EOF) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw switch (c) {
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright /* Default options when none is specified. */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (0);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * smbstat_init
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * Global initialization.
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright smbstat_fail(1, gettext("kstat_open(): can't open /dev/kstat"));
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * smbstat_fini
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * Releases the resources smbstat_init() allocated.
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * smbstat_kstat_snapshot
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * Takes a snapshot of the data.
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * smbstat_kstat_process
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * smbstat_kstat_print
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * Print the data processed.
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * smbstat_print_counters
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * Displays the SMB server counters (session, users...).
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright if (smbstat_opt_u || smbstat_opt_r || smbstat_opt_t ||
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright (smbstat_rows == 0) || (smbstat_rows >= smbstat_ws.ws_row)) {
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * smbstat_print_throughput
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * Formats the SMB server throughput output.
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright if (smbstat_opt_u || smbstat_opt_r || smbstat_opt_c ||
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright (smbstat_rows == 0) || (smbstat_rows >= smbstat_ws.ws_row)) {
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * smbstat_print_utilization
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright if (smbstat_opt_t || smbstat_opt_r || smbstat_opt_c ||
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright (smbstat_rows == 0) || (smbstat_rows >= smbstat_ws.ws_row)) {
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * smbstat_print_requests
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic void
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright for (i = 0; i < SMB_COM_NUM; i++) {
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright strncmp(prq[i].ri_name, "Invalid", sizeof ("Invalid")) == 0)
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross for (i = 0; i < SMB2__NCMDS; i++) {
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * smbstat_cpu_init
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright size = smbstat_nrcpus * sizeof (smbstat_cpu_snapshot_t);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright for (i = 0; i < SMBSTAT_SNAPSHOT_COUNT; i++)
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright smbstat_cpu_snapshots[i] = smbstat_zalloc(size);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * smbstat_cpu_fini
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright size = smbstat_nrcpus * sizeof (smbstat_cpu_snapshot_t);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright for (i = 0; i < SMBSTAT_SNAPSHOT_COUNT; i++)
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * smbstat_cpu_current_snapshot
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright return (smbstat_cpu_snapshots[smbstat_snapshot_idx]);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * smbstat_cpu_previous_snapshot
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright idx = (smbstat_snapshot_idx - 1) & SMBSTAT_SNAPSHOT_MASK;
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * smbstat_cpu_snapshot
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright /* If no valid CPU is present, move on to the next one */
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright ksp = kstat_lookup(smbstat_ksc, "cpu", i, "sys");
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright gettext("kstat_lookup('cpu sys %d') failed"), i);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright for (j = 0; j < CPU_TICKS_SENTINEL; j++) {
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright ksn = kstat_data_lookup(ksp, smbstat_cpu_states[j]);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * smbstat_cpu_process
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic void
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright for (i = 0; i < smbstat_nrcpus; i++, curr++, prev++) {
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright for (j = 0; j < CPU_TICKS_SENTINEL; j++) {
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright agg_ticks[j] += smbstat_sub_64(curr->cs_ticks[j],
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright total_ticks += smbstat_sub_64(curr->cs_ticks[j],
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright for (j = 0; j < CPU_TICKS_SENTINEL; j++)
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * smbstat_wrk_init
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic void
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright kstat_lookup(smbstat_ksc, "unix", -1, SMBSRV_KSTAT_WORKERS);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright gettext("cannot retrieve smbsrv workers kstat\n"));
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * smbstat_wrk_snapshot
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright if (kstat_read(smbstat_ksc, smbstat_wrk_ksp, NULL) == -1)
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright smbstat_fail(1, gettext("kstat_read('%s') failed"),
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright kn = kstat_data_lookup(smbstat_wrk_ksp, "maxthreads");
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright if ((kn == NULL) || (kn->data_type != KSTAT_DATA_UINT64))
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright smbstat_fail(1, gettext("kstat_read('%s') failed"),
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright "maxthreads");
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright kn = kstat_data_lookup(smbstat_wrk_ksp, "bnalloc");
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright if ((kn == NULL) || (kn->data_type != KSTAT_DATA_UINT64))
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright smbstat_fail(1, gettext("kstat_read('%s') failed"),
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * smbstat_wrk_process
6537f381d2d9e7b4e2f7b29c3e7a3f13be036f2easstatic void
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * smbstat_wrk_current_snapshot
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright return (&smbstat_wrk_snapshots[smbstat_snapshot_idx]);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * smbstat_srv_init
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright smbstat_srv_ksp = kstat_lookup(smbstat_ksc, SMBSRV_KSTAT_MODULE,
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright smbstat_fail(1, gettext("cannot retrieve smbsrv kstat\n"));
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * smbstat_srv_fini
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * smbstat_srv_snapshot
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * Take a snapshot of the smbsrv module statistics.
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright if ((kstat_read(smbstat_ksc, smbstat_srv_ksp, NULL) == -1) ||
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright (smbstat_srv_ksp->ks_data_size != sizeof (curr->ss_data)))
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright smbstat_fail(1, gettext("kstat_read('%s') failed"),
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright curr->ss_snaptime = smbstat_srv_ksp->ks_snaptime;
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright bcopy(smbstat_srv_ksp->ks_data, &curr->ss_data, sizeof (curr->ss_data));
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * smbstat_srv_process
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * Processes the snapshot data.
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright smbstat_hrtime_delta(curr->ss_data.ks_start_time,
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright smbstat_hrtime_delta(prev->ss_snaptime, curr->ss_snaptime);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright smbstat_srv_info.si_etime = smbstat_srv_info.si_hretime / NANOSEC;
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright smbstat_sub_64(curr->ss_data.ks_nreq, prev->ss_data.ks_nreq);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * smbstat_srv_process_counters
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wrightsmbstat_srv_process_counters(smbstat_srv_snapshot_t *curr)
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright smbstat_srv_info.si_nbt_sess = curr->ss_data.ks_nbt_sess;
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright smbstat_srv_info.si_tcp_sess = curr->ss_data.ks_tcp_sess;
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright smbstat_srv_info.si_users = curr->ss_data.ks_users;
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright smbstat_srv_info.si_trees = curr->ss_data.ks_trees;
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright smbstat_srv_info.si_files = curr->ss_data.ks_files;
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright smbstat_srv_info.si_pipes = curr->ss_data.ks_pipes;
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * smbstat_srv_process_throughput
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * Processes the data relative to the throughput of the smbsrv module and
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * stores the results in the structure smbstat_srv_info.
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright smbstat_sub_64(curr->ss_data.ks_txb, prev->ss_data.ks_txb);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright smbstat_srv_info.si_tbs /= smbstat_srv_info.si_etime;
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright smbstat_sub_64(curr->ss_data.ks_rxb, prev->ss_data.ks_rxb);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright smbstat_srv_info.si_rbs /= smbstat_srv_info.si_etime;
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright smbstat_srv_info.si_rqs = smbstat_srv_info.si_total_nreqs;
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright smbstat_srv_info.si_rqs /= smbstat_srv_info.si_etime;
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross curr->ss_data.ks_reqs1[SMB_COM_LOCK_AND_READ].kr_nreq,
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross prev->ss_data.ks_reqs1[SMB_COM_LOCK_AND_READ].kr_nreq);
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross curr->ss_data.ks_reqs1[SMB_COM_READ_RAW].kr_nreq,
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross prev->ss_data.ks_reqs1[SMB_COM_READ_RAW].kr_nreq);
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross curr->ss_data.ks_reqs1[SMB_COM_READ_ANDX].kr_nreq,
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross prev->ss_data.ks_reqs1[SMB_COM_READ_ANDX].kr_nreq);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright smbstat_srv_info.si_rds /= smbstat_srv_info.si_etime;
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross curr->ss_data.ks_reqs1[SMB_COM_WRITE_AND_UNLOCK].kr_nreq,
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross prev->ss_data.ks_reqs1[SMB_COM_WRITE_AND_UNLOCK].kr_nreq);
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross curr->ss_data.ks_reqs1[SMB_COM_WRITE_RAW].kr_nreq,
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross prev->ss_data.ks_reqs1[SMB_COM_WRITE_RAW].kr_nreq);
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross curr->ss_data.ks_reqs1[SMB_COM_WRITE_AND_CLOSE].kr_nreq,
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross prev->ss_data.ks_reqs1[SMB_COM_WRITE_AND_CLOSE].kr_nreq);
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross curr->ss_data.ks_reqs1[SMB_COM_WRITE_ANDX].kr_nreq,
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross prev->ss_data.ks_reqs1[SMB_COM_WRITE_ANDX].kr_nreq);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright smbstat_srv_info.si_wrs /= smbstat_srv_info.si_etime;
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * smbstat_srv_process_utilization
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * Processes the data relative to the utilization of the smbsrv module and
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * stores the results in the structure smbstat_srv_info.
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright w_delta = smbstat_hrtime_delta(prev->ss_data.ks_utilization.ku_wlentime,
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright r_delta = smbstat_hrtime_delta(prev->ss_data.ks_utilization.ku_rlentime,
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright tw_delta = smbstat_hrtime_delta(prev->ss_data.ks_utilization.ku_wtime,
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright tr_delta = smbstat_hrtime_delta(prev->ss_data.ks_utilization.ku_rtime,
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright rqs = smbstat_srv_info.si_total_nreqs / smbstat_srv_info.si_etime;
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright /* Average number of requests waiting */
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright smbstat_srv_info.si_avw = w_delta / smbstat_srv_info.si_hretime;
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright /* Average number of request running */
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright smbstat_srv_info.si_avr = r_delta / smbstat_srv_info.si_hretime;
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright /* Utilization */
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright (smbstat_srv_info.si_avr / curr->ss_data.ks_maxreqs) * 100;
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright /* Average wait service time in milliseconds */
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright /* % of time there is a transaction waiting for service */
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright smbstat_srv_info.si_wpct /= smbstat_srv_info.si_hretime;
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright /* % of time there is a transaction running */
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright smbstat_srv_info.si_rpct /= smbstat_srv_info.si_hretime;
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * smbstat_srv_process_requests
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * Processes the data relative to the SMB requests and stores the results in
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * the structure smbstat_srv_info.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic void
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright for (i = 0; i < SMB_COM_NUM; i++) {
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross for (i = 0; i < SMB2__NCMDS; i++) {
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross info->ri_rqs = nrqs / smbstat_srv_info.si_etime;
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross info->ri_pct /= smbstat_srv_info.si_total_nreqs;
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross /* First time. Take the aggregate */
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross /* Take the differential */
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * smbstat_srv_current_snapshot
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * Returns the current snapshot.
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright return (&smbstat_srv_snapshots[smbstat_snapshot_idx]);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * smbstat_srv_previous_snapshot
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * Returns the previous snapshot.
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright idx = (smbstat_snapshot_idx - 1) & SMBSTAT_SNAPSHOT_MASK;
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * smbstat_usage
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * Prints out a help message.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic void
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * smbstat_fail
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * Prints out to stderr an error message and exits the process.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic void
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* LINTED E_SEC_PRINTF_VAR_FMT */
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * smbstat_sub_64
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * Substract 2 uint64_t and returns a double.
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wrightstatic double
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright return ((double)(a - b));
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * smbstat_zero
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * Returns zero if the value passed in is less than 1.
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wrightstatic double
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * smbstat_strtoi
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * Converts a string representing an integer value into its binary value.
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * If the conversion fails this routine exits the process.
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * smbstat_termio_init
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * Determines the size of the terminal associated with the process.
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &smbstat_ws) != -1) {
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * smbstat_snapshot_idx_inc
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * Increments the snapshot index.
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * smbstat_req_cmp_name
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * Call back function passed to qsort() when the list of requests must be sorted
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wrightsmbstat_req_cmp_name(const void *obj1, const void *obj2)
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright sizeof (((smbstat_req_info_t *)obj2)->ri_name)));
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * smbstat_req_order
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * Snapshots the smbsrv module statistics once to get the name of the requests.
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * The request list is smbstat_srv_info is then sorted by name or by code
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * depending on the boolean smbstat_opt_a.
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * The function should be called once during initialization.
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright for (i = 0; i < SMB_COM_NUM; i++) {
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright (void) strlcpy(info[i].ri_name, reqs[i].kr_name,
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright qsort(info, SMB_COM_NUM, sizeof (smbstat_req_info_t),
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross for (i = 0; i < SMB2__NCMDS; i++) {
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross (void) strlcpy(info[i].ri_name, reqs[i].kr_name,
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross qsort(info, SMB2__NCMDS, sizeof (smbstat_req_info_t),
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * Return the number of ticks delta between two hrtime_t
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * values. Attempt to cater for various kinds of overflow
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * in hrtime_t - no matter how improbable.
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wrightstatic double
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * We've overflowed the positive portion of an hrtime_t.
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * The new value is negative. Handle the case where the old
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * value is positive or negative.
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright return ((double)del);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * Either we've just gone from being negative to positive *or* the last
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * entry was positive and the new entry is also positive but *less* than
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * the old entry. This implies we waited quite a few days on a very fast
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * system between displays.
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright return ((double)del);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wrightstatic void *