diff options
author | Simon MacMullen <simon@rabbitmq.com> | 2012-09-24 12:54:19 +0100 |
---|---|---|
committer | Simon MacMullen <simon@rabbitmq.com> | 2012-09-24 12:54:19 +0100 |
commit | 6b5d91f884e339098d2794f469b01af1a77fbab5 (patch) | |
tree | b3b8e32e62f4657d6bbc7ed7eac8385ca953e46c | |
parent | 2156b9ac95585daae655881f2becb969499c028a (diff) | |
download | rabbitmq-server-6b5d91f884e339098d2794f469b01af1a77fbab5.tar.gz |
Move this stuff to its own module
-rw-r--r-- | src/rabbit.erl | 67 | ||||
-rw-r--r-- | src/rabbit_vm.erl | 93 |
2 files changed, 95 insertions, 65 deletions
diff --git a/src/rabbit.erl b/src/rabbit.erl index 26e4f1f4..da2a1783 100644 --- a/src/rabbit.erl +++ b/src/rabbit.erl @@ -21,7 +21,7 @@ -export([start/0, boot/0, stop/0, stop_and_halt/0, await_startup/0, status/0, is_running/0, is_running/1, environment/0, rotate_logs/1, force_event_refresh/0, - start_fhc/0, memory/0]). + start_fhc/0]). -export([start/2, stop/1]). @@ -247,7 +247,6 @@ -spec(maybe_insert_default_data/0 :: () -> 'ok'). -spec(boot_delegate/0 :: () -> 'ok'). -spec(recover/0 :: () -> 'ok'). --spec(memory/0 :: () -> rabbit_types:infos()). -endif. @@ -357,7 +356,7 @@ status() -> {running_applications, application:which_applications(infinity)}, {os, os:type()}, {erlang_version, erlang:system_info(system_version)}, - {memory, memory()}], + {memory, rabbit_vm:memory()}], S2 = rabbit_misc:filter_exit_map( fun ({Key, {M, F, A}}) -> {Key, erlang:apply(M, F, A)} end, [{vm_memory_high_watermark, {vm_memory_monitor, @@ -744,65 +743,3 @@ start_fhc() -> rabbit_sup:start_restartable_child( file_handle_cache, [fun rabbit_alarm:set_alarm/1, fun rabbit_alarm:clear_alarm/1]). - -%% Like erlang:memory(), but with awareness of rabbit-y things -memory() -> - ConnChs = sup_memory(rabbit_tcp_client_sup), - Qs = sup_memory(rabbit_amqqueue_sup) + - sup_memory(rabbit_mirror_queue_slave_sup), - Mnesia = mnesia_memory(), - MsgIndexETS = ets_memory(rabbit_msg_store_ets_index), - MsgIndexProc = pid_memory(msg_store_transient) + - pid_memory(msg_store_persistent), - MgmtDbETS = ets_memory(rabbit_mgmt_db), - MgmtDbProc = sup_memory(rabbit_mgmt_sup), - [{total, Total}, - {processes, Processes}, - {ets, ETS}, - {atom, Atom}, - {binary, Bin}, - {code, Code}, - {system, System}] = - erlang:memory([total, processes, ets, atom, binary, code, system]), - [{total, Total}, - {connection_channel_procs, ConnChs}, - {queue_procs, Qs}, - {other_proc, Processes - ConnChs - Qs - MsgIndexProc - - MgmtDbProc}, - {mnesia, Mnesia}, - {mgmt_db, MgmtDbETS + MgmtDbProc}, - {msg_index, MsgIndexETS + MsgIndexProc}, - {other_ets, ETS - Mnesia - MsgIndexETS - MgmtDbETS}, - {binary, Bin}, - {code, Code}, - {atom, Atom}, - {other_system, System - ETS - Atom - Bin - Code}]. - -sup_memory(Sup) -> - lists:sum([child_memory(P, T) || {_, P, T, _} <- sup_children(Sup)]) + - pid_memory(Sup). - -sup_children(Sup) -> - rabbit_misc:with_exit_handler( - rabbit_misc:const([]), fun () -> supervisor:which_children(Sup) end). - -pid_memory(Pid) when is_pid(Pid) -> element(2, process_info(Pid, memory)); -pid_memory(Name) when is_atom(Name) -> case whereis(Name) of - P when is_pid(P) -> pid_memory(P); - _ -> 0 - end. - -child_memory(Pid, worker) when is_pid (Pid) -> pid_memory(Pid); -child_memory(Pid, supervisor) when is_pid (Pid) -> sup_memory(Pid); -child_memory(_, _) -> 0. - -mnesia_memory() -> - lists:sum([bytes(mnesia:table_info(Tab, memory)) || - Tab <- mnesia:system_info(tables)]). - -ets_memory(Name) -> - lists:sum([bytes(ets:info(T, memory)) || T <- ets:all(), - N <- [ets:info(T, name)], - N =:= Name]). - -bytes(Words) -> Words * erlang:system_info(wordsize). diff --git a/src/rabbit_vm.erl b/src/rabbit_vm.erl new file mode 100644 index 00000000..ce6c9323 --- /dev/null +++ b/src/rabbit_vm.erl @@ -0,0 +1,93 @@ +%% The contents of this file are subject to the Mozilla Public License +%% Version 1.1 (the "License"); you may not use this file except in +%% compliance with the License. You may obtain a copy of the License +%% at http://www.mozilla.org/MPL/ +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +%% the License for the specific language governing rights and +%% limitations under the License. +%% +%% The Original Code is RabbitMQ. +%% +%% The Initial Developer of the Original Code is VMware, Inc. +%% Copyright (c) 2007-2012 VMware, Inc. All rights reserved. +%% + +-module(rabbit_vm). + +-export([memory/0]). + +%%---------------------------------------------------------------------------- + +-ifdef(use_specs). + +-spec(memory/0 :: () -> rabbit_types:infos()). + +-endif. + +%%---------------------------------------------------------------------------- + +%% Like erlang:memory(), but with awareness of rabbit-y things +memory() -> + ConnChs = sup_memory(rabbit_tcp_client_sup), + Qs = sup_memory(rabbit_amqqueue_sup) + + sup_memory(rabbit_mirror_queue_slave_sup), + Mnesia = mnesia_memory(), + MsgIndexETS = ets_memory(rabbit_msg_store_ets_index), + MsgIndexProc = pid_memory(msg_store_transient) + + pid_memory(msg_store_persistent), + MgmtDbETS = ets_memory(rabbit_mgmt_db), + MgmtDbProc = sup_memory(rabbit_mgmt_sup), + [{total, Total}, + {processes, Processes}, + {ets, ETS}, + {atom, Atom}, + {binary, Bin}, + {code, Code}, + {system, System}] = + erlang:memory([total, processes, ets, atom, binary, code, system]), + [{total, Total}, + {connection_channel_procs, ConnChs}, + {queue_procs, Qs}, + {other_proc, Processes - ConnChs - Qs - MsgIndexProc - + MgmtDbProc}, + {mnesia, Mnesia}, + {mgmt_db, MgmtDbETS + MgmtDbProc}, + {msg_index, MsgIndexETS + MsgIndexProc}, + {other_ets, ETS - Mnesia - MsgIndexETS - MgmtDbETS}, + {binary, Bin}, + {code, Code}, + {atom, Atom}, + {other_system, System - ETS - Atom - Bin - Code}]. + +%%---------------------------------------------------------------------------- + +sup_memory(Sup) -> + lists:sum([child_memory(P, T) || {_, P, T, _} <- sup_children(Sup)]) + + pid_memory(Sup). + +sup_children(Sup) -> + rabbit_misc:with_exit_handler( + rabbit_misc:const([]), fun () -> supervisor:which_children(Sup) end). + +pid_memory(Pid) when is_pid(Pid) -> element(2, process_info(Pid, memory)); +pid_memory(Name) when is_atom(Name) -> case whereis(Name) of + P when is_pid(P) -> pid_memory(P); + _ -> 0 + end. + +child_memory(Pid, worker) when is_pid (Pid) -> pid_memory(Pid); +child_memory(Pid, supervisor) when is_pid (Pid) -> sup_memory(Pid); +child_memory(_, _) -> 0. + +mnesia_memory() -> + lists:sum([bytes(mnesia:table_info(Tab, memory)) || + Tab <- mnesia:system_info(tables)]). + +ets_memory(Name) -> + lists:sum([bytes(ets:info(T, memory)) || T <- ets:all(), + N <- [ets:info(T, name)], + N =:= Name]). + +bytes(Words) -> Words * erlang:system_info(wordsize). |