Skip to content

Commit 951197b

Browse files
committed
use java to get RAM free, total and CPU load
1 parent df3c02a commit 951197b

File tree

6 files changed

+43
-23
lines changed

6 files changed

+43
-23
lines changed

+stdlib/+sys/checkRAM.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
end
1313

1414
% get available RAM
15-
freebytes = stdlib.sys.memfree();
15+
freebytes = stdlib.sys.ram_free();
1616
% variable sizing
1717
switch(myclass)
1818
case {'single','int32','uint32'}, bits = 32;

+stdlib/+sys/cpu_load.m

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function L = cpu_load()
2+
%% CPU_LOAD get total physical CPU load
3+
% https://docs.oracle.com/javase/9/docs/api/com/sun/management/OperatingSystemMXBean.html#getSystemCpuLoad--
4+
% Returns the "recent cpu usage" for the whole system.
5+
% This value is a double in the [0.0,1.0] interval.
6+
% A value of 0.0 means that all CPUs were idle during the recent period of time observed, while a value of 1.0 means that all CPUs were actively running 100% of the time during the recent period being observed.
7+
% All values betweens 0.0 and 1.0 are possible depending of the activities going on in the system.
8+
% If the system recent cpu usage is not available, the method returns a negative value.
9+
10+
b = java.lang.management.ManagementFactory.getOperatingSystemMXBean();
11+
L = b.getSystemCpuLoad();
12+
13+
end

+stdlib/+sys/memfree.m

Lines changed: 0 additions & 17 deletions
This file was deleted.

+stdlib/+sys/ram_free.m

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
function freebytes = ram_free()
2+
%% ram_free()
3+
% get free physical RAM across operating systems
4+
% Ref: https://docs.oracle.com/javase/9/docs/api/com/sun/management/OperatingSystemMXBean.html
5+
%
6+
%%% Outputs
7+
% * freebytes: free physical RAM [bytes]
8+
9+
10+
b = java.lang.management.ManagementFactory.getOperatingSystemMXBean();
11+
12+
freebytes = b.getFreePhysicalMemorySize();
13+
14+
end

+stdlib/+sys/ram_total.m

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
function bytes = ram_total()
2+
%% ram_total()
3+
% get total physical RAM across operating systems
4+
% Ref: https://docs.oracle.com/javase/9/docs/api/com/sun/management/OperatingSystemMXBean.html
5+
%
6+
%%% Outputs
7+
% * bytes: total physical RAM [bytes]
8+
9+
10+
b = java.lang.management.ManagementFactory.getOperatingSystemMXBean();
11+
12+
bytes = b.getTotalPhysicalMemorySize();
13+
14+
end

test/TestIntg.m

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ function setup_path(tc)
1313
methods (Test)
1414

1515
function test_checkRAM(tc)
16-
pe = pyenv;
17-
tc.assumeFalse(pe.Version == "", "Python not available")
1816
tc.assertTrue(islogical(stdlib.sys.checkRAM(1)))
1917
end
2018

@@ -25,9 +23,7 @@ function test_diskfree(tc)
2523
end
2624

2725
function test_memory(tc)
28-
pe = pyenv;
29-
tc.assumeFalse(pe.Version == "", "Python not available")
30-
tc.assertTrue(isnumeric(stdlib.sys.memfree))
26+
tc.assertTrue(isnumeric(stdlib.sys.ram_free))
3127
end
3228

3329
end

0 commit comments

Comments
 (0)