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

Commit af04d72

Browse files
Introduce rabbit_runtime
1 parent e6b3d1f commit af04d72

File tree

2 files changed

+57
-17
lines changed

2 files changed

+57
-17
lines changed

src/rabbit_misc.erl

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,12 +1206,11 @@ rpc_call(Node, Mod, Fun, Args, Timeout) ->
12061206
rpc:call(Node, Mod, Fun, Args, Timeout)
12071207
end.
12081208

1209+
get_gc_info(Pid) ->
1210+
rabbit_runtime:get_gc_info(Pid).
1211+
12091212
guess_number_of_cpu_cores() ->
1210-
case erlang:system_info(logical_processors_available) of
1211-
unknown -> % Happens on Mac OS X.
1212-
erlang:system_info(schedulers);
1213-
N -> N
1214-
end.
1213+
rabbit_runtime:guess_number_of_cpu_cores().
12151214

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

1226-
get_gc_info(Pid) ->
1227-
{garbage_collection, GC} = erlang:process_info(Pid, garbage_collection),
1228-
case proplists:get_value(max_heap_size, GC) of
1229-
I when is_integer(I) ->
1230-
GC;
1231-
undefined ->
1232-
GC;
1233-
Map ->
1234-
lists:keyreplace(max_heap_size, 1, GC,
1235-
{max_heap_size, maps:get(size, Map)})
1236-
end.
1237-
12381225
%% -------------------------------------------------------------------------
12391226
%% Begin copypasta from gen_server2.erl
12401227

src/rabbit_runtime.erl

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
%% The contents of this file are subject to the Mozilla Public License
2+
%% Version 1.1 (the "License"); you may not use this file except in
3+
%% compliance with the License. You may obtain a copy of the License
4+
%% at http://www.mozilla.org/MPL/
5+
%%
6+
%% Software distributed under the License is distributed on an "AS IS"
7+
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
8+
%% the License for the specific language governing rights and
9+
%% limitations under the License.
10+
%%
11+
%% The Original Code is RabbitMQ.
12+
%%
13+
%% The Initial Developer of the Original Code is GoPivotal, Inc.
14+
%% Copyright (c) 2007-2018 Pivotal Software, Inc. All rights reserved.
15+
%%
16+
17+
%% This module provides access to runtime metrics that are exposed
18+
%% via CLI tools, management UI or otherwise used by the broker.
19+
20+
-module(rabbit_runtime).
21+
22+
%%
23+
%% API
24+
%%
25+
26+
-export([guess_number_of_cpu_cores/0, get_gc_info/1, msacc_stats/1]).
27+
28+
29+
-spec guess_number_of_cpu_cores() -> pos_integer().
30+
guess_number_of_cpu_cores() ->
31+
case erlang:system_info(logical_processors_available) of
32+
unknown -> % Happens on Mac OS X.
33+
erlang:system_info(schedulers);
34+
N -> N
35+
end.
36+
37+
-spec get_gc_info(pid()) -> nonempty_list(tuple()).
38+
get_gc_info(Pid) ->
39+
{garbage_collection, GC} = erlang:process_info(Pid, garbage_collection),
40+
case proplists:get_value(max_heap_size, GC) of
41+
I when is_integer(I) ->
42+
GC;
43+
undefined ->
44+
GC;
45+
Map ->
46+
lists:keyreplace(max_heap_size, 1, GC,
47+
{max_heap_size, maps:get(size, Map)})
48+
end.
49+
50+
-spec msacc_stats(integer()) -> nonempty_list(#{atom() => any()}).
51+
msacc_stats(TimeInMs) ->
52+
msacc:start(TimeInMs),
53+
msacc:stats().

0 commit comments

Comments
 (0)