couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kocol...@apache.org
Subject svn commit: r779846 - /couchdb/trunk/src/couchdb/couch_rep.erl
Date Fri, 29 May 2009 05:31:01 GMT
Author: kocolosk
Date: Fri May 29 05:31:01 2009
New Revision: 779846

URL: http://svn.apache.org/viewvc?rev=779846&view=rev
Log:
make sure process is still alive before calculating memory footprint

Modified:
    couchdb/trunk/src/couchdb/couch_rep.erl

Modified: couchdb/trunk/src/couchdb/couch_rep.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_rep.erl?rev=779846&r1=779845&r2=779846&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_rep.erl (original)
+++ couchdb/trunk/src/couchdb/couch_rep.erl Fri May 29 05:31:01 2009
@@ -808,16 +808,20 @@
 %% @spec memory_footprint([pid()]) -> integer()
 %% @doc Sum of process and binary memory utilization for all processes in list
 memory_footprint(PidList) ->
-    ProcessMemory = lists:foldl(fun(Pid, Acc) ->
-        Acc + element(2,process_info(Pid, memory))
-    end, 0, PidList),
-    
-    BinaryMemory = lists:foldl(fun(Pid, Acc) ->
-        Acc + binary_memory(Pid)
-    end, 0, PidList),
-    
+    memory_footprint(PidList, {0,0}).
+
+memory_footprint([], {ProcessMemory, BinaryMemory}) ->
     ?LOG_DEBUG("ProcessMem ~p BinaryMem ~p", [ProcessMemory, BinaryMemory]),
-    ProcessMemory + BinaryMemory.
+    ProcessMemory + BinaryMemory;
+memory_footprint([Pid|Rest], {ProcAcc, BinAcc}) ->
+    case is_process_alive(Pid) of
+    true ->
+        ProcMem = element(2,process_info(Pid, memory)),
+        BinMem = binary_memory(Pid),
+        memory_footprint(Rest, {ProcMem + ProcAcc, BinMem + BinAcc});
+    false ->
+        memory_footprint(Rest, {ProcAcc, BinAcc})
+    end.
 
 %% @spec binary_memory(pid()) -> integer()
 %% @doc Memory utilization of all binaries referenced by this process.



Mime
View raw message