couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From beno...@apache.org
Subject [38/50] lager commit: updated refs/heads/import-master to da4419e
Date Thu, 13 Feb 2014 16:43:40 GMT
Don't use the proplists module when decoding error_logger messages

Proplist module is a lot slower than lists:keyfind, which is a BIF,
because proplists has to work with 'bare' atoms as well as 2-tuples.

This should marginally improve the throughput when printing many
error_logger messages.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-lager/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-lager/commit/32ea9286
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-lager/tree/32ea9286
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-lager/diff/32ea9286

Branch: refs/heads/import-master
Commit: 32ea9286944210fd78d8764be12243eb0ce96c0c
Parents: 73a1207
Author: Andrew Thompson <andrew@hijacked.us>
Authored: Mon Feb 3 13:32:31 2014 -0500
Committer: Andrew Thompson <andrew@hijacked.us>
Committed: Mon Feb 3 13:32:31 2014 -0500

----------------------------------------------------------------------
 src/error_logger_lager_h.erl | 30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-lager/blob/32ea9286/src/error_logger_lager_h.erl
----------------------------------------------------------------------
diff --git a/src/error_logger_lager_h.erl b/src/error_logger_lager_h.erl
index 1c7e092..3874f31 100644
--- a/src/error_logger_lager_h.erl
+++ b/src/error_logger_lager_h.erl
@@ -235,8 +235,8 @@ log_event(Event, State) ->
                     ?LOGFMT(info, P, "Application ~w started on node ~w",
                         [App, Node]);
                 [{started, Started}, {supervisor, Name}] ->
-                    MFA = format_mfa(proplists:get_value(mfargs, Started)),
-                    Pid = proplists:get_value(pid, Started),
+                    MFA = format_mfa(get_value(mfargs, Started)),
+                    Pid = get_value(pid, Started),
                     ?LOGFMT(debug, P, "Supervisor ~w started ~s at pid ~w",
                         [supervisor_name(Name), MFA, Pid]);
                 _ ->
@@ -248,13 +248,13 @@ log_event(Event, State) ->
     {ok, State}.
 
 format_crash_report(Report, Neighbours) ->
-    Name = case proplists:get_value(registered_name, Report, []) of
+    Name = case get_value(registered_name, Report, []) of
         [] ->
             %% process_info(Pid, registered_name) returns [] for unregistered processes
-            proplists:get_value(pid, Report);
+            get_value(pid, Report);
         Atom -> Atom
     end,
-    {Class, Reason, Trace} = proplists:get_value(error_info, Report),
+    {Class, Reason, Trace} = get_value(error_info, Report),
     ReasonStr = format_reason({Reason, Trace}),
     Type = case Class of
         exit -> "exited";
@@ -264,17 +264,17 @@ format_crash_report(Report, Neighbours) ->
         [Name, length(Neighbours), Type, ReasonStr]).
 
 format_offender(Off) ->
-    case proplists:get_value(mfargs, Off) of
+    case get_value(mfargs, Off) of
         undefined ->
             %% supervisor_bridge
             io_lib:format("at module ~w at ~w",
-                [proplists:get_value(mod, Off), proplists:get_value(pid, Off)]);
+                [get_value(mod, Off), get_value(pid, Off)]);
         MFArgs ->
             %% regular supervisor
             MFA = format_mfa(MFArgs),
-            Name = proplists:get_value(name, Off),
+            Name = get_value(name, Off),
             io_lib:format("~p started with ~s at ~w",
-                [Name, MFA, proplists:get_value(pid, Off)])
+                [Name, MFA, get_value(pid, Off)])
     end.
 
 format_reason({'function not exported', [{M, F, A},MFA|_]}) ->
@@ -361,7 +361,7 @@ format_mfa({M, F, A}) when is_list(A) ->
 format_mfa({M, F, A}) when is_integer(A) ->
     io_lib:format("~w:~w/~w", [M, F, A]);
 format_mfa({M, F, A, Props}) when is_list(Props) ->
-    case proplists:get_value(line, Props) of
+    case get_value(line, Props) of
         undefined ->
             format_mfa({M, F, A});
         Line ->
@@ -405,6 +405,16 @@ print_val(Val) ->
     {Str, _} = lager_trunc_io:print(Val, 500),
     Str.
 
+
+get_value(Key, Value) ->
+    get_value(Key, Value, undefined).
+
+get_value(Key, List, Default) ->
+    case lists:keyfind(Key, 1, List) of
+        false -> Default;
+        {Key, Value} -> Value
+    end.
+
 supervisor_name({local, Name}) -> Name;
 supervisor_name(Name) -> Name.
 -ifdef(TEST).


Mime
View raw message