summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Klishin <michael@novemberain.com>2017-06-27 18:49:01 +0300
committerGitHub <noreply@github.com>2017-06-27 18:49:01 +0300
commit31a81e3779dc68e2c661233a60212b6555ffc305 (patch)
treec2b42dd78e7ddb5ea62a3f02c91d8f52a33c29c5 /src
parentf74855c1e3b0d5dfb2f723bdbfd6ceec6913442c (diff)
parent13bd0be01c28137c97ff187e2dcc6ada8023eeab (diff)
downloadrabbitmq-server-git-31a81e3779dc68e2c661233a60212b6555ffc305.tar.gz
Merge pull request #1225 from rabbitmq/rabbitmq-common-198
Add rabbit_tracer boot step for running Looking Glass
Diffstat (limited to 'src')
-rw-r--r--src/rabbit.erl5
-rw-r--r--src/rabbit_looking_glass.erl41
2 files changed, 46 insertions, 0 deletions
diff --git a/src/rabbit.erl b/src/rabbit.erl
index 138d03f051..254dc02d73 100644
--- a/src/rabbit.erl
+++ b/src/rabbit.erl
@@ -220,6 +220,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..71d7b067b8
--- /dev/null
+++ b/src/rabbit_looking_glass.erl
@@ -0,0 +1,41 @@
+%% 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).
+
+-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})
+ 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}].