From c1ca0dd42524fb6999e1f05de94ccff71bc497b6 Mon Sep 17 00:00:00 2001 From: Adam Kocoloski Date: Fri, 29 May 2009 05:31:09 +0000 Subject: 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 --- src/couchdb/couch_rep.erl | 22 +++++++++++++--------- 1 file 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. -- cgit v1.2.3