Skip to content
This repository was archived by the owner on Nov 17, 2020. It is now read-only.

Commit 4b8a2fa

Browse files
committed
Use recon_alloc:memory for all memory calculation
1 parent 701fc1b commit 4b8a2fa

File tree

1 file changed

+7
-42
lines changed

1 file changed

+7
-42
lines changed

src/vm_memory_monitor.erl

Lines changed: 7 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -164,55 +164,20 @@ get_memory_calculation_strategy() ->
164164
rss
165165
end.
166166

167+
%% Win32 Note: 3.6.12 shipped with code that used wmic.exe to get the
168+
%% WorkingSetSize value for the running erl.exe process. Unfortunately
169+
%% even with a moderate invocation rate of 1 ops/second that uses more
170+
%% CPU resources than some Windows users are willing to tolerate.
171+
%% See rabbitmq/rabbitmq-server#1343 and rabbitmq/rabbitmq-common#224
172+
%% for details.
167173
-spec get_system_process_resident_memory() -> {ok, Bytes :: integer()} | {error, term()}.
168174
get_system_process_resident_memory() ->
169175
try
170-
get_system_process_resident_memory(os:type())
176+
{ok, recon_alloc:memory(allocated)}
171177
catch _:Error ->
172178
{error, {"Failed to get process resident memory", Error}}
173179
end.
174180

175-
get_system_process_resident_memory({unix,darwin}) ->
176-
get_ps_memory();
177-
178-
get_system_process_resident_memory({unix, linux}) ->
179-
get_ps_memory();
180-
181-
get_system_process_resident_memory({unix,freebsd}) ->
182-
get_ps_memory();
183-
184-
get_system_process_resident_memory({unix,openbsd}) ->
185-
get_ps_memory();
186-
187-
get_system_process_resident_memory({win32,_OSname}) ->
188-
%% Note: 3.6.12 shipped with code that used wmic.exe to get the
189-
%% WorkingSetSize value for the running erl.exe process. Unfortunately
190-
%% even with a moderate invocation rate of 1 ops/second that uses more
191-
%% CPU resources than some Windows users are willing to tolerate.
192-
%% See rabbitmq/rabbitmq-server#1343 and rabbitmq/rabbitmq-common#224
193-
%% for details.
194-
{ok, recon_alloc:memory(allocated)};
195-
196-
get_system_process_resident_memory({unix, sunos}) ->
197-
get_ps_memory();
198-
199-
get_system_process_resident_memory({unix, aix}) ->
200-
get_ps_memory();
201-
202-
get_system_process_resident_memory(_OsType) ->
203-
{error, not_implemented_for_os}.
204-
205-
get_ps_memory() ->
206-
OsPid = os:getpid(),
207-
Cmd = "ps -p " ++ OsPid ++ " -o rss=",
208-
CmdOutput = os:cmd(Cmd),
209-
case re:run(CmdOutput, "[0-9]+", [{capture, first, list}]) of
210-
{match, [Match]} ->
211-
{ok, list_to_integer(Match) * 1024};
212-
_ ->
213-
{error, {unexpected_output_from_command, Cmd, CmdOutput}}
214-
end.
215-
216181
%%----------------------------------------------------------------------------
217182
%% gen_server callbacks
218183
%%----------------------------------------------------------------------------

0 commit comments

Comments
 (0)