Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Silent when optput is requested and prettyfing. #2

Merged
merged 1 commit into from
Nov 6, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 35 additions & 21 deletions memory.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Copyright (C) 2012 - 2015 Markus Bergholz <[email protected]>
##
## Copyright (C) 2015 JuanPi Carbajal <[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
Expand All @@ -20,33 +21,46 @@
## memory is available and how much is currently being
## used by Octave

function memory()
function m = memory()

if isunix
# open /proc/meminfo
meminfo = fopen("/proc/meminfo", "r");

# open /proc/meminfo
meminfo = fopen ("/proc/meminfo", "r");
PID = getpid;
total = str2double(cell2mat(cell2mat(regexp(fread(meminfo, "char=>char").', "MemTotal:(.*?) kB\n", "tokens"))));
fclose(meminfo);
total = str2double ( ...
cell2mat (cell2mat ( ...
regexp( ...
fread(meminfo, "char=>char").', ...
"MemTotal:(.*?) kB\n", "tokens"))));

fclose (meminfo);


# open /proc/<pid>/statm
statm = fopen(sprintf("/proc/%d/statm", PID), "r");
statm = fopen (sprintf ("/proc/%d/statm", PID), "r");
# statm is measured in pages. the pagesize is 4096 bytes
mem = sscanf(fread(statm, "char=>char").', "%d ")'([1 2 3 6]) * 4 / 1024;
fclose(statm);

# print verbose output
fprintf("\n Total memory usage by GNU Octave (VmSize): \t %g MB", mem(1))
fprintf("\n RSS Size: \t\t\t\t\t %g MB", mem(2))
fprintf("\n shared pages: \t\t\t\t\t %g MB", mem(3))
fprintf("\n data + stack size: \t\t\t\t %g MB", mem(4))
fprintf("\n Physical Memory (RAM): \t\t\t %g MB\n\n", total/1024)
mem = sscanf ( ...
fread (statm, "char=>char").', ...
"%d ").'([1 2 3 6]) * 4 / 1024;
fclose (statm);

else
error("Function MEMORY is not available on this platform.")
if (nargout < 1)
# print verbose output
fprintf (["\n Total memory usage by \
GNU Octave (VmSize): \t %g MB"], mem(1));
fprintf ("\n RSS Size: \t\t\t\t\t %g MB", mem(2));
fprintf ("\n shared pages: \t\t\t\t\t %g MB", mem(3));
fprintf ("\n data + stack size: \t\t\t\t %g MB", mem(4));
fprintf ("\n Physical Memory (RAM): \
\t\t\t %g MB\n\n", total/1024);
fflush (stdout);
endif

m = struct ("total",mem(1),"rss",mem(2), ...
"shared",mem(3),"data",mem(4), ...
"physical", total/1024);
else
error ("Function MEMORY is not available on this platform.");
endif
endfunction

endfunction