Print this page
10113 fmd_adm_xprt_f should return void


   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 




  27 #include <fm/fmd_adm.h>
  28 
  29 #include <strings.h>
  30 #include <limits.h>
  31 #include <stdlib.h>
  32 #include <stdarg.h>
  33 #include <stdio.h>
  34 #include <errno.h>
  35 #include <poll.h>
  36 #include <locale.h>
  37 
  38 #include "statcommon.h"
  39 
  40 #define FMSTAT_EXIT_SUCCESS     0
  41 #define FMSTAT_EXIT_ERROR       1
  42 #define FMSTAT_EXIT_USAGE       2
  43 
  44 static const struct stats {
  45         fmd_stat_t module;
  46         fmd_stat_t authority;


 356          * busy times, dividing by the elapsed time, and multiplying by 100.
 357          */
 358         delta = u64delta(old->wtime.fmds_value.ui64,
 359             new->wtime.fmds_value.ui64);
 360 
 361         if (delta != 0)
 362                 mp->m_pct_w = ((double)delta / elapsed) * 100.0;
 363         else
 364                 mp->m_pct_w = 0.0;
 365 
 366         delta = u64delta(old->dtime.fmds_value.ui64,
 367             new->dtime.fmds_value.ui64);
 368 
 369         if (delta != 0)
 370                 mp->m_pct_b = ((double)delta / elapsed) * 100.0;
 371         else
 372                 mp->m_pct_b = 0.0;
 373 }
 374 
 375 /*ARGSUSED*/
 376 static int
 377 stat_one_xprt(id_t id, void *ignored)
 378 {
 379         fmd_adm_stats_t ams;
 380         struct modstats *mp;
 381 
 382         if (fmd_adm_xprt_stats(g_adm, id, &ams) != 0) {
 383                 warn("failed to retrieve statistics for transport %d", (int)id);
 384                 return (0); /* continue on to the next transport */
 385         }
 386 
 387         for (mp = g_mods; mp != NULL; mp = mp->m_next) {
 388                 if (mp->m_id == id)
 389                         break;
 390         }
 391 
 392         if (mp == NULL && (mp = modstat_create(NULL, id)) == NULL) {
 393                 warn("failed to allocate memory for transport %d", (int)id);
 394                 (void) fmd_adm_stats_free(g_adm, &ams);
 395                 return (0);
 396         }
 397 
 398         modstat_compute(mp, &ams);
 399 
 400         (void) printf("%3d %5s %7llu %7llu %7llu %7llu "
 401             "%4.1f %6.1f %3.0f %3.0f %s\n", (int)id,
 402             mp->m_new->state.fmds_value.str,
 403             u64delta(mp->m_old->prdequeued.fmds_value.ui64,
 404             mp->m_new->prdequeued.fmds_value.ui64),
 405             u64delta(mp->m_old->received.fmds_value.ui64,
 406             mp->m_new->received.fmds_value.ui64),
 407             u64delta(mp->m_old->discarded.fmds_value.ui64,
 408             mp->m_new->discarded.fmds_value.ui64),
 409             u64delta(mp->m_old->lost.fmds_value.ui64,
 410             mp->m_new->lost.fmds_value.ui64),
 411             mp->m_wait, mp->m_svc, mp->m_pct_w, mp->m_pct_b,
 412             mp->m_new->module.fmds_value.str);
 413 
 414         (void) fmd_adm_stats_free(g_adm, &ams);
 415         return (0);
 416 }
 417 
 418 static void
 419 stat_xprt(void)
 420 {
 421         (void) printf("%3s %5s %7s %7s %7s %7s %4s %6s %3s %3s %s\n",
 422             "id", "state", "ev_send", "ev_recv", "ev_drop", "ev_lost",
 423             "wait", "svc_t", "%w", "%b", "module");
 424 
 425         if (fmd_adm_xprt_iter(g_adm, stat_one_xprt, NULL) != 0)
 426                 die("failed to retrieve list of transports");
 427 }
 428 
 429 static int
 430 stat_one_xprt_auth(id_t id, void *arg)
 431 {
 432         const char *module = arg;
 433         fmd_adm_stats_t ams;
 434         struct modstats *mp;
 435 
 436         if (fmd_adm_xprt_stats(g_adm, id, &ams) != 0) {
 437                 warn("failed to retrieve statistics for transport %d", (int)id);
 438                 return (0); /* continue on to the next transport */
 439         }
 440 
 441         for (mp = g_mods; mp != NULL; mp = mp->m_next) {
 442                 if (mp->m_id == id)
 443                         break;
 444         }
 445 
 446         if (mp == NULL && (mp = modstat_create(NULL, id)) == NULL) {
 447                 warn("failed to allocate memory for transport %d", (int)id);
 448                 (void) fmd_adm_stats_free(g_adm, &ams);
 449                 return (0);
 450         }
 451 
 452         modstat_compute(mp, &ams);
 453 
 454         if (module == NULL ||
 455             strcmp(module, mp->m_new->module.fmds_value.str) == 0) {
 456                 (void) printf("%3d %5s %-18s  %s\n", (int)id,
 457                     mp->m_new->state.fmds_value.str,
 458                     mp->m_new->module.fmds_value.str,
 459                     mp->m_new->authority.fmds_value.str ?
 460                     mp->m_new->authority.fmds_value.str : "-");
 461         }
 462 
 463         (void) fmd_adm_stats_free(g_adm, &ams);
 464         return (0);
 465 }
 466 
 467 static void
 468 stat_xprt_auth(const char *module)
 469 {
 470         (void) printf("%3s %5s %-18s  %s\n",
 471             "id", "state", "module", "authority");
 472 
 473         if (fmd_adm_xprt_iter(g_adm, stat_one_xprt_auth, (void *)module) != 0)
 474                 die("failed to retrieve list of transports");
 475 }
 476 
 477 /*ARGSUSED*/
 478 static int
 479 stat_one_fmd(const fmd_adm_modinfo_t *ami, void *ignored)
 480 {
 481         char memsz[8], bufsz[8];
 482         fmd_adm_stats_t ams;
 483         struct modstats *mp;
 484 




   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 /*
  28  * Copyright (c) 2018, Joyent, Inc.
  29  */
  30 
  31 #include <fm/fmd_adm.h>
  32 
  33 #include <strings.h>
  34 #include <limits.h>
  35 #include <stdlib.h>
  36 #include <stdarg.h>
  37 #include <stdio.h>
  38 #include <errno.h>
  39 #include <poll.h>
  40 #include <locale.h>
  41 
  42 #include "statcommon.h"
  43 
  44 #define FMSTAT_EXIT_SUCCESS     0
  45 #define FMSTAT_EXIT_ERROR       1
  46 #define FMSTAT_EXIT_USAGE       2
  47 
  48 static const struct stats {
  49         fmd_stat_t module;
  50         fmd_stat_t authority;


 360          * busy times, dividing by the elapsed time, and multiplying by 100.
 361          */
 362         delta = u64delta(old->wtime.fmds_value.ui64,
 363             new->wtime.fmds_value.ui64);
 364 
 365         if (delta != 0)
 366                 mp->m_pct_w = ((double)delta / elapsed) * 100.0;
 367         else
 368                 mp->m_pct_w = 0.0;
 369 
 370         delta = u64delta(old->dtime.fmds_value.ui64,
 371             new->dtime.fmds_value.ui64);
 372 
 373         if (delta != 0)
 374                 mp->m_pct_b = ((double)delta / elapsed) * 100.0;
 375         else
 376                 mp->m_pct_b = 0.0;
 377 }
 378 
 379 /*ARGSUSED*/
 380 static void
 381 stat_one_xprt(id_t id, void *ignored)
 382 {
 383         fmd_adm_stats_t ams;
 384         struct modstats *mp;
 385 
 386         if (fmd_adm_xprt_stats(g_adm, id, &ams) != 0) {
 387                 warn("failed to retrieve statistics for transport %d", (int)id);
 388                 return;
 389         }
 390 
 391         for (mp = g_mods; mp != NULL; mp = mp->m_next) {
 392                 if (mp->m_id == id)
 393                         break;
 394         }
 395 
 396         if (mp == NULL && (mp = modstat_create(NULL, id)) == NULL) {
 397                 warn("failed to allocate memory for transport %d", (int)id);
 398                 (void) fmd_adm_stats_free(g_adm, &ams);
 399                 return;
 400         }
 401 
 402         modstat_compute(mp, &ams);
 403 
 404         (void) printf("%3d %5s %7llu %7llu %7llu %7llu "
 405             "%4.1f %6.1f %3.0f %3.0f %s\n", (int)id,
 406             mp->m_new->state.fmds_value.str,
 407             u64delta(mp->m_old->prdequeued.fmds_value.ui64,
 408             mp->m_new->prdequeued.fmds_value.ui64),
 409             u64delta(mp->m_old->received.fmds_value.ui64,
 410             mp->m_new->received.fmds_value.ui64),
 411             u64delta(mp->m_old->discarded.fmds_value.ui64,
 412             mp->m_new->discarded.fmds_value.ui64),
 413             u64delta(mp->m_old->lost.fmds_value.ui64,
 414             mp->m_new->lost.fmds_value.ui64),
 415             mp->m_wait, mp->m_svc, mp->m_pct_w, mp->m_pct_b,
 416             mp->m_new->module.fmds_value.str);
 417 
 418         (void) fmd_adm_stats_free(g_adm, &ams);

 419 }
 420 
 421 static void
 422 stat_xprt(void)
 423 {
 424         (void) printf("%3s %5s %7s %7s %7s %7s %4s %6s %3s %3s %s\n",
 425             "id", "state", "ev_send", "ev_recv", "ev_drop", "ev_lost",
 426             "wait", "svc_t", "%w", "%b", "module");
 427 
 428         if (fmd_adm_xprt_iter(g_adm, stat_one_xprt, NULL) != 0)
 429                 die("failed to retrieve list of transports");
 430 }
 431 
 432 static void
 433 stat_one_xprt_auth(id_t id, void *arg)
 434 {
 435         const char *module = arg;
 436         fmd_adm_stats_t ams;
 437         struct modstats *mp;
 438 
 439         if (fmd_adm_xprt_stats(g_adm, id, &ams) != 0) {
 440                 warn("failed to retrieve statistics for transport %d", (int)id);
 441                 return;
 442         }
 443 
 444         for (mp = g_mods; mp != NULL; mp = mp->m_next) {
 445                 if (mp->m_id == id)
 446                         break;
 447         }
 448 
 449         if (mp == NULL && (mp = modstat_create(NULL, id)) == NULL) {
 450                 warn("failed to allocate memory for transport %d", (int)id);
 451                 (void) fmd_adm_stats_free(g_adm, &ams);
 452                 return;
 453         }
 454 
 455         modstat_compute(mp, &ams);
 456 
 457         if (module == NULL ||
 458             strcmp(module, mp->m_new->module.fmds_value.str) == 0) {
 459                 (void) printf("%3d %5s %-18s  %s\n", (int)id,
 460                     mp->m_new->state.fmds_value.str,
 461                     mp->m_new->module.fmds_value.str,
 462                     mp->m_new->authority.fmds_value.str ?
 463                     mp->m_new->authority.fmds_value.str : "-");
 464         }
 465 
 466         (void) fmd_adm_stats_free(g_adm, &ams);

 467 }
 468 
 469 static void
 470 stat_xprt_auth(const char *module)
 471 {
 472         (void) printf("%3s %5s %-18s  %s\n",
 473             "id", "state", "module", "authority");
 474 
 475         if (fmd_adm_xprt_iter(g_adm, stat_one_xprt_auth, (void *)module) != 0)
 476                 die("failed to retrieve list of transports");
 477 }
 478 
 479 /*ARGSUSED*/
 480 static int
 481 stat_one_fmd(const fmd_adm_modinfo_t *ami, void *ignored)
 482 {
 483         char memsz[8], bufsz[8];
 484         fmd_adm_stats_t ams;
 485         struct modstats *mp;
 486