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.
data/ext/procfs/procfs.c CHANGED
@@ -21,29 +21,29 @@
21
21
  #include "loadavg_pid.h"
22
22
 
23
23
  int Init_procfs() {
24
- VALUE _linux_stat = rb_define_module("LinuxStat") ;
25
- VALUE _procfs = rb_define_module_under(_linux_stat, "ProcFS") ;
26
- VALUE _cpu = rb_define_module_under(_linux_stat, "CPU") ;
27
- VALUE _process = rb_define_module_under(_linux_stat, "Process") ;
24
+ VALUE _linux_stat = rb_define_module("LinuxStat");
25
+ VALUE _procfs = rb_define_module_under(_linux_stat, "ProcFS");
26
+ VALUE _cpu = rb_define_module_under(_linux_stat, "CPU");
27
+ VALUE _process = rb_define_module_under(_linux_stat, "Process");
28
28
 
29
29
  // uptime
30
- rb_define_module_function(_procfs, "uptime_f", uptime_f, 0) ;
30
+ rb_define_module_function(_procfs, "uptime_f", uptime_f, 0);
31
31
 
32
32
  // statm
33
- rb_define_module_function(_procfs, "statm_memory", statm_memory, 1) ;
34
- rb_define_module_function(_procfs, "statm", statm, 1) ;
35
- rb_define_module_function(_procfs, "statm_virtual", statm_virtual, 1) ;
36
- rb_define_module_function(_procfs, "statm_resident", statm_resident, 1) ;
37
- rb_define_module_function(_procfs, "statm_shared", statm_shared, 1) ;
33
+ rb_define_module_function(_procfs, "statm_memory", statm_memory, 1);
34
+ rb_define_module_function(_procfs, "statm", statm, 1);
35
+ rb_define_module_function(_procfs, "statm_virtual", statm_virtual, 1);
36
+ rb_define_module_function(_procfs, "statm_resident", statm_resident, 1);
37
+ rb_define_module_function(_procfs, "statm_shared", statm_shared, 1);
38
38
 
39
39
  // loadavg last PID
40
- rb_define_module_function(_procfs, "last_pid", last_pid, 0) ;
40
+ rb_define_module_function(_procfs, "last_pid", last_pid, 0);
41
41
 
42
42
  // stat
43
- rb_define_module_function(_procfs, "ps_state", ps_state, 1) ;
44
- rb_define_module_function(_procfs, "ps_times", ps_times, 1) ;
45
- rb_define_module_function(_procfs, "ps_stat", ps_stat, 1) ;
46
- rb_define_module_function(_procfs, "cpu_times", cpuTimes, 0) ;
47
- rb_define_module_function(_procfs, "list_process", listProcess, 0) ;
43
+ rb_define_module_function(_procfs, "ps_state", ps_state, 1);
44
+ rb_define_module_function(_procfs, "ps_times", ps_times, 1);
45
+ rb_define_module_function(_procfs, "ps_stat", ps_stat, 1);
46
+ rb_define_module_function(_procfs, "cpu_times", cpuTimes, 0);
47
+ rb_define_module_function(_procfs, "list_process", listProcess, 0);
48
48
 
49
49
  }
data/ext/procfs/stat.h CHANGED
@@ -1,77 +1,77 @@
1
- static VALUE ps_state(volatile VALUE obj, volatile VALUE pid) {
2
- int _pid = FIX2INT(pid) ;
3
- if (_pid < 0) return rb_str_new_cstr("") ;
1
+ static VALUE ps_state(VALUE obj, VALUE pid) {
2
+ int _pid = FIX2INT(pid);
3
+ if (_pid < 0) return rb_str_new_cstr("");
4
4
 
5
- char _path[22] ;
6
- sprintf(_path, "/proc/%d/stat", _pid) ;
5
+ char _path[22];
7
6
 
8
- FILE *f = fopen(_path, "r") ;
9
- if (!f) return rb_str_new_cstr("") ;
10
7
 
11
- char _s[1] ;
8
+ FILE *f = fopen(_path, "r");
9
+ if (!f) return rb_str_new_cstr("");
12
10
 
13
- char status = fscanf(f, "%*llu (%*[^)]%*[)] %s", _s) ;
14
- fclose(f) ;
11
+ char _s[1];
15
12
 
16
- if (status != 1) return rb_str_new_cstr("") ;
17
- return rb_str_new_cstr(_s) ;
13
+ char status = fscanf(f, "%*llu (%*[^)]%*[)] %s", _s);
14
+ fclose(f);
15
+
16
+ if (status != 1) return rb_str_new_cstr("");
17
+ return rb_str_new_cstr(_s);
18
18
  }
19
19
 
20
- static VALUE listProcess(volatile VALUE obj) {
21
- VALUE ary = rb_ary_new() ;
20
+ static VALUE listProcess(VALUE obj) {
21
+ VALUE ary = rb_ary_new();
22
22
 
23
- glob_t globlist ;
24
- int status = glob("/proc/[0-9]*/", GLOB_NOSORT, NULL, &globlist) ;
23
+ glob_t globlist;
24
+ int status = glob("/proc/[0-9]*/", GLOB_NOSORT, NULL, &globlist);
25
25
 
26
26
  if (status == GLOB_NOSPACE || status == GLOB_ABORTED || status == GLOB_NOMATCH) {
27
- globfree(&globlist) ;
28
- return ary ;
27
+ globfree(&globlist);
28
+ return ary;
29
29
  }
30
30
 
31
- char *v, *token ;
32
- unsigned int i = 0 ;
33
- unsigned int num ;
31
+ char *v, *token;
32
+ unsigned int i = 0;
33
+ unsigned int num;
34
34
 
35
35
  while(v = globlist.gl_pathv[i++]) {
36
- if (sscanf(v, "/proc/%u", &num) == 1) rb_ary_push(ary, UINT2NUM(num)) ;
36
+ if (sscanf(v, "/proc/%u", &num) == 1) rb_ary_push(ary, UINT2NUM(num));
37
37
  }
38
38
 
39
- globfree(&globlist) ;
40
- return ary ;
39
+ globfree(&globlist);
40
+ return ary;
41
41
  }
42
42
 
43
- static VALUE ps_times(volatile VALUE obj, volatile VALUE pid) {
44
- int _pid = FIX2INT(pid) ;
45
- if (_pid < 0) return Qnil ;
43
+ static VALUE ps_times(VALUE obj, VALUE pid) {
44
+ pid_t _pid = (pid_t)NUM2LONG(pid);
45
+ if (_pid < 0) return Qnil;
46
46
 
47
- char _path[22] ;
48
- sprintf(_path, "/proc/%d/stat", _pid) ;
47
+ char _path[22];
48
+ snprintf(_path, sizeof(_path), "/proc/%d/stat", _pid);
49
49
 
50
- FILE *f = fopen(_path, "r") ;
51
- if (!f) return Qnil ;
50
+ FILE *f = fopen(_path, "r");
51
+ if (!f) return Qnil;
52
52
 
53
- unsigned long utime, stime ;
53
+ unsigned long utime, stime;
54
54
 
55
- char status = fscanf(f, "%*llu (%*[^)]%*[)] %*c %*d %*d %*d %*d %*d %*u %*lu %*lu %*lu %*lu %lu %lu", &utime, &stime) ;
56
- fclose(f) ;
55
+ char status = fscanf(f, "%*llu (%*[^)]%*[)] %*c %*d %*d %*d %*d %*d %*u %*lu %*lu %*lu %*lu %lu %lu", &utime, &stime);
56
+ fclose(f);
57
57
 
58
- if (status != 2) return Qnil ;
58
+ if (status != 2) return Qnil;
59
59
  double total_time = (utime + stime) / (float)sysconf(_SC_CLK_TCK);
60
60
 
61
- return DBL2NUM(total_time) ;
61
+ return DBL2NUM(total_time);
62
62
  }
63
63
 
64
- static VALUE ps_stat(volatile VALUE obj, volatile VALUE pid) {
65
- int _pid = FIX2INT(pid) ;
66
- if (_pid < 0) return rb_str_new_cstr("") ;
64
+ static VALUE ps_stat(VALUE obj, VALUE pid) {
65
+ pid_t _pid = (pid_t)NUM2LONG(pid);
66
+ if (_pid < 0) return rb_str_new_cstr("");
67
67
 
68
- char _path[22] ;
69
- sprintf(_path, "/proc/%d/stat", _pid) ;
68
+ char _path[22];
69
+ snprintf(_path, sizeof(_path), "/proc/%d/stat", _pid);
70
70
 
71
- FILE *f = fopen(_path, "r") ;
71
+ FILE *f = fopen(_path, "r");
72
72
 
73
73
  if (!f)
74
- return rb_ary_new() ;
74
+ return rb_ary_new();
75
75
 
76
76
  // ?? JEEZ !!
77
77
  // We need to do this because the datatypes are different
@@ -80,23 +80,23 @@ static VALUE ps_stat(volatile VALUE obj, volatile VALUE pid) {
80
80
  //
81
81
  // For this struct,
82
82
  // follow https://man7.org/linux/man-pages/man5/proc.5.html
83
- int ppid, pgrp, session, tty_nr, tpgid ;
84
- unsigned flags ;
85
- long unsigned minflt, cminflt, majflt, cmajflt, utime, stime ;
86
- long cutime, cstime, priority, nice, num_threads, itrealvalue ;
87
- long long unsigned starttime ;
88
- long unsigned vsize ;
89
- long rss ;
90
- long unsigned rsslim, startcode, endcode, startstack, kstkesp, kstkeip ;
91
- long unsigned signal, blocked, sigignore, sigcatch, wchan, nswap, cnswap ;
92
- int exit_signal, processor ;
93
- unsigned rt_priority, policy ;
94
- long long unsigned delayacct_blkio_ticks ;
95
- long unsigned guest_time ;
96
- long cguest_time ;
97
- long unsigned start_data, end_data, start_brk, arg_start, arg_end ;
98
- long unsigned env_start, env_end ;
99
- int exit_code ;
83
+ int ppid, pgrp, session, tty_nr, tpgid;
84
+ unsigned flags;
85
+ long unsigned minflt, cminflt, majflt, cmajflt, utime, stime;
86
+ long cutime, cstime, priority, nice, num_threads, itrealvalue;
87
+ long long unsigned starttime;
88
+ long unsigned vsize;
89
+ long rss;
90
+ long unsigned rsslim, startcode, endcode, startstack, kstkesp, kstkeip;
91
+ long unsigned signal, blocked, sigignore, sigcatch, wchan, nswap, cnswap;
92
+ int exit_signal, processor;
93
+ unsigned rt_priority, policy;
94
+ long long unsigned delayacct_blkio_ticks;
95
+ long unsigned guest_time;
96
+ long cguest_time;
97
+ long unsigned start_data, end_data, start_brk, arg_start, arg_end;
98
+ long unsigned env_start, env_end;
99
+ int exit_code;
100
100
 
101
101
  char status = fscanf(
102
102
  f, "%*llu (%*[^)]%*[)] %*c "
@@ -111,12 +111,12 @@ static VALUE ps_stat(volatile VALUE obj, volatile VALUE pid) {
111
111
  &sigcatch, &wchan, &nswap, &cnswap, &exit_signal, &processor, &rt_priority, &policy,
112
112
  &delayacct_blkio_ticks, &guest_time, &cguest_time, &start_data, &end_data,
113
113
  &start_brk, &arg_start, &arg_end, &env_start, &env_end, &exit_code
114
- ) ;
114
+ );
115
115
 
116
- fclose(f) ;
116
+ fclose(f);
117
117
 
118
118
  if (status != 49)
119
- return rb_ary_new() ;
119
+ return rb_ary_new();
120
120
 
121
121
  return rb_ary_new_from_args(49,
122
122
  INT2NUM(ppid), INT2NUM(pgrp), INT2NUM(session), INT2NUM(tty_nr), INT2NUM(tpgid),
@@ -138,48 +138,48 @@ static VALUE ps_stat(volatile VALUE obj, volatile VALUE pid) {
138
138
  ULONG2NUM(end_data), ULONG2NUM(start_brk), ULONG2NUM(arg_start), ULONG2NUM(arg_end),
139
139
  ULONG2NUM(env_start), ULONG2NUM(env_end),
140
140
  INT2NUM(exit_code)
141
- ) ;
141
+ );
142
142
  }
143
143
 
144
- static VALUE cpuTimes(volatile VALUE obj) {
145
- VALUE ary = rb_ary_new() ;
146
- FILE *f = fopen("/proc/stat", "r") ;
144
+ static VALUE cpuTimes(VALUE obj) {
145
+ VALUE ary = rb_ary_new();
146
+ FILE *f = fopen("/proc/stat", "r");
147
147
 
148
- if (!f) return ary ;
148
+ if (!f) return ary;
149
149
 
150
- unsigned long user, nice, system, idle, iowait, irq, softirq, steal, guest, guest_nice ;
151
- char line[1024] ;
152
- char cpuCode[7] ;
153
- float ticks = sysconf(_SC_CLK_TCK) ;
154
- char scanStatus ;
150
+ unsigned long user, nice, system, idle, iowait, irq, softirq, steal, guest, guest_nice;
151
+ char line[1024];
152
+ char cpuCode[7];
153
+ float ticks = sysconf(_SC_CLK_TCK);
154
+ char scanStatus;
155
155
 
156
156
  while(fgets(line, 1023, f)) {
157
- if (!(line[0] == 'c' && line[1] == 'p' && line[2] == 'u')) break ;
157
+ if (!(line[0] == 'c' && line[1] == 'p' && line[2] == 'u')) break;
158
158
 
159
159
  scanStatus = sscanf(line,
160
160
  "%7[cpu0-9] %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu",
161
161
  cpuCode, &user, &nice, &system, &idle, &iowait, &irq, &softirq, &steal, &guest, &guest_nice
162
- ) ;
163
-
164
- if (scanStatus != 11) break ;
165
-
166
- VALUE innerHash = rb_hash_new() ;
167
- rb_hash_aset(innerHash, ID2SYM(rb_intern("cpu")), rb_str_new_cstr(cpuCode)) ;
168
- rb_hash_aset(innerHash, ID2SYM(rb_intern("user")), rb_float_new(user / ticks)) ;
169
- rb_hash_aset(innerHash, ID2SYM(rb_intern("nice")), rb_float_new(nice / ticks)) ;
170
- rb_hash_aset(innerHash, ID2SYM(rb_intern("system")), rb_float_new(system / ticks)) ;
171
- rb_hash_aset(innerHash, ID2SYM(rb_intern("idle")), rb_float_new(idle / ticks)) ;
172
- rb_hash_aset(innerHash, ID2SYM(rb_intern("iowait")), rb_float_new(iowait / ticks)) ;
173
- rb_hash_aset(innerHash, ID2SYM(rb_intern("irq")), rb_float_new(irq / ticks)) ;
174
- rb_hash_aset(innerHash, ID2SYM(rb_intern("softirq")), rb_float_new(softirq / ticks)) ;
175
- rb_hash_aset(innerHash, ID2SYM(rb_intern("steal")), rb_float_new(steal / ticks)) ;
176
- rb_hash_aset(innerHash, ID2SYM(rb_intern("guest")), rb_float_new(guest / ticks)) ;
177
- rb_hash_aset(innerHash, ID2SYM(rb_intern("guest_nice")), rb_float_new(guest_nice / ticks)) ;
178
-
179
- rb_ary_push(ary, innerHash) ;
162
+ );
163
+
164
+ if (scanStatus != 11) break;
165
+
166
+ VALUE innerHash = rb_hash_new();
167
+ rb_hash_aset(innerHash, ID2SYM(rb_intern("cpu")), rb_str_new_cstr(cpuCode));
168
+ rb_hash_aset(innerHash, ID2SYM(rb_intern("user")), rb_float_new(user / ticks));
169
+ rb_hash_aset(innerHash, ID2SYM(rb_intern("nice")), rb_float_new(nice / ticks));
170
+ rb_hash_aset(innerHash, ID2SYM(rb_intern("system")), rb_float_new(system / ticks));
171
+ rb_hash_aset(innerHash, ID2SYM(rb_intern("idle")), rb_float_new(idle / ticks));
172
+ rb_hash_aset(innerHash, ID2SYM(rb_intern("iowait")), rb_float_new(iowait / ticks));
173
+ rb_hash_aset(innerHash, ID2SYM(rb_intern("irq")), rb_float_new(irq / ticks));
174
+ rb_hash_aset(innerHash, ID2SYM(rb_intern("softirq")), rb_float_new(softirq / ticks));
175
+ rb_hash_aset(innerHash, ID2SYM(rb_intern("steal")), rb_float_new(steal / ticks));
176
+ rb_hash_aset(innerHash, ID2SYM(rb_intern("guest")), rb_float_new(guest / ticks));
177
+ rb_hash_aset(innerHash, ID2SYM(rb_intern("guest_nice")), rb_float_new(guest_nice / ticks));
178
+
179
+ rb_ary_push(ary, innerHash);
180
180
  }
181
181
 
182
- fclose(f) ;
182
+ fclose(f);
183
183
 
184
- return ary ;
184
+ return ary;
185
185
  }
data/ext/procfs/statm.h CHANGED
@@ -1,109 +1,109 @@
1
1
  #define PAGESIZE sysconf(_SC_PAGESIZE)
2
2
 
3
- static VALUE statm(volatile VALUE obj, volatile VALUE pid) {
4
- VALUE hash = rb_hash_new() ;
3
+ static VALUE statm(VALUE obj, VALUE pid) {
4
+ VALUE hash = rb_hash_new();
5
5
 
6
- int _pid = FIX2INT(pid) ;
7
- if (_pid < 0) return hash ;
6
+ pid_t _pid = (pid_t)NUM2LONG(pid);
7
+ if (_pid < 0) return hash;
8
8
 
9
- char _path[22] ;
10
- sprintf(_path, "/proc/%d/statm", _pid) ;
9
+ char _path[22];
10
+ snprintf(_path, sizeof(_path), "/proc/%d/statm", _pid);
11
11
 
12
- FILE *f = fopen(_path, "r") ;
13
- if (!f) return hash ;
12
+ FILE *f = fopen(_path, "r");
13
+ if (!f) return hash;
14
14
 
15
- unsigned int _virtual, resident, shared ;
16
- char status = fscanf(f, "%u %u %u", &_virtual, &resident, &shared) ;
17
- fclose(f) ;
15
+ unsigned int _virtual, resident, shared;
16
+ char status = fscanf(f, "%u %u %u", &_virtual, &resident, &shared);
17
+ fclose(f);
18
18
 
19
- if (status != 3) return hash ;
19
+ if (status != 3) return hash;
20
20
 
21
- int pagesize = PAGESIZE ;
21
+ int pagesize = PAGESIZE;
22
22
 
23
- _virtual *= pagesize ;
24
- resident *= pagesize ;
25
- shared *= pagesize ;
23
+ _virtual *= pagesize;
24
+ resident *= pagesize;
25
+ shared *= pagesize;
26
26
 
27
- unsigned int v = resident - shared ;
27
+ unsigned int v = resident - shared;
28
28
 
29
- rb_hash_aset(hash, ID2SYM(rb_intern("memory")), UINT2NUM(v)) ;
30
- rb_hash_aset(hash, ID2SYM(rb_intern("virtual_memory")), UINT2NUM(_virtual)) ;
31
- rb_hash_aset(hash, ID2SYM(rb_intern("resident_memory")), UINT2NUM(resident)) ;
32
- rb_hash_aset(hash, ID2SYM(rb_intern("shared_memory")), UINT2NUM(shared)) ;
29
+ rb_hash_aset(hash, ID2SYM(rb_intern("memory")), UINT2NUM(v));
30
+ rb_hash_aset(hash, ID2SYM(rb_intern("virtual_memory")), UINT2NUM(_virtual));
31
+ rb_hash_aset(hash, ID2SYM(rb_intern("resident_memory")), UINT2NUM(resident));
32
+ rb_hash_aset(hash, ID2SYM(rb_intern("shared_memory")), UINT2NUM(shared));
33
33
 
34
- return hash ;
34
+ return hash;
35
35
  }
36
36
 
37
- static VALUE statm_virtual(volatile VALUE obj, volatile VALUE pid) {
38
- int _pid = FIX2INT(pid) ;
39
- if (_pid < 0) return Qnil ;
37
+ static VALUE statm_virtual(VALUE obj, VALUE pid) {
38
+ pid_t _pid = (pid_t)NUM2LONG(pid);
39
+ if (_pid < 0) return Qnil;
40
40
 
41
- char _path[22] ;
42
- sprintf(_path, "/proc/%d/statm", _pid) ;
41
+ char _path[22];
42
+ snprintf(_path, sizeof(_path), "/proc/%d/statm", _pid);
43
43
 
44
- FILE *f = fopen(_path, "r") ;
45
- if (!f) return Qnil ;
44
+ FILE *f = fopen(_path, "r");
45
+ if (!f) return Qnil;
46
46
 
47
- unsigned int _virtual ;
48
- char status = fscanf(f, "%u", &_virtual) ;
49
- fclose(f) ;
47
+ unsigned int _virtual;
48
+ char status = fscanf(f, "%u", &_virtual);
49
+ fclose(f);
50
50
 
51
- if (status != 1) return Qnil ;
52
- return UINT2NUM(_virtual * PAGESIZE) ;
51
+ if (status != 1) return Qnil;
52
+ return UINT2NUM(_virtual * PAGESIZE);
53
53
  }
54
54
 
55
- static VALUE statm_resident(volatile VALUE obj, volatile VALUE pid) {
56
- int _pid = FIX2INT(pid) ;
57
- if (_pid < 0) return Qnil ;
55
+ static VALUE statm_resident(VALUE obj, VALUE pid) {
56
+ pid_t _pid = (pid_t)NUM2LONG(pid);
57
+ if (_pid < 0) return Qnil;
58
58
 
59
- char _path[22] ;
60
- sprintf(_path, "/proc/%d/statm", _pid) ;
59
+ char _path[22];
60
+ snprintf(_path, sizeof(_path), "/proc/%d/statm", _pid);
61
61
 
62
- FILE *f = fopen(_path, "r") ;
63
- if (!f) return Qnil ;
62
+ FILE *f = fopen(_path, "r");
63
+ if (!f) return Qnil;
64
64
 
65
- unsigned int resident ;
66
- char status = fscanf(f, "%*u %u", &resident) ;
67
- fclose(f) ;
65
+ unsigned int resident;
66
+ char status = fscanf(f, "%*u %u", &resident);
67
+ fclose(f);
68
68
 
69
- if (status != 1) return Qnil ;
70
- return UINT2NUM(resident * PAGESIZE) ;
69
+ if (status != 1) return Qnil;
70
+ return UINT2NUM(resident * PAGESIZE);
71
71
  }
72
72
 
73
- static VALUE statm_shared(volatile VALUE obj, volatile VALUE pid) {
74
- int _pid = FIX2INT(pid) ;
75
- if (_pid < 0) return Qnil ;
73
+ static VALUE statm_shared(VALUE obj, VALUE pid) {
74
+ pid_t _pid = (pid_t)NUM2LONG(pid);
75
+ if (_pid < 0) return Qnil;
76
76
 
77
- char _path[22] ;
78
- sprintf(_path, "/proc/%d/statm", _pid) ;
77
+ char _path[22];
78
+ snprintf(_path, sizeof(_path), "/proc/%d/statm", _pid);
79
79
 
80
- FILE *f = fopen(_path, "r") ;
81
- if (!f) return Qnil ;
80
+ FILE *f = fopen(_path, "r");
81
+ if (!f) return Qnil;
82
82
 
83
- unsigned int shared ;
84
- char status = fscanf(f, "%*u %*u %u", &shared) ;
85
- fclose(f) ;
83
+ unsigned int shared;
84
+ char status = fscanf(f, "%*u %*u %u", &shared);
85
+ fclose(f);
86
86
 
87
- if (status != 1) return Qnil ;
88
- return UINT2NUM(shared * PAGESIZE) ;
87
+ if (status != 1) return Qnil;
88
+ return UINT2NUM(shared * PAGESIZE);
89
89
  }
90
90
 
91
- static VALUE statm_memory(volatile VALUE obj, volatile VALUE pid) {
92
- int _pid = FIX2INT(pid) ;
93
- if (_pid < 0) return Qnil ;
91
+ static VALUE statm_memory(VALUE obj, VALUE pid) {
92
+ pid_t _pid = (pid_t)NUM2LONG(pid);
93
+ if (_pid < 0) return Qnil;
94
94
 
95
- char _path[22] ;
96
- sprintf(_path, "/proc/%d/statm", _pid) ;
95
+ char _path[22];
96
+ snprintf(_path, sizeof(_path), "/proc/%d/statm", _pid);
97
97
 
98
- FILE *f = fopen(_path, "r") ;
99
- if (!f) return Qnil ;
98
+ FILE *f = fopen(_path, "r");
99
+ if (!f) return Qnil;
100
100
 
101
- unsigned int resident, shared ;
102
- char status = fscanf(f, "%*u %u %u", &resident, &shared) ;
103
- fclose(f) ;
101
+ unsigned int resident, shared;
102
+ char status = fscanf(f, "%*u %u %u", &resident, &shared);
103
+ fclose(f);
104
104
 
105
- if (status != 2) return Qnil ;
105
+ if (status != 2) return Qnil;
106
106
 
107
- unsigned int v = (resident - shared) * PAGESIZE ;
108
- return UINT2NUM(v) ;
107
+ unsigned int v = (resident - shared) * PAGESIZE;
108
+ return UINT2NUM(v);
109
109
  }
data/ext/procfs/uptime.h CHANGED
@@ -1,12 +1,12 @@
1
- static VALUE uptime_f(volatile VALUE obj) {
2
- FILE *f = fopen("/proc/uptime", "r") ;
3
- if (!f) return Qnil ;
1
+ static VALUE uptime_f(VALUE obj) {
2
+ FILE *f = fopen("/proc/uptime", "r");
3
+ if (!f) return Qnil;
4
4
 
5
- double up_f ;
6
- char status = fscanf(f, "%lf", &up_f) ;
7
- fclose(f) ;
5
+ double up_f;
6
+ char status = fscanf(f, "%lf", &up_f);
7
+ fclose(f);
8
8
 
9
- if (status != 1) return Qnil ;
9
+ if (status != 1) return Qnil;
10
10
 
11
- return DBL2NUM(up_f) ;
11
+ return DBL2NUM(up_f);
12
12
  }
@@ -8,4 +8,6 @@ unless have_header('unistd.h') && have_header('ruby.h')
8
8
  abort('Missing header')
9
9
  end
10
10
 
11
+ $CFLAGS << ' -O3 -march=native -mtune=native'
12
+
11
13
  create_makefile 'linux_stat/sysconf'