Module: LinuxStat::Sysinfo
- Defined in:
- ext/sysinfo/sysinfo.c
Class Method Summary collapse
- .bufferram ⇒ Object
- .freehigh ⇒ Object
- .freeram ⇒ Object
- .freeswap ⇒ Object
- .loads ⇒ Object
- .sharedram ⇒ Object
-
.stat ⇒ Object
Some people may need this function, just keep it to not make unnecessary calls.
- .totalhigh ⇒ Object
- .totalram ⇒ Object
- .totalswap ⇒ Object
- .uptime ⇒ Object
Class Method Details
.bufferram ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'ext/sysinfo/sysinfo.c', line 34
static VALUE bufferram(VALUE obj) {
struct sysinfo info;
char status = sysinfo(&info);
if (status < 0) return Qnil;
VALUE _rb_v = ULL2NUM((unsigned long long) info.bufferram);
VALUE _rb_mem_unit = ULL2NUM((unsigned long long) info.mem_unit);
return rb_funcallv_public(_rb_v, rb_intern("*"), 1, &_rb_mem_unit);
}
|
.freehigh ⇒ Object
74 75 76 77 78 79 80 81 82 |
# File 'ext/sysinfo/sysinfo.c', line 74
static VALUE freehigh(VALUE obj) {
struct sysinfo info;
char status = sysinfo(&info);
if (status < 0) return Qnil;
VALUE _rb_v = ULL2NUM((unsigned long long) info.freehigh);
VALUE _rb_mem_unit = ULL2NUM((unsigned long long) info.mem_unit);
return rb_funcallv_public(_rb_v, rb_intern("*"), 1, &_rb_mem_unit);
}
|
.freeram ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'ext/sysinfo/sysinfo.c', line 14
static VALUE freeram(VALUE obj) {
struct sysinfo info;
char status = sysinfo(&info);
if (status < 0) return Qnil;
VALUE _rb_v = ULL2NUM((unsigned long long) info.freeram);
VALUE _rb_mem_unit = ULL2NUM((unsigned long long) info.mem_unit);
return rb_funcallv_public(_rb_v, rb_intern("*"), 1, &_rb_mem_unit);
}
|
.freeswap ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'ext/sysinfo/sysinfo.c', line 54
static VALUE freeswap(VALUE obj) {
struct sysinfo info;
char status = sysinfo(&info);
if (status < 0) return Qnil;
VALUE _rb_v = ULL2NUM((unsigned long long) info.freeswap);
VALUE _rb_mem_unit = ULL2NUM((unsigned long long) info.mem_unit);
return rb_funcallv_public(_rb_v, rb_intern("*"), 1, &_rb_mem_unit);
}
|
.loads ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'ext/sysinfo/sysinfo.c', line 93
static VALUE loads(VALUE obj) {
struct sysinfo info;
char status = sysinfo(&info);
if(status < 0) return rb_ary_new();
double scale = 1.0 / (double) (1 << SI_LOAD_SHIFT);
return rb_ary_new_from_args(
3,
rb_float_new(info.loads[0] * scale),
rb_float_new(info.loads[1] * scale),
rb_float_new(info.loads[2] * scale)
);
}
|
.sharedram ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'ext/sysinfo/sysinfo.c', line 24
static VALUE sharedram(VALUE obj) {
struct sysinfo info;
char status = sysinfo(&info);
if (status < 0) return Qnil;
VALUE _rb_v = ULL2NUM((unsigned long long) info.sharedram);
VALUE _rb_mem_unit = ULL2NUM((unsigned long long) info.mem_unit);
return rb_funcallv_public(_rb_v, rb_intern("*"), 1, &_rb_mem_unit);
}
|
.stat ⇒ Object
Some people may need this function, just keep it to not make unnecessary calls
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'ext/sysinfo/sysinfo.c', line 108
static VALUE sysinfoStat(VALUE obj) {
struct sysinfo info;
char status = sysinfo(&info);
VALUE hash = rb_hash_new();
if (status < 0) return hash;
unsigned long long mem_unit = info.mem_unit;
VALUE _rb_mem_unit = ULL2NUM(mem_unit);
unsigned long long _totalram = info.totalram;
unsigned long long _freeram = info.freeram;
unsigned long long _sharedram = info.sharedram;
unsigned long long _bufferram = info.bufferram;
unsigned long long _totalswap = info.totalswap;
unsigned long long _freeswap = info.freeswap;
unsigned long long _totalhigh = info.totalhigh;
unsigned long long _freehigh = info.freehigh;
unsigned long long _uptime = info.uptime;
double scale = 1.0 / (double)(1 << SI_LOAD_SHIFT);
VALUE loads = rb_ary_new_from_args(3,
rb_float_new(info.loads[0] * scale),
rb_float_new(info.loads[1] * scale),
rb_float_new(info.loads[2] * scale)
);
VALUE mul = rb_intern("*");
rb_hash_aset(hash, ID2SYM(rb_intern("totalram")), rb_funcallv_public(ULL2NUM(_totalram), mul, 1, &_rb_mem_unit));
rb_hash_aset(hash, ID2SYM(rb_intern("freeram")), rb_funcallv_public(ULL2NUM(_freeram), mul, 1, &_rb_mem_unit));
rb_hash_aset(hash, ID2SYM(rb_intern("sharedram")), rb_funcallv_public(ULL2NUM(_sharedram), mul, 1, &_rb_mem_unit));
rb_hash_aset(hash, ID2SYM(rb_intern("bufferram")), rb_funcallv_public(ULL2NUM(_bufferram), mul, 1, &_rb_mem_unit));
rb_hash_aset(hash, ID2SYM(rb_intern("totalswap")), rb_funcallv_public(ULL2NUM(_totalswap), mul, 1, &_rb_mem_unit));
rb_hash_aset(hash, ID2SYM(rb_intern("freeswap")), rb_funcallv_public(ULL2NUM(_freeswap), mul, 1, &_rb_mem_unit));
rb_hash_aset(hash, ID2SYM(rb_intern("totalhigh")), rb_funcallv_public(ULL2NUM(_totalhigh), mul, 1, &_rb_mem_unit));
rb_hash_aset(hash, ID2SYM(rb_intern("freehigh")), rb_funcallv_public(ULL2NUM(_freehigh), mul, 1, &_rb_mem_unit));
rb_hash_aset(hash, ID2SYM(rb_intern("uptime")), rb_funcallv_public(ULL2NUM(_uptime), mul, 1, &_rb_mem_unit));
rb_hash_aset(hash, ID2SYM(rb_intern("loads")), loads);
return hash;
}
|
.totalhigh ⇒ Object
64 65 66 67 68 69 70 71 72 |
# File 'ext/sysinfo/sysinfo.c', line 64
static VALUE totalhigh(VALUE obj) {
struct sysinfo info;
char status = sysinfo(&info);
if (status < 0) return Qnil;
VALUE _rb_v = ULL2NUM((unsigned long long) info.totalhigh);
VALUE _rb_mem_unit = ULL2NUM((unsigned long long) info.mem_unit);
return rb_funcallv_public(_rb_v, rb_intern("*"), 1, &_rb_mem_unit);
}
|
.totalram ⇒ Object
4 5 6 7 8 9 10 11 12 |
# File 'ext/sysinfo/sysinfo.c', line 4
static VALUE totalram(VALUE obj) {
struct sysinfo info;
char status = sysinfo(&info);
if (status < 0) return Qnil;
VALUE _rb_v = ULL2NUM((unsigned long long) info.totalram);
VALUE _rb_mem_unit = ULL2NUM((unsigned long long) info.mem_unit);
return rb_funcallv_public(_rb_v, rb_intern("*"), 1, &_rb_mem_unit);
}
|
.totalswap ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'ext/sysinfo/sysinfo.c', line 44
static VALUE totalswap(VALUE obj) {
struct sysinfo info;
char status = sysinfo(&info);
if (status < 0) return Qnil;
VALUE _rb_v = ULL2NUM((unsigned long long) info.totalswap);
VALUE _rb_mem_unit = ULL2NUM((unsigned long long) info.mem_unit);
return rb_funcallv_public(_rb_v, rb_intern("*"), 1, &_rb_mem_unit);
}
|
.uptime ⇒ Object
84 85 86 87 88 89 90 91 |
# File 'ext/sysinfo/sysinfo.c', line 84
static VALUE uptime(VALUE obj) {
struct sysinfo info;
char status = sysinfo(&info);
if (status < 0) return Qnil;
unsigned long long v = info.uptime;
return ULL2NUM((unsigned long long) v);
}
|