hyperic-sigar 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/COPYING +339 -0
- data/EXCEPTIONS +104 -0
- data/README +2 -0
- data/Rakefile +87 -0
- data/bindings/SigarWrapper.pm +2934 -0
- data/bindings/ruby/examples/cpu_info.rb +16 -0
- data/bindings/ruby/examples/df.rb +32 -0
- data/bindings/ruby/examples/free.rb +19 -0
- data/bindings/ruby/examples/ifconfig.rb +67 -0
- data/bindings/ruby/examples/netstat.rb +54 -0
- data/bindings/ruby/examples/pargs.rb +18 -0
- data/bindings/ruby/examples/penv.rb +14 -0
- data/bindings/ruby/examples/route.rb +31 -0
- data/bindings/ruby/examples/who.rb +13 -0
- data/bindings/ruby/extconf.rb +110 -0
- data/bindings/ruby/rbsigar.c +628 -0
- data/include/sigar.h +901 -0
- data/include/sigar_fileinfo.h +141 -0
- data/include/sigar_format.h +65 -0
- data/include/sigar_getline.h +18 -0
- data/include/sigar_log.h +82 -0
- data/include/sigar_private.h +365 -0
- data/include/sigar_ptql.h +55 -0
- data/include/sigar_util.h +192 -0
- data/src/os/aix/aix_sigar.c +1927 -0
- data/src/os/aix/sigar_os.h +71 -0
- data/src/os/darwin/darwin_sigar.c +3450 -0
- data/src/os/darwin/sigar_os.h +82 -0
- data/src/os/hpux/dlpi.c +284 -0
- data/src/os/hpux/hpux_sigar.c +1205 -0
- data/src/os/hpux/sigar_os.h +51 -0
- data/src/os/linux/linux_sigar.c +2595 -0
- data/src/os/linux/sigar_os.h +84 -0
- data/src/os/netware/netware_sigar.c +719 -0
- data/src/os/netware/sigar_os.h +26 -0
- data/src/os/osf1/osf1_sigar.c +593 -0
- data/src/os/osf1/sigar_os.h +42 -0
- data/src/os/solaris/get_mib2.c +321 -0
- data/src/os/solaris/get_mib2.h +127 -0
- data/src/os/solaris/hmekstat.h +77 -0
- data/src/os/solaris/kstats.c +182 -0
- data/src/os/solaris/procfs.c +99 -0
- data/src/os/solaris/sigar_os.h +225 -0
- data/src/os/solaris/solaris_sigar.c +2561 -0
- data/src/os/stub/sigar_os.h +8 -0
- data/src/os/stub/stub_sigar.c +303 -0
- data/src/os/win32/peb.c +213 -0
- data/src/os/win32/sigar_os.h +623 -0
- data/src/os/win32/sigar_pdh.h +49 -0
- data/src/os/win32/win32_sigar.c +3718 -0
- data/src/sigar.c +2292 -0
- data/src/sigar_cache.c +181 -0
- data/src/sigar_fileinfo.c +792 -0
- data/src/sigar_format.c +649 -0
- data/src/sigar_getline.c +1849 -0
- data/src/sigar_ptql.c +1966 -0
- data/src/sigar_signal.c +218 -0
- data/src/sigar_util.c +1061 -0
- data/version.properties +11 -0
- metadata +112 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* from sys/hme.h, private to _KERNEL.
|
|
3
|
+
* we should be ok provided ksp->ks_data_size == sizeof(struct hmekstat)
|
|
4
|
+
* else will need to fallback to using kstat_data_lookup.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
struct hmekstat {
|
|
8
|
+
struct kstat_named hk_ipackets; /* packets received */
|
|
9
|
+
struct kstat_named hk_ierrors; /* input errors */
|
|
10
|
+
struct kstat_named hk_opackets; /* packets transmitted */
|
|
11
|
+
struct kstat_named hk_oerrors; /* output errors */
|
|
12
|
+
struct kstat_named hk_coll; /* collisions encountered */
|
|
13
|
+
struct kstat_named hk_defer; /* slots deferred */
|
|
14
|
+
struct kstat_named hk_fram; /* framing errors */
|
|
15
|
+
struct kstat_named hk_crc; /* crc errors */
|
|
16
|
+
struct kstat_named hk_sqerr; /* SQE test errors */
|
|
17
|
+
struct kstat_named hk_cvc; /* code violation errors */
|
|
18
|
+
struct kstat_named hk_lenerr; /* rx len errors */
|
|
19
|
+
struct kstat_named hk_ifspeed; /* interface speed */
|
|
20
|
+
struct kstat_named hk_buff; /* buff errors */
|
|
21
|
+
struct kstat_named hk_oflo; /* overflow errors */
|
|
22
|
+
struct kstat_named hk_uflo; /* underflow errors */
|
|
23
|
+
struct kstat_named hk_missed; /* missed/dropped packets */
|
|
24
|
+
struct kstat_named hk_tlcol; /* late collisions */
|
|
25
|
+
struct kstat_named hk_trtry; /* retry errors */
|
|
26
|
+
struct kstat_named hk_fstcol; /* first collisions */
|
|
27
|
+
struct kstat_named hk_tnocar; /* no carrier */
|
|
28
|
+
struct kstat_named hk_inits; /* initialization */
|
|
29
|
+
struct kstat_named hk_nocanput; /* nocanput errors */
|
|
30
|
+
struct kstat_named hk_allocbfail; /* allocb failures */
|
|
31
|
+
struct kstat_named hk_runt; /* runt errors */
|
|
32
|
+
struct kstat_named hk_jab; /* jabber errors */
|
|
33
|
+
struct kstat_named hk_babl; /* runt errors */
|
|
34
|
+
struct kstat_named hk_tmder; /* tmd errors */
|
|
35
|
+
struct kstat_named hk_txlaterr; /* tx late errors */
|
|
36
|
+
struct kstat_named hk_rxlaterr; /* rx late errors */
|
|
37
|
+
struct kstat_named hk_slvparerr; /* slave parity errors */
|
|
38
|
+
struct kstat_named hk_txparerr; /* tx parity errors */
|
|
39
|
+
struct kstat_named hk_rxparerr; /* rx parity errors */
|
|
40
|
+
struct kstat_named hk_slverrack; /* slave error acks */
|
|
41
|
+
struct kstat_named hk_txerrack; /* tx error acks */
|
|
42
|
+
struct kstat_named hk_rxerrack; /* rx error acks */
|
|
43
|
+
struct kstat_named hk_txtagerr; /* tx tag error */
|
|
44
|
+
struct kstat_named hk_rxtagerr; /* rx tag error */
|
|
45
|
+
struct kstat_named hk_eoperr; /* eop error */
|
|
46
|
+
struct kstat_named hk_notmds; /* tmd errors */
|
|
47
|
+
struct kstat_named hk_notbufs; /* tx buf errors */
|
|
48
|
+
struct kstat_named hk_norbufs; /* rx buf errors */
|
|
49
|
+
struct kstat_named hk_clsn; /* clsn errors */
|
|
50
|
+
|
|
51
|
+
/*
|
|
52
|
+
* required by kstat for MIB II objects(RFC 1213)
|
|
53
|
+
*/
|
|
54
|
+
struct kstat_named hk_rcvbytes; /* # octets received */
|
|
55
|
+
/* MIB - ifInOctets */
|
|
56
|
+
struct kstat_named hk_xmtbytes; /* # octets transmitted */
|
|
57
|
+
/* MIB - ifOutOctets */
|
|
58
|
+
struct kstat_named hk_multircv; /* # multicast packets */
|
|
59
|
+
/* delivered to upper layer */
|
|
60
|
+
/* MIB - ifInNUcastPkts */
|
|
61
|
+
struct kstat_named hk_multixmt; /* # multicast packets */
|
|
62
|
+
/* requested to be sent */
|
|
63
|
+
/* MIB - ifOutNUcastPkts */
|
|
64
|
+
struct kstat_named hk_brdcstrcv; /* # broadcast packets */
|
|
65
|
+
/* delivered to upper layer */
|
|
66
|
+
/* MIB - ifInNUcastPkts */
|
|
67
|
+
struct kstat_named hk_brdcstxmt; /* # broadcast packets */
|
|
68
|
+
/* requested to be sent */
|
|
69
|
+
/* MIB - ifOutNUcastPkts */
|
|
70
|
+
struct kstat_named hk_norcvbuf; /* # rcv packets discarded */
|
|
71
|
+
/* MIB - ifInDiscards */
|
|
72
|
+
struct kstat_named hk_noxmtbuf; /* # xmt packets discarded */
|
|
73
|
+
/* MIB - ifOutDiscards */
|
|
74
|
+
|
|
75
|
+
struct kstat_named hk_phyfail; /* phy failures */
|
|
76
|
+
struct kstat_named hk_link_up; /* Link Status */
|
|
77
|
+
};
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) [2004, 2005, 2006], Hyperic, Inc.
|
|
3
|
+
* This file is part of SIGAR.
|
|
4
|
+
*
|
|
5
|
+
* SIGAR is free software; you can redistribute it and/or modify
|
|
6
|
+
* it under the terms version 2 of the GNU General Public License as
|
|
7
|
+
* published by the Free Software Foundation. This program is distributed
|
|
8
|
+
* in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
|
|
9
|
+
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
|
10
|
+
* PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
11
|
+
* details.
|
|
12
|
+
*
|
|
13
|
+
* You should have received a copy of the GNU General Public License
|
|
14
|
+
* along with this program; if not, write to the Free Software
|
|
15
|
+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
16
|
+
* USA.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
#include "sigar.h"
|
|
20
|
+
#include "sigar_private.h"
|
|
21
|
+
#include "sigar_util.h"
|
|
22
|
+
#include "sigar_os.h"
|
|
23
|
+
|
|
24
|
+
int sigar_get_kstats(sigar_t *sigar)
|
|
25
|
+
{
|
|
26
|
+
kstat_ctl_t *kc = sigar->kc;
|
|
27
|
+
unsigned int i, id, ncpu = sysconf(_SC_NPROCESSORS_CONF);
|
|
28
|
+
int is_debug = SIGAR_LOG_IS_DEBUG(sigar);
|
|
29
|
+
|
|
30
|
+
if (ncpu != sigar->ncpu) {
|
|
31
|
+
if (!sigar->ks.lcpu) {
|
|
32
|
+
/* init */
|
|
33
|
+
sigar->ks.lcpu = ncpu;
|
|
34
|
+
sigar->ks.cpu = malloc(sizeof(*(sigar->ks.cpu)) * ncpu);
|
|
35
|
+
sigar->ks.cpu_info = malloc(sizeof(*(sigar->ks.cpu_info)) * ncpu);
|
|
36
|
+
sigar->ks.cpuid = malloc(sizeof(*(sigar->ks.cpuid)) * ncpu);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
sigar_log_printf(sigar, SIGAR_LOG_INFO,
|
|
40
|
+
"ncpu changed from %d to %d",
|
|
41
|
+
sigar->ncpu, ncpu);
|
|
42
|
+
if (ncpu > sigar->ks.lcpu) {
|
|
43
|
+
/* one or more cpus have been added */
|
|
44
|
+
sigar->ks.cpu = realloc(sigar->ks.cpu,
|
|
45
|
+
sizeof(*(sigar->ks.cpu)) * ncpu);
|
|
46
|
+
sigar->ks.cpu_info = realloc(sigar->ks.cpu_info,
|
|
47
|
+
sizeof(*(sigar->ks.cpu_info)) * ncpu);
|
|
48
|
+
sigar->ks.cpuid = realloc(sigar->ks.cpuid,
|
|
49
|
+
sizeof(*(sigar->ks.cpuid)) * ncpu);
|
|
50
|
+
sigar->ks.lcpu = ncpu;
|
|
51
|
+
}
|
|
52
|
+
/* else or more cpus have been removed */
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
sigar->ncpu = ncpu;
|
|
56
|
+
|
|
57
|
+
/* from man p_online:
|
|
58
|
+
* ``Processor numbers are integers,
|
|
59
|
+
* greater than or equal to 0,
|
|
60
|
+
* and are defined by the hardware platform.
|
|
61
|
+
* Processor numbers are not necessarily contiguous,
|
|
62
|
+
* but "not too sparse."``
|
|
63
|
+
* so we maintain our own mapping in ks.cpuid[]
|
|
64
|
+
*/
|
|
65
|
+
|
|
66
|
+
/* lookup in order, which kstat chain may not be in */
|
|
67
|
+
for (i=0, id=0; i<ncpu; id++) {
|
|
68
|
+
kstat_t *cpu_info, *cpu_stat;
|
|
69
|
+
|
|
70
|
+
if (!(cpu_info = kstat_lookup(kc, "cpu_info", id, NULL))) {
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (!(cpu_stat = kstat_lookup(kc, "cpu_stat", id, NULL))) {
|
|
75
|
+
/* XXX warn, faulted cpu? */
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
sigar->ks.cpu_info[i] = cpu_info;
|
|
79
|
+
sigar->ks.cpu[i] = cpu_stat;
|
|
80
|
+
sigar->ks.cpuid[i] = id;
|
|
81
|
+
|
|
82
|
+
if (is_debug) {
|
|
83
|
+
sigar_log_printf(sigar, SIGAR_LOG_DEBUG,
|
|
84
|
+
"cpu %d id=%d", i, sigar->ks.cpuid[i]);
|
|
85
|
+
}
|
|
86
|
+
i++;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
sigar->ks.system = kstat_lookup(kc, "unix", -1, "system_misc");
|
|
91
|
+
sigar->ks.syspages = kstat_lookup(kc, "unix", -1, "system_pages");
|
|
92
|
+
sigar->ks.mempages = kstat_lookup(kc, "bunyip", -1, "mempages");
|
|
93
|
+
|
|
94
|
+
return SIGAR_OK;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
SIGAR_INLINE kid_t sigar_kstat_update(sigar_t *sigar)
|
|
98
|
+
{
|
|
99
|
+
kid_t id = kstat_chain_update(sigar->kc);
|
|
100
|
+
|
|
101
|
+
switch (id) {
|
|
102
|
+
case -1:
|
|
103
|
+
sigar_log_printf(sigar, SIGAR_LOG_ERROR,
|
|
104
|
+
"kstat_chain_update error: %s",
|
|
105
|
+
sigar_strerror(sigar, errno));
|
|
106
|
+
break;
|
|
107
|
+
case 0:
|
|
108
|
+
/* up-to-date */
|
|
109
|
+
break;
|
|
110
|
+
default:
|
|
111
|
+
sigar_get_kstats(sigar);
|
|
112
|
+
sigar_log(sigar, SIGAR_LOG_DEBUG,
|
|
113
|
+
"kstat chain updated");
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return id;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/*
|
|
121
|
+
* bincompat is not possible with certain kstat data structures between
|
|
122
|
+
* solaris 2.6, 2.7, 2.8, etc. alternative is to use kstat_data_lookup()
|
|
123
|
+
* which means everytime we want a stat, must do a linear search
|
|
124
|
+
* of ksp->ks_data. eek. so we meet half way and do the search for
|
|
125
|
+
* each key once per sigar_t instance. once the initial search has
|
|
126
|
+
* been done, we have a table of offsets to quickly access the stats via
|
|
127
|
+
* ksp->ks_data + offset. this gives us bincompat without the overhead
|
|
128
|
+
* of many kstat_data_lookup calls.
|
|
129
|
+
*/
|
|
130
|
+
static SIGAR_INLINE int kstat_named_offset(kstat_t *ksp, const char *name)
|
|
131
|
+
{
|
|
132
|
+
unsigned int i;
|
|
133
|
+
kstat_named_t *kn;
|
|
134
|
+
|
|
135
|
+
for (i=0, kn=ksp->ks_data;
|
|
136
|
+
i<ksp->ks_ndata;
|
|
137
|
+
i++, kn++)
|
|
138
|
+
{
|
|
139
|
+
if (strEQ(kn->name, name)) {
|
|
140
|
+
return i;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return -2; /* not found */
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
static char *kstat_keys_system[] = {
|
|
148
|
+
"boot_time",
|
|
149
|
+
"avenrun_1min",
|
|
150
|
+
"avenrun_5min",
|
|
151
|
+
"avenrun_15min",
|
|
152
|
+
NULL
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
static char *kstat_keys_mempages[] = {
|
|
156
|
+
"pages_anon",
|
|
157
|
+
"pages_exec",
|
|
158
|
+
"pages_vnode",
|
|
159
|
+
NULL
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
static char *kstat_keys_syspages[] = {
|
|
163
|
+
"pagesfree",
|
|
164
|
+
NULL
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
static char **kstat_keys[] = {
|
|
168
|
+
kstat_keys_system,
|
|
169
|
+
kstat_keys_mempages,
|
|
170
|
+
kstat_keys_syspages,
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
void sigar_koffsets_lookup(kstat_t *ksp, int *offsets, int kidx)
|
|
174
|
+
{
|
|
175
|
+
int i;
|
|
176
|
+
char **keys = kstat_keys[kidx];
|
|
177
|
+
|
|
178
|
+
for (i=0; keys[i]; i++) {
|
|
179
|
+
offsets[i] = kstat_named_offset(ksp, keys[i]);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) [2004, 2005, 2006], Hyperic, Inc.
|
|
3
|
+
* This file is part of SIGAR.
|
|
4
|
+
*
|
|
5
|
+
* SIGAR is free software; you can redistribute it and/or modify
|
|
6
|
+
* it under the terms version 2 of the GNU General Public License as
|
|
7
|
+
* published by the Free Software Foundation. This program is distributed
|
|
8
|
+
* in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
|
|
9
|
+
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
|
10
|
+
* PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
11
|
+
* details.
|
|
12
|
+
*
|
|
13
|
+
* You should have received a copy of the GNU General Public License
|
|
14
|
+
* along with this program; if not, write to the Free Software
|
|
15
|
+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
16
|
+
* USA.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
#include "sigar.h"
|
|
20
|
+
#include "sigar_private.h"
|
|
21
|
+
#include "sigar_util.h"
|
|
22
|
+
#include "sigar_os.h"
|
|
23
|
+
|
|
24
|
+
#define my_pread(fd, ptr, type, offset) \
|
|
25
|
+
(pread(fd, ptr, sizeof(type), offset) == sizeof(type))
|
|
26
|
+
|
|
27
|
+
int sigar_proc_psinfo_get(sigar_t *sigar, sigar_pid_t pid)
|
|
28
|
+
{
|
|
29
|
+
int fd, retval = SIGAR_OK;
|
|
30
|
+
char buffer[BUFSIZ];
|
|
31
|
+
time_t timenow = time(NULL);
|
|
32
|
+
|
|
33
|
+
if (sigar->pinfo == NULL) {
|
|
34
|
+
sigar->pinfo = malloc(sizeof(*sigar->pinfo));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (sigar->last_pid == pid) {
|
|
38
|
+
if ((timenow - sigar->last_getprocs) < SIGAR_LAST_PROC_EXPIRE) {
|
|
39
|
+
return SIGAR_OK;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
sigar->last_pid = pid;
|
|
44
|
+
sigar->last_getprocs = timenow;
|
|
45
|
+
|
|
46
|
+
(void)SIGAR_PROC_FILENAME(buffer, pid, "/psinfo");
|
|
47
|
+
|
|
48
|
+
if ((fd = open(buffer, O_RDONLY)) < 0) {
|
|
49
|
+
return ESRCH;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (!my_pread(fd, sigar->pinfo, psinfo_t, 0)) {
|
|
53
|
+
retval = errno;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
close(fd);
|
|
57
|
+
|
|
58
|
+
return retval;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
int sigar_proc_usage_get(sigar_t *sigar, prusage_t *prusage, sigar_pid_t pid)
|
|
62
|
+
{
|
|
63
|
+
int fd, retval = SIGAR_OK;
|
|
64
|
+
char buffer[BUFSIZ];
|
|
65
|
+
|
|
66
|
+
(void)SIGAR_PROC_FILENAME(buffer, pid, "/usage");
|
|
67
|
+
|
|
68
|
+
if ((fd = open(buffer, O_RDONLY)) < 0) {
|
|
69
|
+
return ESRCH;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (!my_pread(fd, prusage, prusage_t, 0)) {
|
|
73
|
+
retval = errno;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
close(fd);
|
|
77
|
+
|
|
78
|
+
return retval;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
int sigar_proc_status_get(sigar_t *sigar, pstatus_t *pstatus, sigar_pid_t pid)
|
|
82
|
+
{
|
|
83
|
+
int fd, retval = SIGAR_OK;
|
|
84
|
+
char buffer[BUFSIZ];
|
|
85
|
+
|
|
86
|
+
(void)SIGAR_PROC_FILENAME(buffer, pid, "/status");
|
|
87
|
+
|
|
88
|
+
if ((fd = open(buffer, O_RDONLY)) < 0) {
|
|
89
|
+
return ESRCH;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (!my_pread(fd, pstatus, pstatus_t, 0)) {
|
|
93
|
+
retval = errno;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
close(fd);
|
|
97
|
+
|
|
98
|
+
return retval;
|
|
99
|
+
}
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) [2004, 2005, 2006], Hyperic, Inc.
|
|
3
|
+
* This file is part of SIGAR.
|
|
4
|
+
*
|
|
5
|
+
* SIGAR is free software; you can redistribute it and/or modify
|
|
6
|
+
* it under the terms version 2 of the GNU General Public License as
|
|
7
|
+
* published by the Free Software Foundation. This program is distributed
|
|
8
|
+
* in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
|
|
9
|
+
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
|
10
|
+
* PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
11
|
+
* details.
|
|
12
|
+
*
|
|
13
|
+
* You should have received a copy of the GNU General Public License
|
|
14
|
+
* along with this program; if not, write to the Free Software
|
|
15
|
+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
16
|
+
* USA.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
#ifndef SIGAR_OS_H
|
|
20
|
+
#define SIGAR_OS_H
|
|
21
|
+
|
|
22
|
+
#ifndef _POSIX_PTHREAD_SEMANTICS
|
|
23
|
+
#define _POSIX_PTHREAD_SEMANTICS
|
|
24
|
+
#endif
|
|
25
|
+
|
|
26
|
+
typedef unsigned long long int u_int64_t;
|
|
27
|
+
|
|
28
|
+
#include <ctype.h>
|
|
29
|
+
#include <assert.h>
|
|
30
|
+
#ifndef DMALLOC
|
|
31
|
+
#include <malloc.h>
|
|
32
|
+
#endif
|
|
33
|
+
#include <unistd.h>
|
|
34
|
+
#include <fcntl.h>
|
|
35
|
+
#include <stdio.h>
|
|
36
|
+
#include <errno.h>
|
|
37
|
+
#include <stdlib.h>
|
|
38
|
+
#include <sys/types.h>
|
|
39
|
+
#include <sys/processor.h>
|
|
40
|
+
#include <sys/sysinfo.h>
|
|
41
|
+
#include <sys/param.h>
|
|
42
|
+
|
|
43
|
+
#include <kstat.h>
|
|
44
|
+
#include <procfs.h>
|
|
45
|
+
|
|
46
|
+
#include "get_mib2.h"
|
|
47
|
+
|
|
48
|
+
/* avoid -Wall warning since solaris doesnt have a prototype for this */
|
|
49
|
+
int getdomainname(char *, int);
|
|
50
|
+
|
|
51
|
+
typedef struct {
|
|
52
|
+
kstat_t **ks;
|
|
53
|
+
int num;
|
|
54
|
+
char *name;
|
|
55
|
+
int nlen;
|
|
56
|
+
} kstat_list_t;
|
|
57
|
+
|
|
58
|
+
SIGAR_INLINE kid_t sigar_kstat_update(sigar_t *sigar);
|
|
59
|
+
|
|
60
|
+
int sigar_get_kstats(sigar_t *sigar);
|
|
61
|
+
|
|
62
|
+
void sigar_init_multi_kstats(sigar_t *sigar);
|
|
63
|
+
|
|
64
|
+
void sigar_free_multi_kstats(sigar_t *sigar);
|
|
65
|
+
|
|
66
|
+
int sigar_get_multi_kstats(sigar_t *sigar,
|
|
67
|
+
kstat_list_t *kl,
|
|
68
|
+
const char *name,
|
|
69
|
+
kstat_t **retval);
|
|
70
|
+
|
|
71
|
+
void sigar_koffsets_lookup(kstat_t *ksp, int *offsets, int kidx);
|
|
72
|
+
|
|
73
|
+
int sigar_proc_psinfo_get(sigar_t *sigar, sigar_pid_t pid);
|
|
74
|
+
|
|
75
|
+
int sigar_proc_usage_get(sigar_t *sigar, prusage_t *prusage, sigar_pid_t pid);
|
|
76
|
+
|
|
77
|
+
int sigar_proc_status_get(sigar_t *sigar, pstatus_t *pstatus, sigar_pid_t pid);
|
|
78
|
+
|
|
79
|
+
#define CPU_ONLINE(n) \
|
|
80
|
+
(p_online(n, P_STATUS) == P_ONLINE)
|
|
81
|
+
|
|
82
|
+
typedef enum {
|
|
83
|
+
KSTAT_SYSTEM_BOOT_TIME,
|
|
84
|
+
KSTAT_SYSTEM_LOADAVG_1,
|
|
85
|
+
KSTAT_SYSTEM_LOADAVG_2,
|
|
86
|
+
KSTAT_SYSTEM_LOADAVG_3,
|
|
87
|
+
KSTAT_SYSTEM_MAX
|
|
88
|
+
} kstat_system_off_e;
|
|
89
|
+
|
|
90
|
+
typedef enum {
|
|
91
|
+
KSTAT_MEMPAGES_ANON,
|
|
92
|
+
KSTAT_MEMPAGES_EXEC,
|
|
93
|
+
KSTAT_MEMPAGES_VNODE,
|
|
94
|
+
KSTAT_MEMPAGES_MAX
|
|
95
|
+
} kstat_mempages_off_e;
|
|
96
|
+
|
|
97
|
+
typedef enum {
|
|
98
|
+
KSTAT_SYSPAGES_FREE,
|
|
99
|
+
KSTAT_SYSPAGES_MAX
|
|
100
|
+
} kstat_syspages_off_e;
|
|
101
|
+
|
|
102
|
+
enum {
|
|
103
|
+
KSTAT_KEYS_system,
|
|
104
|
+
KSTAT_KEYS_mempages,
|
|
105
|
+
KSTAT_KEYS_syspages,
|
|
106
|
+
} kstat_keys_e;
|
|
107
|
+
|
|
108
|
+
typedef struct ps_prochandle * (*proc_grab_func_t)(pid_t, int, int *);
|
|
109
|
+
|
|
110
|
+
typedef void (*proc_free_func_t)(struct ps_prochandle *);
|
|
111
|
+
|
|
112
|
+
typedef int (*proc_create_agent_func_t)(struct ps_prochandle *);
|
|
113
|
+
|
|
114
|
+
typedef void (*proc_destroy_agent_func_t)(struct ps_prochandle *);
|
|
115
|
+
|
|
116
|
+
typedef void (*proc_objname_func_t)(struct ps_prochandle *,
|
|
117
|
+
uintptr_t, const char *, size_t);
|
|
118
|
+
|
|
119
|
+
typedef char * (*proc_dirname_func_t)(const char *, char *, size_t);
|
|
120
|
+
|
|
121
|
+
typedef char * (*proc_exename_func_t)(struct ps_prochandle *, char *, size_t);
|
|
122
|
+
|
|
123
|
+
typedef int (*proc_fstat64_func_t)(struct ps_prochandle *, int, void *);
|
|
124
|
+
|
|
125
|
+
typedef int (*proc_getsockopt_func_t)(struct ps_prochandle *,
|
|
126
|
+
int, int, int, void *, int *);
|
|
127
|
+
|
|
128
|
+
typedef int (*proc_getsockname_func_t)(struct ps_prochandle *,
|
|
129
|
+
int, struct sockaddr *, socklen_t *);
|
|
130
|
+
|
|
131
|
+
struct sigar_t {
|
|
132
|
+
SIGAR_T_BASE;
|
|
133
|
+
|
|
134
|
+
int solaris_version;
|
|
135
|
+
int use_ucb_ps;
|
|
136
|
+
|
|
137
|
+
kstat_ctl_t *kc;
|
|
138
|
+
|
|
139
|
+
/* kstat_lookup() as needed */
|
|
140
|
+
struct {
|
|
141
|
+
kstat_t **cpu;
|
|
142
|
+
kstat_t **cpu_info;
|
|
143
|
+
processorid_t *cpuid;
|
|
144
|
+
unsigned int lcpu; /* number malloced slots in the cpu array above */
|
|
145
|
+
kstat_t *system;
|
|
146
|
+
kstat_t *syspages;
|
|
147
|
+
kstat_t *mempages;
|
|
148
|
+
} ks;
|
|
149
|
+
|
|
150
|
+
struct {
|
|
151
|
+
int system[KSTAT_SYSTEM_MAX];
|
|
152
|
+
int mempages[KSTAT_MEMPAGES_MAX];
|
|
153
|
+
int syspages[KSTAT_SYSPAGES_MAX];
|
|
154
|
+
} koffsets;
|
|
155
|
+
|
|
156
|
+
int pagesize;
|
|
157
|
+
|
|
158
|
+
time_t last_getprocs;
|
|
159
|
+
sigar_pid_t last_pid;
|
|
160
|
+
psinfo_t *pinfo;
|
|
161
|
+
sigar_cpu_list_t cpulist;
|
|
162
|
+
|
|
163
|
+
/* libproc.so interface */
|
|
164
|
+
void *plib;
|
|
165
|
+
proc_grab_func_t pgrab;
|
|
166
|
+
proc_free_func_t pfree;
|
|
167
|
+
proc_create_agent_func_t pcreate_agent;
|
|
168
|
+
proc_destroy_agent_func_t pdestroy_agent;
|
|
169
|
+
proc_objname_func_t pobjname;
|
|
170
|
+
proc_dirname_func_t pdirname;
|
|
171
|
+
proc_exename_func_t pexename;
|
|
172
|
+
proc_fstat64_func_t pfstat64;
|
|
173
|
+
proc_getsockopt_func_t pgetsockopt;
|
|
174
|
+
proc_getsockname_func_t pgetsockname;
|
|
175
|
+
|
|
176
|
+
sigar_cache_t *pargs;
|
|
177
|
+
|
|
178
|
+
solaris_mib2_t mib2;
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
#ifdef SIGAR_64BIT
|
|
182
|
+
#define KSTAT_UINT ui64
|
|
183
|
+
#else
|
|
184
|
+
#define KSTAT_UINT ui32
|
|
185
|
+
#endif
|
|
186
|
+
|
|
187
|
+
#define kSTAT_exists(v, type) \
|
|
188
|
+
(sigar->koffsets.type[v] != -2)
|
|
189
|
+
|
|
190
|
+
#define kSTAT_ptr(v, type) \
|
|
191
|
+
((kstat_named_t *)ksp->ks_data + sigar->koffsets.type[v])
|
|
192
|
+
|
|
193
|
+
#define kSTAT_uint(v, type) \
|
|
194
|
+
(kSTAT_exists(v, type) ? kSTAT_ptr(v, type)->value.KSTAT_UINT : 0)
|
|
195
|
+
|
|
196
|
+
#define kSTAT_ui32(v, type) \
|
|
197
|
+
(kSTAT_exists(v, type) ? kSTAT_ptr(v, type)->value.ui32 : 0)
|
|
198
|
+
|
|
199
|
+
#define kSYSTEM(v) kSTAT_ui32(v, system)
|
|
200
|
+
|
|
201
|
+
#define kMEMPAGES(v) kSTAT_uint(v, mempages)
|
|
202
|
+
|
|
203
|
+
#define kSYSPAGES(v) kSTAT_uint(v, syspages)
|
|
204
|
+
|
|
205
|
+
#define sigar_koffsets_init(sigar, ksp, type) \
|
|
206
|
+
if (sigar->koffsets.type[0] == -1) \
|
|
207
|
+
sigar_koffsets_lookup(ksp, sigar->koffsets.type, KSTAT_KEYS_##type)
|
|
208
|
+
|
|
209
|
+
#define sigar_koffsets_init_system(sigar, ksp) \
|
|
210
|
+
sigar_koffsets_init(sigar, ksp, system)
|
|
211
|
+
|
|
212
|
+
#define sigar_koffsets_init_mempages(sigar, ksp) \
|
|
213
|
+
sigar_koffsets_init(sigar, ksp, mempages)
|
|
214
|
+
|
|
215
|
+
#define sigar_koffsets_init_syspages(sigar, ksp) \
|
|
216
|
+
sigar_koffsets_init(sigar, ksp, syspages)
|
|
217
|
+
|
|
218
|
+
#define HAVE_READDIR_R
|
|
219
|
+
#define HAVE_GETPWNAM_R
|
|
220
|
+
#define HAVE_GETPWUID_R
|
|
221
|
+
|
|
222
|
+
#define SIGAR_EMIB2 (SIGAR_OS_START_ERROR+1)
|
|
223
|
+
|
|
224
|
+
#endif /* SIGAR_OS_H */
|
|
225
|
+
|