diff options
| author | Loïc Hoguin <essen@ninenines.eu> | 2017-05-18 13:26:23 +0200 |
|---|---|---|
| committer | Loïc Hoguin <essen@ninenines.eu> | 2017-05-18 13:26:23 +0200 |
| commit | 3c132447af478e6ff3fd6552383c2f3d9f13fd95 (patch) | |
| tree | 5b178aea7622b04323e343fc79158ea31b2d2f8a /src | |
| parent | 915f1e944f5cca8f64893a0017e2606f157917c7 (diff) | |
| download | rabbitmq-server-git-3c132447af478e6ff3fd6552383c2f3d9f13fd95.tar.gz | |
Add rabbit_tracer boot step for running Looking Glass
It will run only if RABBITMQ_TRACER is defined. It contain a
list of M:F (for example RABBITMQ_TRACER="abc:def,ghi:jkl")
that are functions returning Looking Glass trace specifications.
This commit comes with one such function, rabbit_tracer:connections.
It will trace all existing and future connection processes across
all rabbit and rabbit_common applications.
More functions will need to be added to trace specific parts of
RabbitMQ, or to trace plugins. For example there could be functions
for tracing channels, or data collection for management. Trace
specifications can be combined to get the target you need.
Diffstat (limited to 'src')
| -rw-r--r-- | src/rabbit.erl | 5 | ||||
| -rw-r--r-- | src/rabbit_tracer.erl | 40 |
2 files changed, 45 insertions, 0 deletions
diff --git a/src/rabbit.erl b/src/rabbit.erl index 5ae58f57d1..3bc669d9f6 100644 --- a/src/rabbit.erl +++ b/src/rabbit.erl @@ -219,6 +219,11 @@ [rabbit_core_metrics_gc]}}, {enables, networking}]}). +-rabbit_boot_step({rabbit_tracer, + [{description, "Looking Glass tracer and profiler"}, + {mfa, {rabbit_tracer, boot, []}}, + {requires, networking}]}). + %%--------------------------------------------------------------------------- -include("rabbit_framing.hrl"). diff --git a/src/rabbit_tracer.erl b/src/rabbit_tracer.erl new file mode 100644 index 0000000000..70323dd039 --- /dev/null +++ b/src/rabbit_tracer.erl @@ -0,0 +1,40 @@ +%% 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_tracer). + +-export([boot/0]). +-export([connections/0]). + +boot() -> + case os:getenv("RABBITMQ_TRACER") of + false -> + ok; + Value -> + Input = parse_value(Value), + {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}]. |
