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
43 44 45 46 47 48 49 50 |
# File 'ext/sysinfo/sysinfo.c', line 43
static VALUE bufferram(volatile VALUE obj) {
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
80 81 82 83 84 85 86 87 |
# File 'ext/sysinfo/sysinfo.c', line 80
static VALUE freehigh(volatile VALUE obj) {
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
25 26 27 28 29 30 31 32 |
# File 'ext/sysinfo/sysinfo.c', line 25
static VALUE freeram(volatile VALUE obj) {
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
62 63 64 65 66 67 68 69 |
# File 'ext/sysinfo/sysinfo.c', line 62
static VALUE freeswap(volatile VALUE obj) {
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
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'ext/sysinfo/sysinfo.c', line 97
static VALUE loads(volatile VALUE obj) {
char status = sysinfo(&info) ;
if(status < 0) return rb_ary_new() ;
long double load = 1.f / (1 << SI_LOAD_SHIFT) ;
float l_1 = info.loads[0] * load ;
float l_5 = info.loads[1] * load ;
float l_15 = info.loads[2] * load ;
return rb_ary_new_from_args(3,
rb_float_new(l_1),
rb_float_new(l_5),
rb_float_new(l_15)
) ;
}
|
.sharedram ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'ext/sysinfo/sysinfo.c', line 34
static VALUE sharedram(volatile VALUE obj) {
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
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 150 151 152 153 154 155 156 157 158 159 160 |
# File 'ext/sysinfo/sysinfo.c', line 115
static VALUE sysinfoStat(volatile VALUE obj) {
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 ;
long double load = 1.f / (1 << SI_LOAD_SHIFT) ;
float l_1 = info.loads[0] * load ;
float l_5 = info.loads[1] * load ;
float l_15 = info.loads[2] * load ;
VALUE loads = rb_ary_new_from_args(3,
rb_float_new(l_1),
rb_float_new(l_5),
rb_float_new(l_15)
) ;
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
71 72 73 74 75 76 77 78 |
# File 'ext/sysinfo/sysinfo.c', line 71
static VALUE totalhigh(volatile VALUE obj) {
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
16 17 18 19 20 21 22 23 |
# File 'ext/sysinfo/sysinfo.c', line 16
static VALUE totalram(volatile VALUE obj) {
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
52 53 54 55 56 57 58 59 60 |
# File 'ext/sysinfo/sysinfo.c', line 52
static VALUE totalswap(volatile VALUE obj) {
static 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
89 90 91 92 93 94 95 |
# File 'ext/sysinfo/sysinfo.c', line 89
static VALUE uptime(volatile VALUE obj) {
char status = sysinfo(&info) ;
if (status < 0) return Qnil ;
unsigned long long v = info.uptime ;
return ULL2NUM((unsigned long long) v) ;
}
|