summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon MacMullen <simon@rabbitmq.com>2014-09-17 13:14:20 +0100
committerSimon MacMullen <simon@rabbitmq.com>2014-09-17 13:14:20 +0100
commit258969e238ff25bbd84562c823a466aef99a0d11 (patch)
tree243ce97e77e77475384805fc0b73b617b549d0be
parent996fc2272f134264a44bcf96a43d971d861d11c9 (diff)
downloadrabbitmq-server-bug25824.tar.gz
Crude binary-summarisation thing.bug25824
-rw-r--r--src/rabbit_vm.erl35
1 files changed, 26 insertions, 9 deletions
diff --git a/src/rabbit_vm.erl b/src/rabbit_vm.erl
index c2e709b5..bcdd77ae 100644
--- a/src/rabbit_vm.erl
+++ b/src/rabbit_vm.erl
@@ -16,7 +16,7 @@
-module(rabbit_vm).
--export([memory/0]).
+-export([memory/0, binary/0]).
-define(MAGIC_PLUGINS, ["mochiweb", "webmachine", "cowboy", "sockjs",
"rfc4627_jsonrpc"]).
@@ -26,6 +26,7 @@
-ifdef(use_specs).
-spec(memory/0 :: () -> rabbit_types:infos()).
+-spec(binary/0 :: () -> rabbit_types:infos()).
-endif.
@@ -33,14 +34,7 @@
%% Like erlang:memory(), but with awareness of rabbit-y things
memory() ->
- ConnProcs = [rabbit_tcp_client_sup, ssl_connection_sup, amqp_sup],
- QProcs = [rabbit_amqqueue_sup_sup],
- MsgIndexProcs = [msg_store_transient, msg_store_persistent],
- MgmtDbProcs = [rabbit_mgmt_sup_sup],
- PluginProcs = plugin_sups(),
-
- All = [ConnProcs, QProcs, MsgIndexProcs, MgmtDbProcs, PluginProcs],
-
+ All = interesting_sups(),
{Sums, _Other} = sum_processes(lists:append(All), [memory]),
[Conns, Qs, MsgIndexProc, MgmtDbProc, Plugins] =
@@ -80,6 +74,18 @@ memory() ->
%% claims about negative memory. See
%% http://erlang.org/pipermail/erlang-questions/2012-September/069320.html
+binary() ->
+ All = interesting_sups(),
+ {Sums, Rest} =
+ sum_processes(
+ lists:append(All),
+ fun (binary, Info, Acc) ->
+ lists:foldl(fun ({Ptr, Sz, _RefCnt}, Acc0) ->
+ sets:add_element({Ptr, Sz}, Acc0)
+ end, Acc, Info)
+ end, [{binary, sets:new()}]),
+ [{K, aggregate_binary(V)} || {K, V} <- Sums ++ [{unknown, Rest}]].
+
%%----------------------------------------------------------------------------
mnesia_memory() ->
@@ -96,6 +102,14 @@ ets_memory(Name) ->
bytes(Words) -> Words * erlang:system_info(wordsize).
+interesting_sups() ->
+ ConnProcs = [rabbit_tcp_client_sup, ssl_connection_sup, amqp_sup],
+ QProcs = [rabbit_amqqueue_sup_sup],
+ MsgIndexProcs = [msg_store_transient, msg_store_persistent],
+ MgmtDbProcs = [rabbit_mgmt_sup_sup],
+ PluginProcs = plugin_sups(),
+ [ConnProcs, QProcs, MsgIndexProcs, MgmtDbProcs, PluginProcs].
+
plugin_sups() ->
lists:append([plugin_sup(App) ||
{App, _, _} <- rabbit_misc:which_applications(),
@@ -128,6 +142,9 @@ extract_memory(Name, Sums) ->
{value, {memory, V}} = lists:keysearch(memory, 1, Accs),
V.
+aggregate_binary([{binary, Set}]) ->
+ sets:fold(fun({_Ptr, Sz}, Acc) -> Acc + Sz end, 0, Set).
+
%%----------------------------------------------------------------------------
%% NB: this code is non-rabbit specific.