sigar-test 0.7.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +201 -0
  3. data/NOTICE +117 -0
  4. data/README +2 -0
  5. data/Rakefile +105 -0
  6. data/bindings/SigarBuild.pm +301 -0
  7. data/bindings/SigarWrapper.pm +3025 -0
  8. data/bindings/ruby/extconf.rb +131 -0
  9. data/bindings/ruby/rbsigar.c +888 -0
  10. data/include/sigar.h +984 -0
  11. data/include/sigar_fileinfo.h +157 -0
  12. data/include/sigar_format.h +65 -0
  13. data/include/sigar_getline.h +18 -0
  14. data/include/sigar_log.h +80 -0
  15. data/include/sigar_private.h +429 -0
  16. data/include/sigar_ptql.h +53 -0
  17. data/include/sigar_util.h +197 -0
  18. data/src/os/aix/aix_sigar.c +2168 -0
  19. data/src/os/aix/sigar_os.h +73 -0
  20. data/src/os/darwin/Info.plist.in +27 -0
  21. data/src/os/darwin/darwin_sigar.c +3718 -0
  22. data/src/os/darwin/sigar_os.h +80 -0
  23. data/src/os/hpux/hpux_sigar.c +1361 -0
  24. data/src/os/hpux/sigar_os.h +49 -0
  25. data/src/os/linux/linux_sigar.c +2810 -0
  26. data/src/os/linux/sigar_os.h +82 -0
  27. data/src/os/solaris/get_mib2.c +321 -0
  28. data/src/os/solaris/get_mib2.h +127 -0
  29. data/src/os/solaris/kstats.c +181 -0
  30. data/src/os/solaris/procfs.c +97 -0
  31. data/src/os/solaris/sigar_os.h +224 -0
  32. data/src/os/solaris/solaris_sigar.c +2732 -0
  33. data/src/os/win32/peb.c +212 -0
  34. data/src/os/win32/sigar.rc.in +40 -0
  35. data/src/os/win32/sigar_os.h +685 -0
  36. data/src/os/win32/sigar_pdh.h +47 -0
  37. data/src/os/win32/win32_sigar.c +4109 -0
  38. data/src/sigar.c +2444 -0
  39. data/src/sigar_cache.c +253 -0
  40. data/src/sigar_fileinfo.c +815 -0
  41. data/src/sigar_format.c +696 -0
  42. data/src/sigar_getline.c +1849 -0
  43. data/src/sigar_ptql.c +1976 -0
  44. data/src/sigar_signal.c +216 -0
  45. data/src/sigar_util.c +1060 -0
  46. data/src/sigar_version.c.in +22 -0
  47. data/src/sigar_version_autoconf.c.in +22 -0
  48. data/version.properties +11 -0
  49. metadata +91 -0
@@ -0,0 +1,82 @@
1
+ /*
2
+ * Copyright (c) 2004-2008 Hyperic, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ #ifndef SIGAR_OS_H
18
+ #define SIGAR_OS_H
19
+
20
+ #include <assert.h>
21
+
22
+ #include <stdlib.h>
23
+ #include <unistd.h>
24
+ #include <fcntl.h>
25
+ #include <ctype.h>
26
+ #include <time.h>
27
+
28
+ #include <netinet/in.h>
29
+ #include <sys/types.h>
30
+ #include <sys/socket.h>
31
+ #include <arpa/inet.h>
32
+
33
+ typedef struct {
34
+ sigar_pid_t pid;
35
+ time_t mtime;
36
+ sigar_uint64_t vsize;
37
+ sigar_uint64_t rss;
38
+ sigar_uint64_t minor_faults;
39
+ sigar_uint64_t major_faults;
40
+ sigar_uint64_t ppid;
41
+ int tty;
42
+ int priority;
43
+ int nice;
44
+ sigar_uint64_t start_time;
45
+ sigar_uint64_t utime;
46
+ sigar_uint64_t stime;
47
+ char name[SIGAR_PROC_NAME_LEN];
48
+ char state;
49
+ int processor;
50
+ } linux_proc_stat_t;
51
+
52
+ typedef enum {
53
+ IOSTAT_NONE,
54
+ IOSTAT_PARTITIONS, /* 2.4 */
55
+ IOSTAT_DISKSTATS, /* 2.6 */
56
+ IOSTAT_SYS /* 2.6 */
57
+ } linux_iostat_e;
58
+
59
+ struct sigar_t {
60
+ SIGAR_T_BASE;
61
+ int pagesize;
62
+ int ram;
63
+ int proc_signal_offset;
64
+ linux_proc_stat_t last_proc_stat;
65
+ int lcpu;
66
+ linux_iostat_e iostat;
67
+ char *proc_net;
68
+ /* Native POSIX Thread Library 2.6+ kernel */
69
+ int has_nptl;
70
+ };
71
+
72
+ #define HAVE_STRERROR_R
73
+ #ifndef __USE_XOPEN2K
74
+ /* use gnu version of strerror_r */
75
+ #define HAVE_STRERROR_R_GLIBC
76
+ #endif
77
+ #define HAVE_READDIR_R
78
+ #define HAVE_GETPWNAM_R
79
+ #define HAVE_GETPWUID_R
80
+ #define HAVE_GETGRGID_R
81
+
82
+ #endif /* SIGAR_OS_H */
@@ -0,0 +1,321 @@
1
+ /*
2
+ * get_mib2() -- get MIB2 information from Solaris 2.[3-7] kernel
3
+ *
4
+ * V. Abell <abe@cc.purdue.edu>
5
+ * Purdue University Computing Center
6
+ */
7
+
8
+
9
+ /*
10
+ * Copyright 1995 Purdue Research Foundation, West Lafayette, Indiana
11
+ * 47907. All rights reserved.
12
+ *
13
+ * Written by Victor A. Abell <abe@cc.purdue.edu>
14
+ *
15
+ * This software is not subject to any license of the American Telephone
16
+ * and Telegraph Company or the Regents of the University of California.
17
+ *
18
+ * Permission is granted to anyone to use this software for any purpose on
19
+ * any computer system, and to alter it and redistribute it freely, subject
20
+ * to the following restrictions:
21
+ *
22
+ * 1. Neither Victor A Abell nor Purdue University are responsible for
23
+ * any consequences of the use of this software.
24
+ *
25
+ * 2. The origin of this software must not be misrepresented, either by
26
+ * explicit claim or by omission. Credit to Victor A. Abell and Purdue
27
+ * University must appear in documentation and sources.
28
+ *
29
+ * 3. Altered versions must be plainly marked as such, and must not be
30
+ * misrepresented as being the original software.
31
+ *
32
+ * 4. This notice may not be removed or altered.
33
+ */
34
+
35
+ /*
36
+ * Altered for sigar:
37
+ * - remove static stuff to make thread-safe by Doug MacEachern (3/11/05)
38
+ */
39
+
40
+ #if 0 /*ndef lint -Wall -Werror*/
41
+ static char copyright[] =
42
+ "@(#) Copyright 1995 Purdue Research Foundation.\nAll rights reserved.\n";
43
+ #endif
44
+
45
+ #include "get_mib2.h"
46
+
47
+ #include <errno.h>
48
+ #include <fcntl.h>
49
+ #include <stdio.h>
50
+ #include <stdlib.h>
51
+ #include <string.h>
52
+ #include <unistd.h>
53
+
54
+ #ifdef DMALLOC
55
+ #include <dmalloc.h>
56
+ #endif
57
+
58
+ /*
59
+ * close_mib2() - close MIB2 access
60
+ *
61
+ * return:
62
+ *
63
+ * exit = GET_MIB2_OK if close succeeded
64
+ * GET_MIB2_* is the error code.
65
+ */
66
+
67
+ int
68
+ close_mib2(solaris_mib2_t *mib2)
69
+ {
70
+ if (mib2->sd < 0) {
71
+ (void) strcpy(mib2->errmsg, "close_mib2: socket not open");
72
+ return(GET_MIB2_ERR_NOTOPEN);
73
+ }
74
+ if (close(mib2->sd)) {
75
+ (void) sprintf(mib2->errmsg, "close_mib2: %s", strerror(errno));
76
+ return(GET_MIB2_ERR_CLOSE);
77
+ }
78
+ mib2->sd = -1;
79
+ if (mib2->db_len && mib2->db) {
80
+ mib2->db_len = 0;
81
+ free((void *)mib2->db);
82
+ mib2->db = NULL;
83
+ }
84
+ if (mib2->smb_len && mib2->smb) {
85
+ mib2->smb_len = 0;
86
+ free((void *)mib2->smb);
87
+ mib2->smb = NULL;
88
+ }
89
+ return(GET_MIB2_OK);
90
+ }
91
+
92
+
93
+ /*
94
+ * get_mib2() - get MIB2 data
95
+ *
96
+ * return:
97
+ *
98
+ * exit = GET_MIB2_OK if get succeeded, and:
99
+ * *opt = opthdr structure address
100
+ * *data = data buffer address
101
+ * *datalen = size of data buffer
102
+ * GET_MIB2_* is the error code for failure.
103
+ */
104
+
105
+ int
106
+ get_mib2(solaris_mib2_t *mib2,
107
+ struct opthdr **opt,
108
+ char **data,
109
+ int *datalen)
110
+ {
111
+ struct strbuf d; /* streams data buffer */
112
+ int err; /* error code */
113
+ int f; /* flags */
114
+ int rc; /* reply code */
115
+
116
+ /*
117
+ * If MIB2 access isn't open, open it and issue the preliminary stream
118
+ * messages.
119
+ */
120
+ if (mib2->sd < 0) {
121
+ /*
122
+ * Open access. Return on error.
123
+ */
124
+ if ((err = open_mib2(mib2))) {
125
+ return(err);
126
+ }
127
+ /*
128
+ * Set up message request and option.
129
+ */
130
+ mib2->req = (struct T_optmgmt_req *)mib2->smb;
131
+ mib2->op = (struct opthdr *)&mib2->smb[sizeof(struct T_optmgmt_req)];
132
+ mib2->req->PRIM_type = T_OPTMGMT_REQ;
133
+ mib2->req->OPT_offset = sizeof(struct T_optmgmt_req);
134
+ mib2->req->OPT_length = sizeof(struct opthdr);
135
+
136
+ #if defined(MI_T_CURRENT)
137
+ mib2->req->MGMT_flags = MI_T_CURRENT;
138
+ #else /* !defined(MI_T_CURRENT) */
139
+ # if defined(T_CURRENT)
140
+ mib2->req->MGMT_flags = T_CURRENT;
141
+ # else /* !defined(T_CURRENT) */
142
+ #error "Neither MI_T_CURRENT nor T_CURRENT are defined."
143
+ # endif /* defined(T_CURRENT) */
144
+ #endif /* defined(MI_T_CURRENT) */
145
+
146
+ mib2->op->level = MIB2_IP;
147
+ mib2->op->name = mib2->op->len = 0;
148
+ mib2->ctlbuf.buf = mib2->smb;
149
+ mib2->ctlbuf.len = mib2->req->OPT_offset + mib2->req->OPT_length;
150
+ /*
151
+ * Put the message.
152
+ */
153
+ if (putmsg(mib2->sd, &mib2->ctlbuf, (struct strbuf *)NULL, 0) == -1) {
154
+ (void) sprintf(mib2->errmsg,
155
+ "get_mib2: putmsg request: %s", strerror(errno));
156
+ return(GET_MIB2_ERR_PUTMSG);
157
+ }
158
+ /*
159
+ * Set up to process replies.
160
+ */
161
+ mib2->op_ack = (struct T_optmgmt_ack *)mib2->smb;
162
+ mib2->ctlbuf.maxlen = mib2->smb_len;
163
+ mib2->err_ack = (struct T_error_ack *)mib2->smb;
164
+ mib2->op = (struct opthdr *)&mib2->smb[sizeof(struct T_optmgmt_ack)];
165
+ }
166
+ /*
167
+ * Get the next (first) reply message.
168
+ */
169
+ f = 0;
170
+ if ((rc = getmsg(mib2->sd, &mib2->ctlbuf, NULL, &f)) < 0) {
171
+ (void) sprintf(mib2->errmsg, "get_mib2: getmsg(reply): %s",
172
+ strerror(errno));
173
+ return(GET_MIB2_ERR_GETMSGR);
174
+ }
175
+ /*
176
+ * Check for end of data.
177
+ */
178
+ if (rc == 0
179
+ && mib2->ctlbuf.len >= sizeof(struct T_optmgmt_ack)
180
+ && mib2->op_ack->PRIM_type == T_OPTMGMT_ACK
181
+ && mib2->op_ack->MGMT_flags == T_SUCCESS
182
+ && mib2->op->len == 0)
183
+ {
184
+ err = close_mib2(mib2);
185
+ if (err) {
186
+ return(err);
187
+ }
188
+ return(GET_MIB2_EOD);
189
+ }
190
+ /*
191
+ * Check for error.
192
+ */
193
+ if (mib2->ctlbuf.len >= sizeof(struct T_error_ack)
194
+ && mib2->err_ack->PRIM_type == T_ERROR_ACK)
195
+ {
196
+ (void) sprintf(mib2->errmsg,
197
+ "get_mib2: T_ERROR_ACK: len=%d, TLI=%#x, UNIX=%#x",
198
+ mib2->ctlbuf.len,
199
+ (int)mib2->err_ack->TLI_error,
200
+ (int)mib2->err_ack->UNIX_error);
201
+ return(GET_MIB2_ERR_ACK);
202
+ }
203
+ /*
204
+ * Check for no data.
205
+ */
206
+ if (rc != MOREDATA
207
+ || mib2->ctlbuf.len < sizeof(struct T_optmgmt_ack)
208
+ || mib2->op_ack->PRIM_type != T_OPTMGMT_ACK
209
+ || mib2->op_ack->MGMT_flags != T_SUCCESS)
210
+ {
211
+ (void) sprintf(mib2->errmsg,
212
+ "get_mib2: T_OPTMGMT_ACK: "
213
+ "rc=%d len=%d type=%#x flags=%#x",
214
+ rc, mib2->ctlbuf.len,
215
+ (int)mib2->op_ack->PRIM_type,
216
+ (int)mib2->op_ack->MGMT_flags);
217
+ return(GET_MIB2_ERR_NODATA);
218
+ }
219
+ /*
220
+ * Allocate (or enlarge) the data buffer.
221
+ */
222
+ if (mib2->op->len >= mib2->db_len) {
223
+ mib2->db_len = mib2->op->len;
224
+ if (mib2->db == NULL) {
225
+ mib2->db = (char *)malloc(mib2->db_len);
226
+ }
227
+ else {
228
+ mib2->db = (char *)realloc(mib2->db, mib2->db_len);
229
+ }
230
+ if (mib2->db == NULL) {
231
+ (void) sprintf(mib2->errmsg,
232
+ "get_mib2: no space for %d byte data buffer",
233
+ mib2->db_len);
234
+ return(GET_MIB2_ERR_NOSPC);
235
+ }
236
+ }
237
+ /*
238
+ * Get the data part of the message -- the MIB2 part.
239
+ */
240
+ d.maxlen = mib2->op->len;
241
+ d.buf = mib2->db;
242
+ d.len = 0;
243
+ f = 0;
244
+ if ((rc = getmsg(mib2->sd, NULL, &d, &f)) < 0) {
245
+ (void) sprintf(mib2->errmsg, "get_mib2: getmsg(data): %s",
246
+ strerror(errno));
247
+ return(GET_MIB2_ERR_GETMSGD);
248
+ }
249
+ if (rc) {
250
+ (void) sprintf(mib2->errmsg,
251
+ "get_mib2: getmsg(data): rc=%d maxlen=%d len=%d: %s",
252
+ rc, d.maxlen, d.len, strerror(errno));
253
+ return(GET_MIB2_ERR_GETMSGD);
254
+ }
255
+ /*
256
+ * Compose a successful return.
257
+ */
258
+ *opt = mib2->op;
259
+ *data = mib2->db;
260
+ *datalen = d.len;
261
+ return(GET_MIB2_OK);
262
+ }
263
+
264
+
265
+ /*
266
+ * open_mib2() - open access to MIB2 data
267
+ *
268
+ * return:
269
+ *
270
+ * exit = GET_MIB2_OK if open succeeded
271
+ * GET_MIB2_* is the error code for failure.
272
+ */
273
+
274
+ int
275
+ open_mib2(solaris_mib2_t *mib2)
276
+ {
277
+ /*
278
+ * It's an error if the stream device is already open.
279
+ */
280
+ if (mib2->sd >= 0) {
281
+ (void) strcpy(mib2->errmsg, "open_mib2: MIB2 access already open");
282
+ return(GET_MIB2_ERR_OPEN);
283
+ }
284
+ /*
285
+ * Open the ARP stream device, push TCP and UDP on it.
286
+ */
287
+ if ((mib2->sd = open(GET_MIB2_ARPDEV, O_RDWR, 0600)) < 0) {
288
+ (void) sprintf(mib2->errmsg, "open_mib2: %s: %s", GET_MIB2_ARPDEV,
289
+ strerror(errno));
290
+ return(GET_MIB2_ERR_ARPOPEN);
291
+ }
292
+ if (ioctl(mib2->sd, I_PUSH, GET_MIB2_TCPSTREAM) == -1) {
293
+ (void) sprintf(mib2->errmsg, "open_mib2: push %s: %s",
294
+ GET_MIB2_TCPSTREAM, strerror(errno));
295
+ return(GET_MIB2_ERR_TCPPUSH);
296
+ }
297
+ if (ioctl(mib2->sd, I_PUSH, GET_MIB2_UDPSTREAM) == -1) {
298
+ (void) sprintf(mib2->errmsg, "open_mib2: push %s: %s",
299
+ GET_MIB2_UDPSTREAM, strerror(errno));
300
+ return(GET_MIB2_ERR_UDPPUSH);
301
+ }
302
+ /*
303
+ * Allocate a stream message buffer.
304
+ */
305
+ mib2->smb_len = sizeof(struct opthdr) + sizeof(struct T_optmgmt_req);
306
+ if (mib2->smb_len < (sizeof (struct opthdr) + sizeof(struct T_optmgmt_ack))) {
307
+ mib2->smb_len = sizeof (struct opthdr) + sizeof(struct T_optmgmt_ack);
308
+ }
309
+ if (mib2->smb_len < sizeof(struct T_error_ack)) {
310
+ mib2->smb_len = sizeof(struct T_error_ack);
311
+ }
312
+ if ((mib2->smb = (char *)malloc(mib2->smb_len)) == NULL) {
313
+ (void) strcpy(mib2->errmsg,
314
+ "open_mib2: no space for stream message buffer");
315
+ return(GET_MIB2_ERR_NOSPC);
316
+ }
317
+ /*
318
+ * All is OK. Return that indication.
319
+ */
320
+ return(GET_MIB2_OK);
321
+ }
@@ -0,0 +1,127 @@
1
+ /*
2
+ * get_mib2.h -- definitions for the get_mib2() function
3
+ *
4
+ * V. Abell <abe@cc.purdue.edu>
5
+ * Purdue University Computing Center
6
+ */
7
+
8
+
9
+ /*
10
+ * Copyright 1995 Purdue Research Foundation, West Lafayette, Indiana
11
+ * 47907. All rights reserved.
12
+ *
13
+ * Written by Victor A. Abell <abe@cc.purdue.edu>
14
+ *
15
+ * This software is not subject to any license of the American Telephone
16
+ * and Telegraph Company or the Regents of the University of California.
17
+ *
18
+ * Permission is granted to anyone to use this software for any purpose on
19
+ * any computer system, and to alter it and redistribute it freely, subject
20
+ * to the following restrictions:
21
+ *
22
+ * 1. Neither Victor A Abell nor Purdue University are responsible for
23
+ * any consequences of the use of this software.
24
+ *
25
+ * 2. The origin of this software must not be misrepresented, either by
26
+ * explicit claim or by omission. Credit to Victor A. Abell and Purdue
27
+ * University must appear in documentation and sources.
28
+ *
29
+ * 3. Altered versions must be plainly marked as such, and must not be
30
+ * misrepresented as being the original software.
31
+ *
32
+ * 4. This notice may not be removed or altered.
33
+ */
34
+
35
+ /*
36
+ * Altered for sigar:
37
+ * - remove static stuff to make thread-safe by Doug MacEachern (3/11/05)
38
+ */
39
+
40
+ #if !defined(GET_MIB2_H)
41
+ #define GET_MIB2_H
42
+
43
+
44
+ /*
45
+ * Required header files
46
+ */
47
+
48
+ #include <stropts.h>
49
+ #include <sys/types.h>
50
+ #include <sys/socket.h>
51
+ #include <sys/stream.h>
52
+ #include <sys/tihdr.h>
53
+ #include <sys/tiuser.h>
54
+ #include <inet/mib2.h>
55
+ #include <inet/led.h>
56
+
57
+
58
+ /*
59
+ * Miscellaneous definitions
60
+ */
61
+
62
+ #define GET_MIB2_ARPDEV "/dev/arp" /* ARP stream devi9ce */
63
+ #define GET_MIB2_ERRMSGL 1024 /* ErrMsg buffer length */
64
+ #define GET_MIB2_TCPSTREAM "tcp" /* TCP stream name */
65
+ #define GET_MIB2_UDPSTREAM "udp" /* UDP stream name */
66
+
67
+
68
+ /*
69
+ * get_mib2() response codes
70
+ *
71
+ * -1 End of MIB2 information
72
+ * 0 Next MIB2 structure returned
73
+ * >0 Error code
74
+ */
75
+
76
+ #define GET_MIB2_EOD -1 /* end of data */
77
+ #define GET_MIB2_OK 0 /* function succeeded */
78
+ #define GET_MIB2_ERR_ACK 1 /* getmsg() ACK error received */
79
+ #define GET_MIB2_ERR_ARPOPEN 2 /* error opening ARPDEV */
80
+ #define GET_MIB2_ERR_CLOSE 3 /* MIB2 access close error */
81
+ #define GET_MIB2_ERR_GETMSGD 4 /* error getting message data */
82
+ #define GET_MIB2_ERR_GETMSGR 5 /* error getting message reply */
83
+ #define GET_MIB2_ERR_NODATA 6 /* data expected; not received */
84
+ #define GET_MIB2_ERR_NOSPC 7 /* no malloc() space */
85
+ #define GET_MIB2_ERR_NOTOPEN 8 /* MIB2 access not open */
86
+ #define GET_MIB2_ERR_OPEN 9 /* MIB2 access open error */
87
+ #define GET_MIB2_ERR_PUTMSG 10 /* error putting request message */
88
+ #define GET_MIB2_ERR_TCPPUSH 11 /* error pushing TCPSTREAM */
89
+ #define GET_MIB2_ERR_UDPPUSH 12 /* error pushing UDPSTREAM */
90
+
91
+ #define GET_MIB2_ERR_MAX 13 /* maximum error number + 1 */
92
+
93
+
94
+ typedef struct {
95
+ char *db; /* data buffer */
96
+ int db_len; /* data buffer length */
97
+ char *smb; /* stream message buffer */
98
+ size_t smb_len; /* size of Smb[] */
99
+ int sd; /* stream device descriptor */
100
+ char errmsg[GET_MIB2_ERRMSGL]; /* error message buffer */
101
+ struct T_optmgmt_ack *op_ack; /* message ACK pointer */
102
+ struct strbuf ctlbuf; /* streams control buffer */
103
+ struct T_error_ack *err_ack; /* message error pointer */
104
+ struct opthdr *op; /* message option pointer */
105
+ struct T_optmgmt_req *req; /* message request pointer */
106
+ } solaris_mib2_t;
107
+
108
+ /*
109
+ * Function prototypes
110
+ */
111
+
112
+ int close_mib2( /* close acccess to MIB2 information */
113
+ solaris_mib2_t *mib2
114
+ );
115
+ int get_mib2( /* get MIB2 information */
116
+ solaris_mib2_t *mib2,
117
+ struct opthdr **opt, /* opthdr pointer return (see
118
+ * <sys/socket.h> */
119
+ char **data, /* data buffer return address */
120
+ int *datalen /* data buffer length return
121
+ * address */
122
+ );
123
+ int open_mib2( /* open acccess to MIB2 information */
124
+ solaris_mib2_t *mib2
125
+ );
126
+
127
+ #endif /* !defined(GET_MIB2_H) */
@@ -0,0 +1,181 @@
1
+ /*
2
+ * Copyright (c) 2004-2007 Hyperic, Inc.
3
+ * Copyright (c) 2009 SpringSource, Inc.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ #include "sigar.h"
19
+ #include "sigar_private.h"
20
+ #include "sigar_util.h"
21
+ #include "sigar_os.h"
22
+
23
+ int sigar_get_kstats(sigar_t *sigar)
24
+ {
25
+ kstat_ctl_t *kc = sigar->kc;
26
+ unsigned int i, id, ncpu = sysconf(_SC_NPROCESSORS_CONF);
27
+ int is_debug = SIGAR_LOG_IS_DEBUG(sigar);
28
+
29
+ if (ncpu != sigar->ncpu) {
30
+ if (!sigar->ks.lcpu) {
31
+ /* init */
32
+ sigar->ks.lcpu = ncpu;
33
+ sigar->ks.cpu = malloc(sizeof(*(sigar->ks.cpu)) * ncpu);
34
+ sigar->ks.cpu_info = malloc(sizeof(*(sigar->ks.cpu_info)) * ncpu);
35
+ sigar->ks.cpuid = malloc(sizeof(*(sigar->ks.cpuid)) * ncpu);
36
+ }
37
+ else {
38
+ sigar_log_printf(sigar, SIGAR_LOG_INFO,
39
+ "ncpu changed from %d to %d",
40
+ sigar->ncpu, ncpu);
41
+ if (ncpu > sigar->ks.lcpu) {
42
+ /* one or more cpus have been added */
43
+ sigar->ks.cpu = realloc(sigar->ks.cpu,
44
+ sizeof(*(sigar->ks.cpu)) * ncpu);
45
+ sigar->ks.cpu_info = realloc(sigar->ks.cpu_info,
46
+ sizeof(*(sigar->ks.cpu_info)) * ncpu);
47
+ sigar->ks.cpuid = realloc(sigar->ks.cpuid,
48
+ sizeof(*(sigar->ks.cpuid)) * ncpu);
49
+ sigar->ks.lcpu = ncpu;
50
+ }
51
+ /* else or more cpus have been removed */
52
+ }
53
+
54
+ sigar->ncpu = ncpu;
55
+
56
+ /* from man p_online:
57
+ * ``Processor numbers are integers,
58
+ * greater than or equal to 0,
59
+ * and are defined by the hardware platform.
60
+ * Processor numbers are not necessarily contiguous,
61
+ * but "not too sparse."``
62
+ * so we maintain our own mapping in ks.cpuid[]
63
+ */
64
+
65
+ /* lookup in order, which kstat chain may not be in */
66
+ for (i=0, id=0; i<ncpu; id++) {
67
+ kstat_t *cpu_info, *cpu_stat;
68
+
69
+ if (!(cpu_info = kstat_lookup(kc, "cpu_info", id, NULL))) {
70
+ continue;
71
+ }
72
+
73
+ if (!(cpu_stat = kstat_lookup(kc, "cpu_stat", id, NULL))) {
74
+ /* XXX warn, faulted cpu? */
75
+ }
76
+
77
+ sigar->ks.cpu_info[i] = cpu_info;
78
+ sigar->ks.cpu[i] = cpu_stat;
79
+ sigar->ks.cpuid[i] = id;
80
+
81
+ if (is_debug) {
82
+ sigar_log_printf(sigar, SIGAR_LOG_DEBUG,
83
+ "cpu %d id=%d", i, sigar->ks.cpuid[i]);
84
+ }
85
+ i++;
86
+ }
87
+ }
88
+
89
+ sigar->ks.system = kstat_lookup(kc, "unix", -1, "system_misc");
90
+ sigar->ks.syspages = kstat_lookup(kc, "unix", -1, "system_pages");
91
+ sigar->ks.mempages = kstat_lookup(kc, "bunyip", -1, "mempages");
92
+
93
+ return SIGAR_OK;
94
+ }
95
+
96
+ SIGAR_INLINE kid_t sigar_kstat_update(sigar_t *sigar)
97
+ {
98
+ kid_t id = kstat_chain_update(sigar->kc);
99
+
100
+ switch (id) {
101
+ case -1:
102
+ sigar_log_printf(sigar, SIGAR_LOG_ERROR,
103
+ "kstat_chain_update error: %s",
104
+ sigar_strerror(sigar, errno));
105
+ break;
106
+ case 0:
107
+ /* up-to-date */
108
+ break;
109
+ default:
110
+ sigar_get_kstats(sigar);
111
+ sigar_log(sigar, SIGAR_LOG_DEBUG,
112
+ "kstat chain updated");
113
+ break;
114
+ }
115
+
116
+ return id;
117
+ }
118
+
119
+ /*
120
+ * bincompat is not possible with certain kstat data structures between
121
+ * solaris 2.6, 2.7, 2.8, etc. alternative is to use kstat_data_lookup()
122
+ * which means everytime we want a stat, must do a linear search
123
+ * of ksp->ks_data. eek. so we meet half way and do the search for
124
+ * each key once per sigar_t instance. once the initial search has
125
+ * been done, we have a table of offsets to quickly access the stats via
126
+ * ksp->ks_data + offset. this gives us bincompat without the overhead
127
+ * of many kstat_data_lookup calls.
128
+ */
129
+ static SIGAR_INLINE int kstat_named_offset(kstat_t *ksp, const char *name)
130
+ {
131
+ unsigned int i;
132
+ kstat_named_t *kn;
133
+
134
+ for (i=0, kn=ksp->ks_data;
135
+ i<ksp->ks_ndata;
136
+ i++, kn++)
137
+ {
138
+ if (strEQ(kn->name, name)) {
139
+ return i;
140
+ }
141
+ }
142
+
143
+ return -2; /* not found */
144
+ }
145
+
146
+ static char *kstat_keys_system[] = {
147
+ "boot_time",
148
+ "avenrun_1min",
149
+ "avenrun_5min",
150
+ "avenrun_15min",
151
+ NULL
152
+ };
153
+
154
+ static char *kstat_keys_mempages[] = {
155
+ "pages_anon",
156
+ "pages_exec",
157
+ "pages_vnode",
158
+ NULL
159
+ };
160
+
161
+ static char *kstat_keys_syspages[] = {
162
+ "pagesfree",
163
+ NULL
164
+ };
165
+
166
+ static char **kstat_keys[] = {
167
+ kstat_keys_system,
168
+ kstat_keys_mempages,
169
+ kstat_keys_syspages,
170
+ };
171
+
172
+ void sigar_koffsets_lookup(kstat_t *ksp, int *offsets, int kidx)
173
+ {
174
+ int i;
175
+ char **keys = kstat_keys[kidx];
176
+
177
+ for (i=0; keys[i]; i++) {
178
+ offsets[i] = kstat_named_offset(ksp, keys[i]);
179
+ }
180
+ }
181
+