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

Introduce rabbit_runtime #286

Merged
merged 4 commits into from
Dec 10, 2018
Merged
Show file tree
Hide file tree
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
21 changes: 4 additions & 17 deletions src/rabbit_misc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1206,12 +1206,11 @@ rpc_call(Node, Mod, Fun, Args, Timeout) ->
rpc:call(Node, Mod, Fun, Args, Timeout)
end.

get_gc_info(Pid) ->
rabbit_runtime:get_gc_info(Pid).

guess_number_of_cpu_cores() ->
case erlang:system_info(logical_processors_available) of
unknown -> % Happens on Mac OS X.
erlang:system_info(schedulers);
N -> N
end.
rabbit_runtime:guess_number_of_cpu_cores().

%% Discussion of choosen values is at
%% https://github.com/rabbitmq/rabbitmq-server/issues/151
Expand All @@ -1223,18 +1222,6 @@ report_default_thread_pool_size() ->
io:format("~b", [guess_default_thread_pool_size()]),
erlang:halt(0).

get_gc_info(Pid) ->
{garbage_collection, GC} = erlang:process_info(Pid, garbage_collection),
case proplists:get_value(max_heap_size, GC) of
I when is_integer(I) ->
GC;
undefined ->
GC;
Map ->
lists:keyreplace(max_heap_size, 1, GC,
{max_heap_size, maps:get(size, Map)})
end.

%% -------------------------------------------------------------------------
%% Begin copypasta from gen_server2.erl

Expand Down
55 changes: 55 additions & 0 deletions src/rabbit_runtime.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
%% 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 GoPivotal, Inc.
%% Copyright (c) 2007-2018 Pivotal Software, Inc. All rights reserved.
%%

%% This module provides access to runtime metrics that are exposed
%% via CLI tools, management UI or otherwise used by the broker.

-module(rabbit_runtime).

%%
%% API
%%

-export([guess_number_of_cpu_cores/0, get_gc_info/1, msacc_stats/1]).


-spec guess_number_of_cpu_cores() -> pos_integer().
guess_number_of_cpu_cores() ->
case erlang:system_info(logical_processors_available) of
unknown -> % Happens on Mac OS X.
erlang:system_info(schedulers);
N -> N
end.

-spec get_gc_info(pid()) -> nonempty_list(tuple()).
get_gc_info(Pid) ->
{garbage_collection, GC} = erlang:process_info(Pid, garbage_collection),
case proplists:get_value(max_heap_size, GC) of
I when is_integer(I) ->
GC;
undefined ->
GC;
Map ->
lists:keyreplace(max_heap_size, 1, GC,
{max_heap_size, maps:get(size, Map)})
end.

-spec msacc_stats(integer()) -> nonempty_list(#{atom() => any()}).
msacc_stats(TimeInMs) ->
msacc:start(TimeInMs),
S = msacc:stats(),
msacc:stop(),
S.