1Kstat(3PERL)                Perl Library Functions                Kstat(3PERL)
2
3
4

NAME

6       Kstat - Perl tied hash interface to the kstat facility
7

SYNOPSIS

9       use Sun::Solaris::Kstat;
10
11       Sun::Solaris::Kstat->new();
12       Sun::Solaris::Kstat->update();
13       Sun::Solaris::Kstat->{module}{instance}{name}{statistic}
14
15

DESCRIPTION

17       Kernel  statistics are categorized using a 3-part key consisting of the
18       module, the instance, and the statistic name. For example, CPU informa‐
19       tion  can be found under cpu_stat:0:cpu_stat0, as in the above example.
20       The method Sun::Solaris::Kstatnew() creates a new 3-layer tree of Perl
21       hashes with the same structure; that is, the statistic for CPU 0 can be
22       accessed as $ks→{cpu_stat}{0}{cpu_stat0}. The fourth and  lowest  layer
23       is a tied hash used to hold the individual statistics values for a par‐
24       ticular system resource.
25
26
27       For performance reasons, the creation of a  Sun::Solaris::Kstat  object
28       is  not  accompanied  by  a  following read of all possible statistics.
29       Instead, the 3-layer structure described above is created, but reads of
30       a  statistic's  values  are  done  only  when  referenced. For example,
31       accessing $ks→{cpu_stat}{0}{cpu_stat0}{syscall} will read  in  all  the
32       statistics  for  CPU 0, including user, system, and wait times, and the
33       other CPU statistics, as well as the number  of  system  call  entries.
34       Once  you  have  accessed  a  lowest  level  statistics  value, calling
35       $ksupdate() will automatically update all the individual values of any
36       statistics you have accessed.
37
38
39       There  are two values of the lowest-level hash that can be read without
40       causing the full set of statistics to be read from  the  kernel.  These
41       are "class", which is the kstat class of the statistics, and "crtime"n,
42       which is the time that the kstat was  created.  See  kstat(3KSTAT)  for
43       full details of these fields.
44
45   Methods
46       new()       Create a new kstat statistics hierarchy and return a refer‐
47                   ence to the top-level hash. Use it like any normal hash  to
48                   access the statistics.
49
50
51       update()    Update  all  the statistics that have been accessed so far.
52                   In scalar context, update() returns 1 if the  kstat  struc‐
53                   ture  has  changed,  and  0  otherwise.  In  list  context,
54                   update() returns references to two arrays: the first  holds
55                   the keys of any kstats that have been added, and the second
56                   holds the keys of any kstats that have been  deleted.  Each
57                   key will be returned in the form "module:instance:name".
58
59

EXAMPLES

61       Example 1 Sun::Solaris::Kstat example
62
63         use Sun::Solaris::Kstat;
64
65         my $kstat = Sun::Solaris::Kstat->new();
66         my ($usr1, $sys1, $wio1, $idle1) =
67            @{$kstat->{cpu_stat}{0}{cpu_stat0}}{qw(user kernel
68                 wait idle)};
69         print("usr sys wio idle\n");
70         while (1) {
71            sleep 5;
72            if ($kstat->update()) {
73                    print("Configuration changed\n");
74            }
75            my ($usr2, $sys2, $wio2, $idle2) =
76                @{$kstat->{cpu_stat}{0}{cpu_stat0}}{qw(user kernel
77                     wait idle)};
78            printf(" %.2d  %.2d  %.2d  %.2d\n",
79                 ($usr2 - $usr1) / 5, ($sys2 - $sys1) / 5,
80                 ($wio2 - $wio1) / 5, ($idle2 - $idle1) / 5);
81            $usr1 = $usr2;
82            $sys1 = $sys2;
83            $wio1 = $wio2;
84            $idle1 = $idle2;
85         }
86
87

SEE ALSO

89       perl(1),    kstat(1M),    kstat(3KSTAT),    kstat_chain_update(3KSTAT),
90       kstat_close(3KSTAT), kstat_open(3KSTAT), kstat_read(3KSTAT)
91

NOTES

93       As the statistics are stored in a tied hash, taking  additional  refer‐
94       ences of members of the hash, such as
95
96         my $ref = \ks->{cpu_stat}{0}{cpu_stat0}{syscall};
97         print("$$ref\n");
98
99
100
101       will  be  recorded  as  a hold on that statistic's value, preventing it
102       from being updated by refresh(). Copy the values explicitly if  persis‐
103       tence is necessary.
104
105
106       Several  of the statistics provided by the kstat facility are stored as
107       64-bit integer values. Perl 5 does not yet  internally  support  64-bit
108       integers,  so  these  values are approximated in this module. There are
109       two classes of 64-bit value to be dealt with:
110
111       64-bit intervals and times    These are the crtime and snaptime  fields
112                                     of  all  the  statistics  hashes, and the
113                                     wtime,  wlentime,   wlastupdate,   rtime,
114                                     rlentime  and  rlastupdate  fields of the
115                                     kstat I/O statistics  structures.   These
116                                     are  measured  by  the  kstat facility in
117                                     nanoseconds, meaning that a 32-bit  value
118                                     would  represent approximately 4 seconds.
119                                     The alternative is to store the values as
120                                     floating-point   numbers,   which   offer
121                                     approximately 53 bits  of   precision  on
122                                     present  hardware.  64-bit  intervals and
123                                     timers as floating point values expressed
124                                     in  seconds,  meaning  that  time-related
125                                     kstats are being rounded to approximately
126                                     microsecond resolution.
127
128
129       64-bit counters               It is not useful to store these values as
130                                     32-bit values. As noted above,  floating-
131                                     point  values offer 53 bits of precision.
132                                     Accordingly,  all  64-bit  counters   are
133                                     stored as floating-point values.
134
135
136
137
138SunOS 5.11                        21 Jul 2005                     Kstat(3PERL)
Impressum