Skip to content

Commit 6a84ef4

Browse files
author
Daniil Fedotov
committed
Current process system memory functions for various OSes.
According to AIX, SunOS and BSD docs, ps command can have rss format, so get_ps_memory should work. We already requiring tasklist for wait command, so we can use it here.
1 parent a83efdf commit 6a84ef4

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/vm_memory_monitor.erl

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -384,19 +384,30 @@ get_system_process_resident_memory({unix, linux}) ->
384384
get_ps_memory();
385385

386386
get_system_process_resident_memory({unix,freebsd}) ->
387-
{error, not_implemented_for_os};
387+
get_ps_memory();
388388

389389
get_system_process_resident_memory({unix,openbsd}) ->
390-
{error, not_implemented_for_os};
390+
get_ps_memory();
391391

392392
get_system_process_resident_memory({win32,_OSname}) ->
393-
{error, not_implemented_for_os};
393+
OsPid = os:getpid(),
394+
Cmd = " tasklist /fi \"pid eq " ++ OsPid ++ "\" /fo LIST 2>&1 ",
395+
CmdOutput = os:cmd(Cmd),
396+
%% Memory usage is displayed in kilobytes
397+
%% with comma-separated thousands
398+
case re:run(CmdOutput, "Mem Usage:\\s+([0-9,]+)\\s+K", [{capture, all_but_first, list}]) of
399+
{match, [Match]} ->
400+
NoCommas = [ N || N <- Match, N =/= $, ],
401+
{ok, list_to_integer(NoCommas) * 1024};
402+
_ ->
403+
{error, {unexpected_output_from_command, Cmd, CmdOutput}}
404+
end;
394405

395406
get_system_process_resident_memory({unix, sunos}) ->
396-
{error, not_implemented_for_os};
407+
get_ps_memory();
397408

398409
get_system_process_resident_memory({unix, aix}) ->
399-
{error, not_implemented_for_os};
410+
get_ps_memory();
400411

401412
get_system_process_resident_memory(_OsType) ->
402413
{error, not_implemented_for_os}.

0 commit comments

Comments
 (0)