Skip to content

Commit 2a57ce4

Browse files
authored
Merge pull request #1384 from rabbitmq/integrate-looking_glass
Integrate `looking_glass`
2 parents 3f96e9b + 0f98949 commit 2a57ce4

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

src/rabbit.erl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,11 @@
200200
[rabbit_core_metrics_gc]}},
201201
{enables, networking}]}).
202202

203+
-rabbit_boot_step({rabbit_looking_glass,
204+
[{description, "Looking Glass tracer and profiler"},
205+
{mfa, {rabbit_looking_glass, boot, []}},
206+
{requires, networking}]}).
207+
203208
%%---------------------------------------------------------------------------
204209

205210
-include("rabbit_framing.hrl").

src/rabbit_looking_glass.erl

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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

Comments
 (0)