summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdam Kocoloski <kocolosk@apache.org>2009-05-29 05:31:09 +0000
committerAdam Kocoloski <kocolosk@apache.org>2009-05-29 05:31:09 +0000
commitc1ca0dd42524fb6999e1f05de94ccff71bc497b6 (patch)
treedee9b4bf9bc9a1daf62b86eb821413e9dd4d0468 /src
parent2db9c94b3e85efec9e48abc3b2cfb5f4160873bd (diff)
make sure process is still alive before calculating memory footprint
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@779846 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r--src/couchdb/couch_rep.erl22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/couchdb/couch_rep.erl b/src/couchdb/couch_rep.erl
index a7bdd555..1fa03250 100644
--- a/src/couchdb/couch_rep.erl
+++ b/src/couchdb/couch_rep.erl
@@ -808,16 +808,20 @@ should_flush(_DocCount) ->
%% @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.