summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/rabbit.erl5
-rw-r--r--src/rabbit_looking_glass.erl56
2 files changed, 61 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..6cd53dbc23
--- /dev/null
+++ b/src/rabbit_looking_glass.erl
@@ -0,0 +1,56 @@
+%% 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}]).
+-ignore_xref([{maps, from_list, 1}]).
+
+-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",
+ maps:from_list([
+ {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}].