Created
June 17, 2015 18:44
-
-
Save markuman/08b4537a62d1170266b7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% Copyright (C) 2012 - 2015 Markus Bergholz <[email protected]> | |
%% | |
%% This program is free software; you can redistribute it and/or modify it under | |
%% the terms of the GNU General Public License as published by the Free Software | |
%% Foundation; either version 3 of the License, or (at your option) any later | |
%% version. | |
%% | |
%% This program is distributed in the hope that it will be useful, but WITHOUT | |
%% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
%% FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | |
%% details. | |
%% | |
%% You should have received a copy of the GNU General Public License along with | |
%% this program; if not, see <http://www.gnu.org/licenses/>. | |
%% -*- texinfo -*- | |
%% | |
%% | |
%% memory returns information about how much physical | |
%% memory is available and how much is currently being | |
%% used by Octave | |
function memory() | |
if isunix == 1 | |
meminfo = fopen('/proc/meminfo', 'r'); | |
if (exist('OCTAVE_VERSION', 'builtin') == 5) | |
PID = getpid; | |
lol = 'Octave'; | |
total = str2double(cell2mat(cell2mat(regexp(fread(meminfo, 'char=>char').', 'MemTotal:(.*?) kB\n', 'tokens')))); | |
else | |
PID = feature('getpid'); | |
lol = 'Matlab'; | |
regexp(fread(meminfo, 'char=>char').', 'MemTotal:(.*?) kB\n', 'tokens'); | |
total = str2double(ans{1}); | |
end | |
fclose(meminfo); | |
statm = fopen(sprintf('/proc/%d/statm', PID), 'r'); | |
mem = sscanf(fread(statm, 'char=>char').', '%d ')'; | |
mem = mem([1 6]); | |
fclose(statm); | |
fprintf('\n Total memory usage by %s: \t %g MB', lol, mem(1)/1024) | |
fprintf('\n Data + Stack Size: \t\t %g MB', mem(2)/1024) | |
fprintf('\n Physical Memory (RAM): \t %g MB\n\n', total/1024) | |
else | |
error('i don''t care') | |
end%if | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment