sigar-test 0.7.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +201 -0
- data/NOTICE +117 -0
- data/README +2 -0
- data/Rakefile +105 -0
- data/bindings/SigarBuild.pm +301 -0
- data/bindings/SigarWrapper.pm +3025 -0
- data/bindings/ruby/extconf.rb +131 -0
- data/bindings/ruby/rbsigar.c +888 -0
- data/include/sigar.h +984 -0
- data/include/sigar_fileinfo.h +157 -0
- data/include/sigar_format.h +65 -0
- data/include/sigar_getline.h +18 -0
- data/include/sigar_log.h +80 -0
- data/include/sigar_private.h +429 -0
- data/include/sigar_ptql.h +53 -0
- data/include/sigar_util.h +197 -0
- data/src/os/aix/aix_sigar.c +2168 -0
- data/src/os/aix/sigar_os.h +73 -0
- data/src/os/darwin/Info.plist.in +27 -0
- data/src/os/darwin/darwin_sigar.c +3718 -0
- data/src/os/darwin/sigar_os.h +80 -0
- data/src/os/hpux/hpux_sigar.c +1361 -0
- data/src/os/hpux/sigar_os.h +49 -0
- data/src/os/linux/linux_sigar.c +2810 -0
- data/src/os/linux/sigar_os.h +82 -0
- data/src/os/solaris/get_mib2.c +321 -0
- data/src/os/solaris/get_mib2.h +127 -0
- data/src/os/solaris/kstats.c +181 -0
- data/src/os/solaris/procfs.c +97 -0
- data/src/os/solaris/sigar_os.h +224 -0
- data/src/os/solaris/solaris_sigar.c +2732 -0
- data/src/os/win32/peb.c +212 -0
- data/src/os/win32/sigar.rc.in +40 -0
- data/src/os/win32/sigar_os.h +685 -0
- data/src/os/win32/sigar_pdh.h +47 -0
- data/src/os/win32/win32_sigar.c +4109 -0
- data/src/sigar.c +2444 -0
- data/src/sigar_cache.c +253 -0
- data/src/sigar_fileinfo.c +815 -0
- data/src/sigar_format.c +696 -0
- data/src/sigar_getline.c +1849 -0
- data/src/sigar_ptql.c +1976 -0
- data/src/sigar_signal.c +216 -0
- data/src/sigar_util.c +1060 -0
- data/src/sigar_version.c.in +22 -0
- data/src/sigar_version_autoconf.c.in +22 -0
- data/version.properties +11 -0
- metadata +91 -0
@@ -0,0 +1,97 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2004, 2006 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
|
+
#include "sigar.h"
|
18
|
+
#include "sigar_private.h"
|
19
|
+
#include "sigar_util.h"
|
20
|
+
#include "sigar_os.h"
|
21
|
+
|
22
|
+
#define my_pread(fd, ptr, type, offset) \
|
23
|
+
(pread(fd, ptr, sizeof(type), offset) == sizeof(type))
|
24
|
+
|
25
|
+
int sigar_proc_psinfo_get(sigar_t *sigar, sigar_pid_t pid)
|
26
|
+
{
|
27
|
+
int fd, retval = SIGAR_OK;
|
28
|
+
char buffer[BUFSIZ];
|
29
|
+
time_t timenow = time(NULL);
|
30
|
+
|
31
|
+
if (sigar->pinfo == NULL) {
|
32
|
+
sigar->pinfo = malloc(sizeof(*sigar->pinfo));
|
33
|
+
}
|
34
|
+
|
35
|
+
if (sigar->last_pid == pid) {
|
36
|
+
if ((timenow - sigar->last_getprocs) < SIGAR_LAST_PROC_EXPIRE) {
|
37
|
+
return SIGAR_OK;
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
sigar->last_pid = pid;
|
42
|
+
sigar->last_getprocs = timenow;
|
43
|
+
|
44
|
+
(void)SIGAR_PROC_FILENAME(buffer, pid, "/psinfo");
|
45
|
+
|
46
|
+
if ((fd = open(buffer, O_RDONLY)) < 0) {
|
47
|
+
return ESRCH;
|
48
|
+
}
|
49
|
+
|
50
|
+
if (!my_pread(fd, sigar->pinfo, psinfo_t, 0)) {
|
51
|
+
retval = errno;
|
52
|
+
}
|
53
|
+
|
54
|
+
close(fd);
|
55
|
+
|
56
|
+
return retval;
|
57
|
+
}
|
58
|
+
|
59
|
+
int sigar_proc_usage_get(sigar_t *sigar, prusage_t *prusage, sigar_pid_t pid)
|
60
|
+
{
|
61
|
+
int fd, retval = SIGAR_OK;
|
62
|
+
char buffer[BUFSIZ];
|
63
|
+
|
64
|
+
(void)SIGAR_PROC_FILENAME(buffer, pid, "/usage");
|
65
|
+
|
66
|
+
if ((fd = open(buffer, O_RDONLY)) < 0) {
|
67
|
+
return ESRCH;
|
68
|
+
}
|
69
|
+
|
70
|
+
if (!my_pread(fd, prusage, prusage_t, 0)) {
|
71
|
+
retval = errno;
|
72
|
+
}
|
73
|
+
|
74
|
+
close(fd);
|
75
|
+
|
76
|
+
return retval;
|
77
|
+
}
|
78
|
+
|
79
|
+
int sigar_proc_status_get(sigar_t *sigar, pstatus_t *pstatus, sigar_pid_t pid)
|
80
|
+
{
|
81
|
+
int fd, retval = SIGAR_OK;
|
82
|
+
char buffer[BUFSIZ];
|
83
|
+
|
84
|
+
(void)SIGAR_PROC_FILENAME(buffer, pid, "/status");
|
85
|
+
|
86
|
+
if ((fd = open(buffer, O_RDONLY)) < 0) {
|
87
|
+
return ESRCH;
|
88
|
+
}
|
89
|
+
|
90
|
+
if (!my_pread(fd, pstatus, pstatus_t, 0)) {
|
91
|
+
retval = errno;
|
92
|
+
}
|
93
|
+
|
94
|
+
close(fd);
|
95
|
+
|
96
|
+
return retval;
|
97
|
+
}
|
@@ -0,0 +1,224 @@
|
|
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
|
+
#ifndef SIGAR_OS_H
|
19
|
+
#define SIGAR_OS_H
|
20
|
+
|
21
|
+
#ifndef _POSIX_PTHREAD_SEMANTICS
|
22
|
+
#define _POSIX_PTHREAD_SEMANTICS
|
23
|
+
#endif
|
24
|
+
|
25
|
+
typedef unsigned long long int u_int64_t;
|
26
|
+
|
27
|
+
#include <ctype.h>
|
28
|
+
#include <assert.h>
|
29
|
+
#ifndef DMALLOC
|
30
|
+
#include <malloc.h>
|
31
|
+
#endif
|
32
|
+
#include <unistd.h>
|
33
|
+
#include <fcntl.h>
|
34
|
+
#include <stdio.h>
|
35
|
+
#include <errno.h>
|
36
|
+
#include <stdlib.h>
|
37
|
+
#include <sys/types.h>
|
38
|
+
#include <sys/processor.h>
|
39
|
+
#include <sys/sysinfo.h>
|
40
|
+
#include <sys/param.h>
|
41
|
+
|
42
|
+
#include <kstat.h>
|
43
|
+
#include <procfs.h>
|
44
|
+
|
45
|
+
#include "get_mib2.h"
|
46
|
+
|
47
|
+
/* avoid -Wall warning since solaris doesnt have a prototype for this */
|
48
|
+
int getdomainname(char *, int);
|
49
|
+
|
50
|
+
typedef struct {
|
51
|
+
kstat_t **ks;
|
52
|
+
int num;
|
53
|
+
char *name;
|
54
|
+
int nlen;
|
55
|
+
} kstat_list_t;
|
56
|
+
|
57
|
+
SIGAR_INLINE kid_t sigar_kstat_update(sigar_t *sigar);
|
58
|
+
|
59
|
+
int sigar_get_kstats(sigar_t *sigar);
|
60
|
+
|
61
|
+
void sigar_init_multi_kstats(sigar_t *sigar);
|
62
|
+
|
63
|
+
void sigar_free_multi_kstats(sigar_t *sigar);
|
64
|
+
|
65
|
+
int sigar_get_multi_kstats(sigar_t *sigar,
|
66
|
+
kstat_list_t *kl,
|
67
|
+
const char *name,
|
68
|
+
kstat_t **retval);
|
69
|
+
|
70
|
+
void sigar_koffsets_lookup(kstat_t *ksp, int *offsets, int kidx);
|
71
|
+
|
72
|
+
int sigar_proc_psinfo_get(sigar_t *sigar, sigar_pid_t pid);
|
73
|
+
|
74
|
+
int sigar_proc_usage_get(sigar_t *sigar, prusage_t *prusage, sigar_pid_t pid);
|
75
|
+
|
76
|
+
int sigar_proc_status_get(sigar_t *sigar, pstatus_t *pstatus, sigar_pid_t pid);
|
77
|
+
|
78
|
+
#define CPU_ONLINE(n) \
|
79
|
+
(p_online(n, P_STATUS) == P_ONLINE)
|
80
|
+
|
81
|
+
typedef enum {
|
82
|
+
KSTAT_SYSTEM_BOOT_TIME,
|
83
|
+
KSTAT_SYSTEM_LOADAVG_1,
|
84
|
+
KSTAT_SYSTEM_LOADAVG_2,
|
85
|
+
KSTAT_SYSTEM_LOADAVG_3,
|
86
|
+
KSTAT_SYSTEM_MAX
|
87
|
+
} kstat_system_off_e;
|
88
|
+
|
89
|
+
typedef enum {
|
90
|
+
KSTAT_MEMPAGES_ANON,
|
91
|
+
KSTAT_MEMPAGES_EXEC,
|
92
|
+
KSTAT_MEMPAGES_VNODE,
|
93
|
+
KSTAT_MEMPAGES_MAX
|
94
|
+
} kstat_mempages_off_e;
|
95
|
+
|
96
|
+
typedef enum {
|
97
|
+
KSTAT_SYSPAGES_FREE,
|
98
|
+
KSTAT_SYSPAGES_MAX
|
99
|
+
} kstat_syspages_off_e;
|
100
|
+
|
101
|
+
enum {
|
102
|
+
KSTAT_KEYS_system,
|
103
|
+
KSTAT_KEYS_mempages,
|
104
|
+
KSTAT_KEYS_syspages,
|
105
|
+
} kstat_keys_e;
|
106
|
+
|
107
|
+
typedef struct ps_prochandle * (*proc_grab_func_t)(pid_t, int, int *);
|
108
|
+
|
109
|
+
typedef void (*proc_free_func_t)(struct ps_prochandle *);
|
110
|
+
|
111
|
+
typedef int (*proc_create_agent_func_t)(struct ps_prochandle *);
|
112
|
+
|
113
|
+
typedef void (*proc_destroy_agent_func_t)(struct ps_prochandle *);
|
114
|
+
|
115
|
+
typedef void (*proc_objname_func_t)(struct ps_prochandle *,
|
116
|
+
uintptr_t, const char *, size_t);
|
117
|
+
|
118
|
+
typedef char * (*proc_dirname_func_t)(const char *, char *, size_t);
|
119
|
+
|
120
|
+
typedef char * (*proc_exename_func_t)(struct ps_prochandle *, char *, size_t);
|
121
|
+
|
122
|
+
typedef int (*proc_fstat64_func_t)(struct ps_prochandle *, int, void *);
|
123
|
+
|
124
|
+
typedef int (*proc_getsockopt_func_t)(struct ps_prochandle *,
|
125
|
+
int, int, int, void *, int *);
|
126
|
+
|
127
|
+
typedef int (*proc_getsockname_func_t)(struct ps_prochandle *,
|
128
|
+
int, struct sockaddr *, socklen_t *);
|
129
|
+
|
130
|
+
struct sigar_t {
|
131
|
+
SIGAR_T_BASE;
|
132
|
+
|
133
|
+
int solaris_version;
|
134
|
+
int use_ucb_ps;
|
135
|
+
|
136
|
+
kstat_ctl_t *kc;
|
137
|
+
|
138
|
+
/* kstat_lookup() as needed */
|
139
|
+
struct {
|
140
|
+
kstat_t **cpu;
|
141
|
+
kstat_t **cpu_info;
|
142
|
+
processorid_t *cpuid;
|
143
|
+
unsigned int lcpu; /* number malloced slots in the cpu array above */
|
144
|
+
kstat_t *system;
|
145
|
+
kstat_t *syspages;
|
146
|
+
kstat_t *mempages;
|
147
|
+
} ks;
|
148
|
+
|
149
|
+
struct {
|
150
|
+
int system[KSTAT_SYSTEM_MAX];
|
151
|
+
int mempages[KSTAT_MEMPAGES_MAX];
|
152
|
+
int syspages[KSTAT_SYSPAGES_MAX];
|
153
|
+
} koffsets;
|
154
|
+
|
155
|
+
int pagesize;
|
156
|
+
|
157
|
+
time_t last_getprocs;
|
158
|
+
sigar_pid_t last_pid;
|
159
|
+
psinfo_t *pinfo;
|
160
|
+
sigar_cpu_list_t cpulist;
|
161
|
+
|
162
|
+
/* libproc.so interface */
|
163
|
+
void *plib;
|
164
|
+
proc_grab_func_t pgrab;
|
165
|
+
proc_free_func_t pfree;
|
166
|
+
proc_create_agent_func_t pcreate_agent;
|
167
|
+
proc_destroy_agent_func_t pdestroy_agent;
|
168
|
+
proc_objname_func_t pobjname;
|
169
|
+
proc_dirname_func_t pdirname;
|
170
|
+
proc_exename_func_t pexename;
|
171
|
+
proc_fstat64_func_t pfstat64;
|
172
|
+
proc_getsockopt_func_t pgetsockopt;
|
173
|
+
proc_getsockname_func_t pgetsockname;
|
174
|
+
|
175
|
+
sigar_cache_t *pargs;
|
176
|
+
|
177
|
+
solaris_mib2_t mib2;
|
178
|
+
};
|
179
|
+
|
180
|
+
#ifdef SIGAR_64BIT
|
181
|
+
#define KSTAT_UINT ui64
|
182
|
+
#else
|
183
|
+
#define KSTAT_UINT ui32
|
184
|
+
#endif
|
185
|
+
|
186
|
+
#define kSTAT_exists(v, type) \
|
187
|
+
(sigar->koffsets.type[v] != -2)
|
188
|
+
|
189
|
+
#define kSTAT_ptr(v, type) \
|
190
|
+
((kstat_named_t *)ksp->ks_data + sigar->koffsets.type[v])
|
191
|
+
|
192
|
+
#define kSTAT_uint(v, type) \
|
193
|
+
(kSTAT_exists(v, type) ? kSTAT_ptr(v, type)->value.KSTAT_UINT : 0)
|
194
|
+
|
195
|
+
#define kSTAT_ui32(v, type) \
|
196
|
+
(kSTAT_exists(v, type) ? kSTAT_ptr(v, type)->value.ui32 : 0)
|
197
|
+
|
198
|
+
#define kSYSTEM(v) kSTAT_ui32(v, system)
|
199
|
+
|
200
|
+
#define kMEMPAGES(v) kSTAT_uint(v, mempages)
|
201
|
+
|
202
|
+
#define kSYSPAGES(v) kSTAT_uint(v, syspages)
|
203
|
+
|
204
|
+
#define sigar_koffsets_init(sigar, ksp, type) \
|
205
|
+
if (sigar->koffsets.type[0] == -1) \
|
206
|
+
sigar_koffsets_lookup(ksp, sigar->koffsets.type, KSTAT_KEYS_##type)
|
207
|
+
|
208
|
+
#define sigar_koffsets_init_system(sigar, ksp) \
|
209
|
+
sigar_koffsets_init(sigar, ksp, system)
|
210
|
+
|
211
|
+
#define sigar_koffsets_init_mempages(sigar, ksp) \
|
212
|
+
sigar_koffsets_init(sigar, ksp, mempages)
|
213
|
+
|
214
|
+
#define sigar_koffsets_init_syspages(sigar, ksp) \
|
215
|
+
sigar_koffsets_init(sigar, ksp, syspages)
|
216
|
+
|
217
|
+
#define HAVE_READDIR_R
|
218
|
+
#define HAVE_GETPWNAM_R
|
219
|
+
#define HAVE_GETPWUID_R
|
220
|
+
|
221
|
+
#define SIGAR_EMIB2 (SIGAR_OS_START_ERROR+1)
|
222
|
+
|
223
|
+
#endif /* SIGAR_OS_H */
|
224
|
+
|