linux_stat 2.5.3 → 2.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.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/exe/linuxstat.rb +1 -0
- data/ext/fs_stat/disk_stat.h +20 -18
- data/ext/fs_stat/extconf.rb +2 -0
- data/ext/fs_stat/fs_stat.c +21 -31
- data/ext/fs_stat/sector_size.h +9 -9
- data/ext/misc/integer/extconf.rb +3 -0
- data/ext/misc/integer/integer?.c +23 -31
- data/ext/nftw/extconf.rb +11 -0
- data/ext/nftw/nftw.c +306 -0
- data/ext/nproc/extconf.rb +2 -0
- data/ext/nproc/nproc.c +10 -18
- data/ext/procfs/extconf.rb +2 -0
- data/ext/procfs/loadavg_pid.h +8 -8
- data/ext/procfs/procfs.c +16 -16
- data/ext/procfs/stat.h +94 -94
- data/ext/procfs/statm.h +71 -71
- data/ext/procfs/uptime.h +8 -8
- data/ext/sysconf/extconf.rb +2 -0
- data/ext/sysconf/sysconf.c +99 -101
- data/ext/sysinfo/extconf.rb +2 -0
- data/ext/sysinfo/sysinfo.c +129 -140
- data/ext/utsname/extconf.rb +2 -0
- data/ext/utsname/utsname.c +42 -46
- data/lib/linux_stat/ftw.rb +101 -0
- data/lib/linux_stat/net.rb +2 -2
- data/lib/linux_stat/prettify_bytes.rb +66 -68
- data/lib/linux_stat/process_info.rb +8 -7
- data/lib/linux_stat/version.rb +1 -1
- data/lib/linux_stat.rb +4 -0
- metadata +7 -3
data/ext/sysconf/sysconf.c
CHANGED
@@ -1,158 +1,156 @@
|
|
1
1
|
#include <unistd.h>
|
2
2
|
#include "ruby.h"
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
#elif defined(__clang__)
|
8
|
-
#pragma clang optimize on
|
9
|
-
#pragma clang diagnostic warning "-Wall"
|
10
|
-
#elif defined(__INTEL_COMPILER)
|
11
|
-
#pragma intel optimization_level 3
|
12
|
-
#endif
|
4
|
+
static VALUE getTick(VALUE obj) {
|
5
|
+
int val = sysconf(_SC_CLK_TCK);
|
6
|
+
if (val < 0) return Qnil;
|
13
7
|
|
14
|
-
|
15
|
-
int val = sysconf(_SC_CLK_TCK) ;
|
16
|
-
if (val < 0) return Qnil ;
|
17
|
-
|
18
|
-
return INT2FIX(val) ;
|
8
|
+
return INT2FIX(val);
|
19
9
|
}
|
20
10
|
|
21
|
-
static VALUE getChildMax(
|
22
|
-
long
|
23
|
-
if (val < 0) return Qnil
|
11
|
+
static VALUE getChildMax(VALUE obj) {
|
12
|
+
long int val = sysconf(_SC_CHILD_MAX);
|
13
|
+
if (val < 0) return Qnil;
|
24
14
|
|
25
|
-
return
|
15
|
+
return LONG2NUM(val);
|
26
16
|
}
|
27
17
|
|
28
|
-
static VALUE getHostnameMax(
|
29
|
-
long
|
30
|
-
if (val < 0) return Qnil
|
18
|
+
static VALUE getHostnameMax(VALUE obj) {
|
19
|
+
long val = sysconf(_SC_HOST_NAME_MAX);
|
20
|
+
if (val < 0) return Qnil;
|
31
21
|
|
32
|
-
return
|
22
|
+
return LONG2NUM(val);
|
33
23
|
}
|
34
24
|
|
35
|
-
static VALUE getLoginNameMax(
|
36
|
-
long
|
37
|
-
if (val < 0) return Qnil
|
25
|
+
static VALUE getLoginNameMax(VALUE obj) {
|
26
|
+
long val = sysconf(_SC_LOGIN_NAME_MAX);
|
27
|
+
if (val < 0) return Qnil;
|
38
28
|
|
39
|
-
return
|
29
|
+
return LONG2NUM(val);
|
40
30
|
}
|
41
31
|
|
42
|
-
static VALUE getOpenMax(
|
43
|
-
long
|
44
|
-
if (val < 0) return Qnil
|
32
|
+
static VALUE getOpenMax(VALUE obj) {
|
33
|
+
long val = sysconf(_SC_OPEN_MAX);
|
34
|
+
if (val < 0) return Qnil;
|
45
35
|
|
46
|
-
return
|
36
|
+
return LONG2NUM(val);
|
47
37
|
}
|
48
38
|
|
49
|
-
static VALUE getPageSize(
|
50
|
-
|
51
|
-
if (val < 0) return Qnil
|
39
|
+
static VALUE getPageSize(VALUE obj) {
|
40
|
+
long val = sysconf(_SC_PAGESIZE);
|
41
|
+
if (val < 0) return Qnil;
|
52
42
|
|
53
|
-
return
|
43
|
+
return LONG2NUM(val);
|
54
44
|
}
|
55
45
|
|
56
|
-
static VALUE getStreamMax(
|
57
|
-
long
|
58
|
-
if (val < 0) return Qnil
|
46
|
+
static VALUE getStreamMax(VALUE obj) {
|
47
|
+
long val = sysconf(_SC_STREAM_MAX);
|
48
|
+
if (val < 0) return Qnil;
|
59
49
|
|
60
|
-
return
|
50
|
+
return LONG2NUM(val);
|
61
51
|
}
|
62
52
|
|
63
|
-
static VALUE getTTYNameMax(
|
64
|
-
long
|
65
|
-
if (val < 0) return Qnil
|
53
|
+
static VALUE getTTYNameMax(VALUE obj) {
|
54
|
+
long val = sysconf(_SC_TTY_NAME_MAX);
|
55
|
+
if (val < 0) return Qnil;
|
66
56
|
|
67
|
-
return
|
57
|
+
return LONG2NUM(val);
|
68
58
|
}
|
69
59
|
|
70
|
-
static VALUE getPosixVersion(
|
71
|
-
long
|
72
|
-
if (val < 0) return Qnil
|
60
|
+
static VALUE getPosixVersion(VALUE obj) {
|
61
|
+
long val = sysconf(_SC_VERSION);
|
62
|
+
if (val < 0) return Qnil;
|
73
63
|
|
74
|
-
return
|
64
|
+
return LONG2NUM(val);
|
75
65
|
}
|
76
66
|
|
77
|
-
static VALUE getLineMax(
|
78
|
-
long
|
79
|
-
if (val < 0) return Qnil
|
67
|
+
static VALUE getLineMax(VALUE obj) {
|
68
|
+
long val = sysconf(_SC_LINE_MAX);
|
69
|
+
if (val < 0) return Qnil;
|
80
70
|
|
81
|
-
return
|
71
|
+
return LONG2NUM(val);
|
82
72
|
}
|
83
73
|
|
84
|
-
static VALUE getExprNestMax(
|
85
|
-
long
|
86
|
-
if (val < 0) return Qnil
|
74
|
+
static VALUE getExprNestMax(VALUE obj) {
|
75
|
+
long val = sysconf(_SC_EXPR_NEST_MAX);
|
76
|
+
if (val < 0) return Qnil;
|
87
77
|
|
88
|
-
return
|
78
|
+
return LONG2NUM(val);
|
89
79
|
}
|
90
80
|
|
91
|
-
static VALUE getProcessorConfigured(
|
92
|
-
long val = sysconf(_SC_NPROCESSORS_CONF)
|
93
|
-
if (val < 0) return Qnil
|
81
|
+
static VALUE getProcessorConfigured(VALUE obj) {
|
82
|
+
long val = sysconf(_SC_NPROCESSORS_CONF);
|
83
|
+
if (val < 0) return Qnil;
|
94
84
|
|
95
|
-
return LONG2NUM(val)
|
85
|
+
return LONG2NUM(val);
|
96
86
|
}
|
97
87
|
|
98
|
-
static VALUE getProcessorOnline(
|
99
|
-
long val = sysconf(_SC_NPROCESSORS_ONLN)
|
100
|
-
if (val < 0) return Qnil
|
88
|
+
static VALUE getProcessorOnline(VALUE obj) {
|
89
|
+
long val = sysconf(_SC_NPROCESSORS_ONLN);
|
90
|
+
if (val < 0) return Qnil;
|
101
91
|
|
102
|
-
return LONG2NUM(val)
|
92
|
+
return LONG2NUM(val);
|
103
93
|
}
|
104
94
|
|
105
|
-
static VALUE getUser(
|
106
|
-
|
107
|
-
|
95
|
+
static VALUE getUser(VALUE obj) {
|
96
|
+
long login_max = sysconf(_SC_LOGIN_NAME_MAX);
|
97
|
+
if (login_max <= 0) return rb_str_new_cstr("");
|
98
|
+
|
99
|
+
char name[login_max + 1];
|
100
|
+
|
101
|
+
if (getlogin_r(name, sizeof(name)) != 0) {
|
102
|
+
return rb_str_new_cstr("");
|
103
|
+
}
|
104
|
+
|
105
|
+
return rb_str_new_cstr(name);
|
108
106
|
}
|
109
107
|
|
110
|
-
static VALUE getUID(
|
111
|
-
return UINT2NUM((unsigned int) getuid())
|
108
|
+
static VALUE getUID(VALUE obj) {
|
109
|
+
return UINT2NUM((unsigned int) getuid());
|
112
110
|
}
|
113
111
|
|
114
112
|
static VALUE getGID(VALUE obj) {
|
115
|
-
return UINT2NUM((unsigned int) getgid())
|
113
|
+
return UINT2NUM((unsigned int) getgid());
|
116
114
|
}
|
117
115
|
|
118
|
-
static VALUE getEUID(
|
119
|
-
return UINT2NUM((unsigned int) geteuid())
|
116
|
+
static VALUE getEUID(VALUE obj) {
|
117
|
+
return UINT2NUM((unsigned int) geteuid());
|
120
118
|
}
|
121
119
|
|
122
|
-
static VALUE getHostname(
|
123
|
-
int h_max = sysconf(_SC_HOST_NAME_MAX) + 1
|
124
|
-
char hostname[h_max]
|
120
|
+
static VALUE getHostname(VALUE obj) {
|
121
|
+
int h_max = sysconf(_SC_HOST_NAME_MAX) + 1;
|
122
|
+
char hostname[h_max + 1];
|
125
123
|
|
126
|
-
char status = gethostname(hostname, h_max)
|
124
|
+
char status = gethostname(hostname, h_max);
|
127
125
|
|
128
|
-
return (status < 0) ? rb_str_new_cstr("") : rb_str_new_cstr(hostname)
|
126
|
+
return (status < 0) ? rb_str_new_cstr("") : rb_str_new_cstr(hostname);
|
129
127
|
}
|
130
128
|
|
131
129
|
void Init_sysconf() {
|
132
|
-
VALUE _linux_stat = rb_define_module("LinuxStat")
|
133
|
-
VALUE _sysconf = rb_define_module_under(_linux_stat, "Sysconf")
|
134
|
-
|
135
|
-
rb_define_module_function(_sysconf, "sc_clk_tck", getTick, 0)
|
136
|
-
rb_define_module_function(_sysconf, "child_max", getChildMax, 0)
|
137
|
-
rb_define_module_function(_sysconf, "hostname_max", getHostnameMax, 0)
|
138
|
-
rb_define_module_function(_sysconf, "login_name_max", getLoginNameMax, 0)
|
139
|
-
rb_define_module_function(_sysconf, "open_max", getOpenMax, 0)
|
140
|
-
rb_define_module_function(_sysconf, "pagesize", getPageSize, 0)
|
141
|
-
rb_define_module_function(_sysconf, "stream_max", getStreamMax, 0)
|
142
|
-
rb_define_module_function(_sysconf, "tty_name_max", getTTYNameMax, 0)
|
143
|
-
rb_define_module_function(_sysconf, "posix_version", getPosixVersion, 0)
|
144
|
-
rb_define_module_function(_sysconf, "line_max", getLineMax, 0)
|
145
|
-
rb_define_module_function(_sysconf, "expr_nest_max", getExprNestMax, 0)
|
146
|
-
|
147
|
-
rb_define_module_function(_sysconf, "processor_online", getProcessorOnline, 0)
|
148
|
-
rb_define_module_function(_sysconf, "processor_configured", getProcessorConfigured, 0)
|
149
|
-
|
150
|
-
rb_define_module_function(_sysconf, "get_uid", getUID, 0)
|
151
|
-
rb_define_module_function(_sysconf, "get_gid", getGID, 0)
|
152
|
-
rb_define_module_function(_sysconf, "get_euid", getEUID, 0)
|
153
|
-
|
154
|
-
rb_define_module_function(_sysconf, "get_user", getUser, 0)
|
155
|
-
rb_define_module_function(_sysconf, "get_login", getUser, 0)
|
156
|
-
|
157
|
-
rb_define_module_function(_sysconf, "hostname", getHostname, 0)
|
130
|
+
VALUE _linux_stat = rb_define_module("LinuxStat");
|
131
|
+
VALUE _sysconf = rb_define_module_under(_linux_stat, "Sysconf");
|
132
|
+
|
133
|
+
rb_define_module_function(_sysconf, "sc_clk_tck", getTick, 0);
|
134
|
+
rb_define_module_function(_sysconf, "child_max", getChildMax, 0);
|
135
|
+
rb_define_module_function(_sysconf, "hostname_max", getHostnameMax, 0);
|
136
|
+
rb_define_module_function(_sysconf, "login_name_max", getLoginNameMax, 0);
|
137
|
+
rb_define_module_function(_sysconf, "open_max", getOpenMax, 0);
|
138
|
+
rb_define_module_function(_sysconf, "pagesize", getPageSize, 0);
|
139
|
+
rb_define_module_function(_sysconf, "stream_max", getStreamMax, 0);
|
140
|
+
rb_define_module_function(_sysconf, "tty_name_max", getTTYNameMax, 0);
|
141
|
+
rb_define_module_function(_sysconf, "posix_version", getPosixVersion, 0);
|
142
|
+
rb_define_module_function(_sysconf, "line_max", getLineMax, 0);
|
143
|
+
rb_define_module_function(_sysconf, "expr_nest_max", getExprNestMax, 0);
|
144
|
+
|
145
|
+
rb_define_module_function(_sysconf, "processor_online", getProcessorOnline, 0);
|
146
|
+
rb_define_module_function(_sysconf, "processor_configured", getProcessorConfigured, 0);
|
147
|
+
|
148
|
+
rb_define_module_function(_sysconf, "get_uid", getUID, 0);
|
149
|
+
rb_define_module_function(_sysconf, "get_gid", getGID, 0);
|
150
|
+
rb_define_module_function(_sysconf, "get_euid", getEUID, 0);
|
151
|
+
|
152
|
+
rb_define_module_function(_sysconf, "get_user", getUser, 0);
|
153
|
+
rb_define_module_function(_sysconf, "get_login", getUser, 0);
|
154
|
+
|
155
|
+
rb_define_module_function(_sysconf, "hostname", getHostname, 0);
|
158
156
|
}
|
data/ext/sysinfo/extconf.rb
CHANGED
data/ext/sysinfo/sysinfo.c
CHANGED
@@ -1,177 +1,166 @@
|
|
1
1
|
#include <sys/sysinfo.h>
|
2
2
|
#include "ruby.h"
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
#endif
|
13
|
-
|
14
|
-
static struct sysinfo info ;
|
15
|
-
|
16
|
-
static VALUE totalram(volatile VALUE obj) {
|
17
|
-
char status = sysinfo(&info) ;
|
18
|
-
if (status < 0) return Qnil ;
|
19
|
-
|
20
|
-
VALUE _rb_v = ULL2NUM((unsigned long long) info.totalram) ;
|
21
|
-
VALUE _rb_mem_unit = ULL2NUM((unsigned long long) info.mem_unit) ;
|
22
|
-
return rb_funcallv_public(_rb_v, rb_intern("*"), 1, &_rb_mem_unit) ;
|
4
|
+
static VALUE totalram(VALUE obj) {
|
5
|
+
struct sysinfo info;
|
6
|
+
char status = sysinfo(&info);
|
7
|
+
if (status < 0) return Qnil;
|
8
|
+
|
9
|
+
VALUE _rb_v = ULL2NUM((unsigned long long) info.totalram);
|
10
|
+
VALUE _rb_mem_unit = ULL2NUM((unsigned long long) info.mem_unit);
|
11
|
+
return rb_funcallv_public(_rb_v, rb_intern("*"), 1, &_rb_mem_unit);
|
23
12
|
}
|
24
13
|
|
25
|
-
static VALUE freeram(
|
26
|
-
|
27
|
-
|
14
|
+
static VALUE freeram(VALUE obj) {
|
15
|
+
struct sysinfo info;
|
16
|
+
char status = sysinfo(&info);
|
17
|
+
if (status < 0) return Qnil;
|
28
18
|
|
29
|
-
VALUE _rb_v = ULL2NUM((unsigned long long) info.freeram)
|
30
|
-
VALUE _rb_mem_unit = ULL2NUM((unsigned long long) info.mem_unit)
|
31
|
-
return rb_funcallv_public(_rb_v, rb_intern("*"), 1, &_rb_mem_unit)
|
19
|
+
VALUE _rb_v = ULL2NUM((unsigned long long) info.freeram);
|
20
|
+
VALUE _rb_mem_unit = ULL2NUM((unsigned long long) info.mem_unit);
|
21
|
+
return rb_funcallv_public(_rb_v, rb_intern("*"), 1, &_rb_mem_unit);
|
32
22
|
}
|
33
23
|
|
34
|
-
static VALUE sharedram(
|
35
|
-
|
36
|
-
|
24
|
+
static VALUE sharedram(VALUE obj) {
|
25
|
+
struct sysinfo info;
|
26
|
+
char status = sysinfo(&info);
|
27
|
+
if (status < 0) return Qnil;
|
37
28
|
|
38
|
-
VALUE _rb_v = ULL2NUM((unsigned long long) info.sharedram)
|
39
|
-
VALUE _rb_mem_unit = ULL2NUM((unsigned long long) info.mem_unit)
|
40
|
-
return rb_funcallv_public(_rb_v, rb_intern("*"), 1, &_rb_mem_unit)
|
29
|
+
VALUE _rb_v = ULL2NUM((unsigned long long) info.sharedram);
|
30
|
+
VALUE _rb_mem_unit = ULL2NUM((unsigned long long) info.mem_unit);
|
31
|
+
return rb_funcallv_public(_rb_v, rb_intern("*"), 1, &_rb_mem_unit);
|
41
32
|
}
|
42
33
|
|
43
|
-
static VALUE bufferram(
|
44
|
-
|
45
|
-
|
34
|
+
static VALUE bufferram(VALUE obj) {
|
35
|
+
struct sysinfo info;
|
36
|
+
char status = sysinfo(&info);
|
37
|
+
if (status < 0) return Qnil;
|
46
38
|
|
47
|
-
VALUE _rb_v = ULL2NUM((unsigned long long) info.bufferram)
|
48
|
-
VALUE _rb_mem_unit = ULL2NUM((unsigned long long) info.mem_unit)
|
49
|
-
return rb_funcallv_public(_rb_v, rb_intern("*"), 1, &_rb_mem_unit)
|
39
|
+
VALUE _rb_v = ULL2NUM((unsigned long long) info.bufferram);
|
40
|
+
VALUE _rb_mem_unit = ULL2NUM((unsigned long long) info.mem_unit);
|
41
|
+
return rb_funcallv_public(_rb_v, rb_intern("*"), 1, &_rb_mem_unit);
|
50
42
|
}
|
51
43
|
|
52
|
-
static VALUE totalswap(
|
53
|
-
|
54
|
-
char status = sysinfo(&info)
|
55
|
-
if (status < 0) return Qnil
|
44
|
+
static VALUE totalswap(VALUE obj) {
|
45
|
+
struct sysinfo info;
|
46
|
+
char status = sysinfo(&info);
|
47
|
+
if (status < 0) return Qnil;
|
56
48
|
|
57
|
-
VALUE _rb_v = ULL2NUM((unsigned long long) info.totalswap)
|
58
|
-
VALUE _rb_mem_unit = ULL2NUM((unsigned long long) info.mem_unit)
|
59
|
-
return rb_funcallv_public(_rb_v, rb_intern("*"), 1, &_rb_mem_unit)
|
49
|
+
VALUE _rb_v = ULL2NUM((unsigned long long) info.totalswap);
|
50
|
+
VALUE _rb_mem_unit = ULL2NUM((unsigned long long) info.mem_unit);
|
51
|
+
return rb_funcallv_public(_rb_v, rb_intern("*"), 1, &_rb_mem_unit);
|
60
52
|
}
|
61
53
|
|
62
|
-
static VALUE freeswap(
|
63
|
-
|
64
|
-
|
54
|
+
static VALUE freeswap(VALUE obj) {
|
55
|
+
struct sysinfo info;
|
56
|
+
char status = sysinfo(&info);
|
57
|
+
if (status < 0) return Qnil;
|
65
58
|
|
66
|
-
VALUE _rb_v = ULL2NUM((unsigned long long) info.freeswap)
|
67
|
-
VALUE _rb_mem_unit = ULL2NUM((unsigned long long) info.mem_unit)
|
68
|
-
return rb_funcallv_public(_rb_v, rb_intern("*"), 1, &_rb_mem_unit)
|
59
|
+
VALUE _rb_v = ULL2NUM((unsigned long long) info.freeswap);
|
60
|
+
VALUE _rb_mem_unit = ULL2NUM((unsigned long long) info.mem_unit);
|
61
|
+
return rb_funcallv_public(_rb_v, rb_intern("*"), 1, &_rb_mem_unit);
|
69
62
|
}
|
70
63
|
|
71
|
-
static VALUE totalhigh(
|
72
|
-
|
73
|
-
|
64
|
+
static VALUE totalhigh(VALUE obj) {
|
65
|
+
struct sysinfo info;
|
66
|
+
char status = sysinfo(&info);
|
67
|
+
if (status < 0) return Qnil;
|
74
68
|
|
75
|
-
VALUE _rb_v = ULL2NUM((unsigned long long) info.totalhigh)
|
76
|
-
VALUE _rb_mem_unit = ULL2NUM((unsigned long long) info.mem_unit)
|
77
|
-
return rb_funcallv_public(_rb_v, rb_intern("*"), 1, &_rb_mem_unit)
|
69
|
+
VALUE _rb_v = ULL2NUM((unsigned long long) info.totalhigh);
|
70
|
+
VALUE _rb_mem_unit = ULL2NUM((unsigned long long) info.mem_unit);
|
71
|
+
return rb_funcallv_public(_rb_v, rb_intern("*"), 1, &_rb_mem_unit);
|
78
72
|
}
|
79
73
|
|
80
|
-
static VALUE freehigh(
|
81
|
-
|
82
|
-
|
74
|
+
static VALUE freehigh(VALUE obj) {
|
75
|
+
struct sysinfo info;
|
76
|
+
char status = sysinfo(&info);
|
77
|
+
if (status < 0) return Qnil;
|
83
78
|
|
84
|
-
VALUE _rb_v = ULL2NUM((unsigned long long) info.freehigh)
|
85
|
-
VALUE _rb_mem_unit = ULL2NUM((unsigned long long) info.mem_unit)
|
86
|
-
return rb_funcallv_public(_rb_v, rb_intern("*"), 1, &_rb_mem_unit)
|
79
|
+
VALUE _rb_v = ULL2NUM((unsigned long long) info.freehigh);
|
80
|
+
VALUE _rb_mem_unit = ULL2NUM((unsigned long long) info.mem_unit);
|
81
|
+
return rb_funcallv_public(_rb_v, rb_intern("*"), 1, &_rb_mem_unit);
|
87
82
|
}
|
88
83
|
|
89
|
-
static VALUE uptime(
|
90
|
-
|
91
|
-
|
84
|
+
static VALUE uptime(VALUE obj) {
|
85
|
+
struct sysinfo info;
|
86
|
+
char status = sysinfo(&info);
|
87
|
+
if (status < 0) return Qnil;
|
92
88
|
|
93
|
-
unsigned long long v = info.uptime
|
94
|
-
return ULL2NUM((unsigned long long) v)
|
89
|
+
unsigned long long v = info.uptime;
|
90
|
+
return ULL2NUM((unsigned long long) v);
|
95
91
|
}
|
96
92
|
|
97
|
-
static VALUE loads(
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
rb_float_new(l_5),
|
110
|
-
rb_float_new(l_15)
|
111
|
-
) ;
|
93
|
+
static VALUE loads(VALUE obj) {
|
94
|
+
struct sysinfo info;
|
95
|
+
char status = sysinfo(&info);
|
96
|
+
if(status < 0) return rb_ary_new();
|
97
|
+
|
98
|
+
double scale = 1.0 / (double) (1 << SI_LOAD_SHIFT);
|
99
|
+
return rb_ary_new_from_args(
|
100
|
+
3,
|
101
|
+
rb_float_new(info.loads[0] * scale),
|
102
|
+
rb_float_new(info.loads[1] * scale),
|
103
|
+
rb_float_new(info.loads[2] * scale)
|
104
|
+
);
|
112
105
|
}
|
113
106
|
|
114
107
|
// Some people may need this function, just keep it to not make unnecessary calls
|
115
|
-
static VALUE sysinfoStat(
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
unsigned long long
|
125
|
-
unsigned long long
|
126
|
-
unsigned long long
|
127
|
-
unsigned long long
|
128
|
-
unsigned long long
|
129
|
-
unsigned long long
|
130
|
-
unsigned long long
|
131
|
-
unsigned long long
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
float l_1 = info.loads[0] * load ;
|
136
|
-
float l_5 = info.loads[1] * load ;
|
137
|
-
float l_15 = info.loads[2] * load ;
|
138
|
-
|
108
|
+
static VALUE sysinfoStat(VALUE obj) {
|
109
|
+
struct sysinfo info;
|
110
|
+
char status = sysinfo(&info);
|
111
|
+
VALUE hash = rb_hash_new();
|
112
|
+
if (status < 0) return hash;
|
113
|
+
|
114
|
+
unsigned long long mem_unit = info.mem_unit;
|
115
|
+
VALUE _rb_mem_unit = ULL2NUM(mem_unit);
|
116
|
+
|
117
|
+
unsigned long long _totalram = info.totalram;
|
118
|
+
unsigned long long _freeram = info.freeram;
|
119
|
+
unsigned long long _sharedram = info.sharedram;
|
120
|
+
unsigned long long _bufferram = info.bufferram;
|
121
|
+
unsigned long long _totalswap = info.totalswap;
|
122
|
+
unsigned long long _freeswap = info.freeswap;
|
123
|
+
unsigned long long _totalhigh = info.totalhigh;
|
124
|
+
unsigned long long _freehigh = info.freehigh;
|
125
|
+
unsigned long long _uptime = info.uptime;
|
126
|
+
|
127
|
+
double scale = 1.0 / (double)(1 << SI_LOAD_SHIFT);
|
139
128
|
VALUE loads = rb_ary_new_from_args(3,
|
140
|
-
rb_float_new(
|
141
|
-
rb_float_new(
|
142
|
-
rb_float_new(
|
143
|
-
)
|
144
|
-
|
145
|
-
VALUE mul = rb_intern("*")
|
146
|
-
|
147
|
-
rb_hash_aset(hash, ID2SYM(rb_intern("totalram")), rb_funcallv_public(ULL2NUM(_totalram), mul, 1, &_rb_mem_unit))
|
148
|
-
rb_hash_aset(hash, ID2SYM(rb_intern("freeram")), rb_funcallv_public(ULL2NUM(_freeram), mul, 1, &_rb_mem_unit))
|
149
|
-
rb_hash_aset(hash, ID2SYM(rb_intern("sharedram")), rb_funcallv_public(ULL2NUM(_sharedram), mul, 1, &_rb_mem_unit))
|
150
|
-
rb_hash_aset(hash, ID2SYM(rb_intern("bufferram")), rb_funcallv_public(ULL2NUM(_bufferram), mul, 1, &_rb_mem_unit))
|
151
|
-
rb_hash_aset(hash, ID2SYM(rb_intern("totalswap")), rb_funcallv_public(ULL2NUM(_totalswap), mul, 1, &_rb_mem_unit))
|
152
|
-
rb_hash_aset(hash, ID2SYM(rb_intern("freeswap")), rb_funcallv_public(ULL2NUM(_freeswap), mul, 1, &_rb_mem_unit))
|
153
|
-
rb_hash_aset(hash, ID2SYM(rb_intern("totalhigh")), rb_funcallv_public(ULL2NUM(_totalhigh), mul, 1, &_rb_mem_unit))
|
154
|
-
rb_hash_aset(hash, ID2SYM(rb_intern("freehigh")), rb_funcallv_public(ULL2NUM(_freehigh), mul, 1, &_rb_mem_unit))
|
155
|
-
rb_hash_aset(hash, ID2SYM(rb_intern("uptime")), rb_funcallv_public(ULL2NUM(_uptime), mul, 1, &_rb_mem_unit))
|
156
|
-
|
157
|
-
rb_hash_aset(hash, ID2SYM(rb_intern("loads")), loads)
|
158
|
-
|
159
|
-
return hash
|
129
|
+
rb_float_new(info.loads[0] * scale),
|
130
|
+
rb_float_new(info.loads[1] * scale),
|
131
|
+
rb_float_new(info.loads[2] * scale)
|
132
|
+
);
|
133
|
+
|
134
|
+
VALUE mul = rb_intern("*");
|
135
|
+
|
136
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("totalram")), rb_funcallv_public(ULL2NUM(_totalram), mul, 1, &_rb_mem_unit));
|
137
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("freeram")), rb_funcallv_public(ULL2NUM(_freeram), mul, 1, &_rb_mem_unit));
|
138
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("sharedram")), rb_funcallv_public(ULL2NUM(_sharedram), mul, 1, &_rb_mem_unit));
|
139
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("bufferram")), rb_funcallv_public(ULL2NUM(_bufferram), mul, 1, &_rb_mem_unit));
|
140
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("totalswap")), rb_funcallv_public(ULL2NUM(_totalswap), mul, 1, &_rb_mem_unit));
|
141
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("freeswap")), rb_funcallv_public(ULL2NUM(_freeswap), mul, 1, &_rb_mem_unit));
|
142
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("totalhigh")), rb_funcallv_public(ULL2NUM(_totalhigh), mul, 1, &_rb_mem_unit));
|
143
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("freehigh")), rb_funcallv_public(ULL2NUM(_freehigh), mul, 1, &_rb_mem_unit));
|
144
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("uptime")), rb_funcallv_public(ULL2NUM(_uptime), mul, 1, &_rb_mem_unit));
|
145
|
+
|
146
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("loads")), loads);
|
147
|
+
|
148
|
+
return hash;
|
160
149
|
}
|
161
150
|
|
162
151
|
void Init_sysinfo() {
|
163
|
-
VALUE _linux_stat = rb_define_module("LinuxStat")
|
164
|
-
VALUE _sysinfo = rb_define_module_under(_linux_stat, "Sysinfo")
|
165
|
-
|
166
|
-
rb_define_module_function(_sysinfo, "totalram", totalram, 0)
|
167
|
-
rb_define_module_function(_sysinfo, "freeram", freeram, 0)
|
168
|
-
rb_define_module_function(_sysinfo, "sharedram", sharedram, 0)
|
169
|
-
rb_define_module_function(_sysinfo, "bufferram", bufferram, 0)
|
170
|
-
rb_define_module_function(_sysinfo, "totalswap", totalswap, 0)
|
171
|
-
rb_define_module_function(_sysinfo, "freeswap", freeswap, 0)
|
172
|
-
rb_define_module_function(_sysinfo, "totalhigh", totalhigh, 0)
|
173
|
-
rb_define_module_function(_sysinfo, "freehigh", freehigh, 0)
|
174
|
-
rb_define_module_function(_sysinfo, "uptime", uptime, 0)
|
175
|
-
rb_define_module_function(_sysinfo, "loads", loads, 0)
|
176
|
-
rb_define_module_function(_sysinfo, "stat", sysinfoStat, 0)
|
152
|
+
VALUE _linux_stat = rb_define_module("LinuxStat");
|
153
|
+
VALUE _sysinfo = rb_define_module_under(_linux_stat, "Sysinfo");
|
154
|
+
|
155
|
+
rb_define_module_function(_sysinfo, "totalram", totalram, 0);
|
156
|
+
rb_define_module_function(_sysinfo, "freeram", freeram, 0);
|
157
|
+
rb_define_module_function(_sysinfo, "sharedram", sharedram, 0);
|
158
|
+
rb_define_module_function(_sysinfo, "bufferram", bufferram, 0);
|
159
|
+
rb_define_module_function(_sysinfo, "totalswap", totalswap, 0);
|
160
|
+
rb_define_module_function(_sysinfo, "freeswap", freeswap, 0);
|
161
|
+
rb_define_module_function(_sysinfo, "totalhigh", totalhigh, 0);
|
162
|
+
rb_define_module_function(_sysinfo, "freehigh", freehigh, 0);
|
163
|
+
rb_define_module_function(_sysinfo, "uptime", uptime, 0);
|
164
|
+
rb_define_module_function(_sysinfo, "loads", loads, 0);
|
165
|
+
rb_define_module_function(_sysinfo, "stat", sysinfoStat, 0);
|
177
166
|
}
|