|
| 1 | +%% The contents of this file are subject to the Mozilla Public License |
| 2 | +%% Version 1.1 (the "License"); you may not use this file except in |
| 3 | +%% compliance with the License. You may obtain a copy of the License |
| 4 | +%% at http://www.mozilla.org/MPL/ |
| 5 | +%% |
| 6 | +%% Software distributed under the License is distributed on an "AS IS" |
| 7 | +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See |
| 8 | +%% the License for the specific language governing rights and |
| 9 | +%% limitations under the License. |
| 10 | +%% |
| 11 | +%% The Original Code is RabbitMQ. |
| 12 | +%% |
| 13 | +%% The Initial Developer of the Original Code is GoPivotal, Inc. |
| 14 | +%% Copyright (c) 2007-2017 Pivotal Software, Inc. All rights reserved. |
| 15 | +%% |
| 16 | + |
| 17 | +-module(rabbit_looking_glass). |
| 18 | + |
| 19 | +-ignore_xref([{lg, trace, 4}]). |
| 20 | +-ignore_xref([{maps, from_list, 1}]). |
| 21 | + |
| 22 | +-export([boot/0]). |
| 23 | +-export([connections/0]). |
| 24 | + |
| 25 | +boot() -> |
| 26 | + case os:getenv("RABBITMQ_TRACER") of |
| 27 | + false -> |
| 28 | + ok; |
| 29 | + Value -> |
| 30 | + Input = parse_value(Value), |
| 31 | + rabbit_log:info( |
| 32 | + "Enabling Looking Glass profiler, input value: ~p", |
| 33 | + [Input] |
| 34 | + ), |
| 35 | + {ok, _} = application:ensure_all_started(looking_glass), |
| 36 | + lg:trace( |
| 37 | + Input, |
| 38 | + lg_file_tracer, |
| 39 | + "traces.lz4", |
| 40 | + maps:from_list([ |
| 41 | + {mode, profile}, |
| 42 | + {running, true}, |
| 43 | + {send, true}] |
| 44 | + ) |
| 45 | + ) |
| 46 | + end. |
| 47 | + |
| 48 | +parse_value(Value) -> |
| 49 | + [begin |
| 50 | + [Mod, Fun] = string:tokens(C, ":"), |
| 51 | + {callback, list_to_atom(Mod), list_to_atom(Fun)} |
| 52 | + end || C <- string:tokens(Value, ",")]. |
| 53 | + |
| 54 | +connections() -> |
| 55 | + Pids = [Pid || {{conns_sup, _}, Pid} <- ets:tab2list(ranch_server)], |
| 56 | + [{app, rabbit}, {app, rabbit_common}, {scope, Pids}]. |
0 commit comments