diff options
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}]. |
