From a93d3d23fb1768ff6b1518052ee7cf12cf4c30f2 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Thu, 19 May 2011 19:11:31 +0100 Subject: inlining --- src/rabbit_trace.erl | 57 +++++++++++++++++++++++----------------------------- 1 file changed, 25 insertions(+), 32 deletions(-) diff --git a/src/rabbit_trace.erl b/src/rabbit_trace.erl index 36125376..ab6ef982 100644 --- a/src/rabbit_trace.erl +++ b/src/rabbit_trace.erl @@ -36,7 +36,10 @@ %%---------------------------------------------------------------------------- init(VHost) -> - trace_exchange(VHost). + case application:get_env(rabbit, trace_exchanges) of + undefined -> none; + {ok, Xs} -> proplists:get_value(VHost, Xs, none) + end. tap_trace_in(Msg, TraceX) -> maybe_trace(Msg, TraceX, <<"publish">>, xname(Msg), []). @@ -47,44 +50,39 @@ tap_trace_out({#resource{name = QName}, _QPid, _QMsgId, Redelivered, Msg}, maybe_trace(Msg, TraceX, <<"deliver">>, QName, [{<<"redelivered">>, signedint, RedeliveredNum}]). -xname(#basic_message{exchange_name = #resource{name = XName}}) -> XName. -vhost(#basic_message{exchange_name = #resource{virtual_host = VHost}}) -> VHost. - maybe_trace(_Msg, none, _RKPrefix, _RKSuffix, _Extra) -> ok; -maybe_trace(Msg0, TraceX, RKPrefix, RKSuffix, Extra) -> - case xname(Msg0) of +maybe_trace(Msg, TraceX, RKPrefix, RKSuffix, Extra) -> + case xname(Msg) of TraceX -> ok; - _ -> Msg = ensure_content_decoded(Msg0), - X = rabbit_misc:r(vhost(Msg), exchange, TraceX), - RKey = <>, - P = #'P_basic'{headers = msg_to_table(Msg) ++ Extra}, - case catch rabbit_basic:publish(X, RKey, P, payload(Msg)) of + _ -> case catch rabbit_basic:publish( + rabbit_misc:r(vhost(Msg), exchange, TraceX), + <>, + #'P_basic'{headers = msg_to_table(Msg) ++ Extra}, + payload(Msg)) of {'EXIT', R} -> rabbit_log:info( "Trace publish died: ~p~n", [R]); {ok, _, _} -> ok end end. -trace_exchange(VHost) -> - case application:get_env(rabbit, trace_exchanges) of - undefined -> none; - {ok, Xs} -> proplists:get_value(VHost, Xs, none) - end. +xname(#basic_message{exchange_name = #resource{name = XName}}) -> XName. +vhost(#basic_message{exchange_name = #resource{virtual_host = VHost}}) -> VHost. msg_to_table(#basic_message{exchange_name = #resource{name = XName}, routing_keys = RoutingKeys, - content = #content{properties = Props}}) -> + content = Content}) -> + #content{properties = Props} = + rabbit_binary_parser:ensure_content_decoded(Content), {PropsTable, _Ix} = - lists:foldl( - fun (K, {L, Ix}) -> - V = element(Ix, Props), - NewL = case V of - undefined -> L; - _ -> [{a2b(K), type(V), V} | L] - end, - {NewL, Ix + 1} - end, {[], 2}, record_info(fields, 'P_basic')), + lists:foldl(fun (K, {L, Ix}) -> + V = element(Ix, Props), + NewL = case V of + undefined -> L; + _ -> [{a2b(K), type(V), V} | L] + end, + {NewL, Ix + 1} + end, {[], 2}, record_info(fields, 'P_basic')), [{<<"exchange_name">>, longstr, XName}, {<<"routing_keys">>, array, [{longstr, K} || K <- RoutingKeys]}, {<<"properties">>, table, PropsTable}, @@ -93,12 +91,7 @@ msg_to_table(#basic_message{exchange_name = #resource{name = XName}, payload(#basic_message{content = #content{payload_fragments_rev = PFR}}) -> list_to_binary(lists:reverse(PFR)). -ensure_content_decoded(Msg = #basic_message{content = Content}) -> - Msg#basic_message{content = rabbit_binary_parser:ensure_content_decoded( - Content)}. - -a2b(A) -> - list_to_binary(atom_to_list(A)). +a2b(A) -> list_to_binary(atom_to_list(A)). type(V) when is_list(V) -> table; type(V) when is_integer(V) -> signedint; -- cgit v1.2.1