Print this page
Add perl support KSTAT_DATA_TIME.


   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   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 (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright (c) 2014 Racktop Systems.

  25  */
  26 
  27 /*
  28  * Kstat.xs is a Perl XS (eXStension module) that makes the Solaris
  29  * kstat(3KSTAT) facility available to Perl scripts.  Kstat is a general-purpose
  30  * mechanism  for  providing kernel statistics to users.  The Solaris API is
  31  * function-based (see the manpage for details), but for ease of use in Perl
  32  * scripts this module presents the information as a nested hash data structure.
  33  * It would be too inefficient to read every kstat in the system, so this module
  34  * uses the Perl TIEHASH mechanism to implement a read-on-demand semantic, which
  35  * only reads and updates kstats as and when they are actually accessed.
  36  */
  37 
  38 /*
  39  * Ignored raw kstats.
  40  *
  41  * Some raw kstats are ignored by this module, these are listed below.  The
  42  * most common reason is that the kstats are stored as arrays and the ks_ndata
  43  * and/or ks_data_size fields are invalid.  In this case it is impossible to
  44  * know how many records are in the array, so they can't be read.


1057         SV*             value;
1058 
1059         for (n = kp->ks_ndata, knp = KSTAT_NAMED_PTR(kp); n > 0; n--, knp++) {
1060                 switch (knp->data_type) {
1061                 case KSTAT_DATA_CHAR:
1062                         value = newSVpv(knp->value.c, strip_str ?
1063                             strlen(knp->value.c) : sizeof (knp->value.c));
1064                         break;
1065                 case KSTAT_DATA_INT32:
1066                         value = newSViv(knp->value.i32);
1067                         break;
1068                 case KSTAT_DATA_UINT32:
1069                         value = NEW_UV(knp->value.ui32);
1070                         break;
1071                 case KSTAT_DATA_INT64:
1072                         value = NEW_UV(knp->value.i64);
1073                         break;
1074                 case KSTAT_DATA_UINT64:
1075                         value = NEW_UV(knp->value.ui64);
1076                         break;



1077                 case KSTAT_DATA_STRING:
1078                         if (KSTAT_NAMED_STR_PTR(knp) == NULL)
1079                                 value = newSVpv("null", sizeof ("null") - 1);
1080                         else
1081                                 value = newSVpv(KSTAT_NAMED_STR_PTR(knp),
1082                                                 KSTAT_NAMED_STR_BUFLEN(knp) -1);
1083                         break;
1084                 default:
1085                         PERL_ASSERTMSG(0, "kstat_read: invalid data type");
1086                         continue;
1087                 }
1088                 hv_store(self, knp->name, strlen(knp->name), value, 0);
1089         }
1090 }
1091 
1092 /*
1093  * Save kstat interrupt statistics
1094  */
1095 
1096 static void




   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   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 (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright (c) 2014 Racktop Systems.
  25  * Copyright 2016 Garrett D'Amore
  26  */
  27 
  28 /*
  29  * Kstat.xs is a Perl XS (eXStension module) that makes the Solaris
  30  * kstat(3KSTAT) facility available to Perl scripts.  Kstat is a general-purpose
  31  * mechanism  for  providing kernel statistics to users.  The Solaris API is
  32  * function-based (see the manpage for details), but for ease of use in Perl
  33  * scripts this module presents the information as a nested hash data structure.
  34  * It would be too inefficient to read every kstat in the system, so this module
  35  * uses the Perl TIEHASH mechanism to implement a read-on-demand semantic, which
  36  * only reads and updates kstats as and when they are actually accessed.
  37  */
  38 
  39 /*
  40  * Ignored raw kstats.
  41  *
  42  * Some raw kstats are ignored by this module, these are listed below.  The
  43  * most common reason is that the kstats are stored as arrays and the ks_ndata
  44  * and/or ks_data_size fields are invalid.  In this case it is impossible to
  45  * know how many records are in the array, so they can't be read.


1058         SV*             value;
1059 
1060         for (n = kp->ks_ndata, knp = KSTAT_NAMED_PTR(kp); n > 0; n--, knp++) {
1061                 switch (knp->data_type) {
1062                 case KSTAT_DATA_CHAR:
1063                         value = newSVpv(knp->value.c, strip_str ?
1064                             strlen(knp->value.c) : sizeof (knp->value.c));
1065                         break;
1066                 case KSTAT_DATA_INT32:
1067                         value = newSViv(knp->value.i32);
1068                         break;
1069                 case KSTAT_DATA_UINT32:
1070                         value = NEW_UV(knp->value.ui32);
1071                         break;
1072                 case KSTAT_DATA_INT64:
1073                         value = NEW_UV(knp->value.i64);
1074                         break;
1075                 case KSTAT_DATA_UINT64:
1076                         value = NEW_UV(knp->value.ui64);
1077                         break;
1078                 case KSTAT_DATA_TIME:
1079                         value = NEW_HRTIME(knp->value.ui64);
1080                         break;
1081                 case KSTAT_DATA_STRING:
1082                         if (KSTAT_NAMED_STR_PTR(knp) == NULL)
1083                                 value = newSVpv("null", sizeof ("null") - 1);
1084                         else
1085                                 value = newSVpv(KSTAT_NAMED_STR_PTR(knp),
1086                                                 KSTAT_NAMED_STR_BUFLEN(knp) -1);
1087                         break;
1088                 default:
1089                         PERL_ASSERTMSG(0, "kstat_read: invalid data type");
1090                         continue;
1091                 }
1092                 hv_store(self, knp->name, strlen(knp->name), value, 0);
1093         }
1094 }
1095 
1096 /*
1097  * Save kstat interrupt statistics
1098  */
1099 
1100 static void