summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGerhard Lazu <gerhard@rabbitmq.com>2017-10-04 16:01:59 +0100
committerLoïc Hoguin <loic@rabbitmq.com>2017-10-04 16:01:59 +0100
commitb50cf0f3cc5468b9d1064cbb916ae9afda3a469b (patch)
tree829ffa7f58f4a8f53159e4f4d86dce912debc07a /src
parent3f96e9b69191f7c08bfa0b6f22cf30b82de9a006 (diff)
downloadrabbitmq-server-git-b50cf0f3cc5468b9d1064cbb916ae9afda3a469b.tar.gz
Integrate looking_glass
An Erlang/Elixir/BEAM profiler tool: https://github.com/rabbitmq/looking_glass Signed-off-by: Loïc Hoguin <loic@rabbitmq.com>
Diffstat (limited to 'src')
-rw-r--r--src/rabbit.erl5
-rw-r--r--src/rabbit_looking_glass.erl46
2 files changed, 51 insertions, 0 deletions
diff --git a/src/rabbit.erl b/src/rabbit.erl
index 93f5230250..033379bad1 100644
--- a/src/rabbit.erl
+++ b/src/rabbit.erl
@@ -200,6 +200,11 @@
[rabbit_core_metrics_gc]}},
{enables, networking}]}).
+-rabbit_boot_step({rabbit_looking_glass,
+ [{description, "Looking Glass tracer and profiler"},
+ {mfa, {rabbit_looking_glass, boot, []}},
+ {requires, networking}]}).
+
%%---------------------------------------------------------------------------
-include("rabbit_framing.hrl").
diff --git a/src/rabbit_looking_glass.erl b/src/rabbit_looking_glass.erl
new file mode 100644
index 0000000000..702fb41eb8
--- /dev/null
+++ b/src/rabbit_looking_glass.erl
@@ -0,0 +1,46 @@
+%% 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-2017 Pivotal Software, Inc. All rights reserved.
+%%
+
+-module(rabbit_looking_glass).
+
+-ignore_xref([{lg, trace, 4}]).
+
+-export([boot/0]).
+-export([connections/0]).
+
+boot() ->
+ case os:getenv("RABBITMQ_TRACER") of
+ false ->
+ ok;
+ Value ->
+ Input = parse_value(Value),
+ rabbit_log:info("Enabling Looking Glass profiler, input value: ~p", [Input]),
+ {ok, _} = application:ensure_all_started(looking_glass),
+ lg:trace(Input, lg_file_tracer, "traces.lz4", #{
+ mode => profile,
+ running => true,
+ send => true})
+ end.
+
+parse_value(Value) ->
+ [begin
+ [Mod, Fun] = string:tokens(C, ":"),
+ {callback, list_to_atom(Mod), list_to_atom(Fun)}
+ end || C <- string:tokens(Value, ",")].
+
+connections() ->
+ Pids = [Pid || {{conns_sup, _}, Pid} <- ets:tab2list(ranch_server)],
+ [{app, rabbit}, {app, rabbit_common}, {scope, Pids}].