Method: LinuxStat::Sysinfo.stat

Defined in:
ext/sysinfo/sysinfo.c

.statObject

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

VALUE sysinfoStat(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 ;
}