You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ii...@apache.org on 2022/05/16 18:51:01 UTC
[couchdb] branch 3.x updated: Fix busy functions to work with pids
This is an automated email from the ASF dual-hosted git repository.
iilyak pushed a commit to branch 3.x
in repository https://gitbox.apache.org/repos/asf/couchdb.git
The following commit(s) were added to refs/heads/3.x by this push:
new e814407e6 Fix busy functions to work with pids
new 3894fb397 Merge pull request #3987 from noahshaw11/fix-busy-functions-to-work-with-pids
e814407e6 is described below
commit e814407e67a58307daf407e82541e0909c8e36c3
Author: ncshaw <nc...@ibm.com>
AuthorDate: Wed Apr 6 15:28:14 2022 -0500
Fix busy functions to work with pids
---
src/couch/src/couch_debug.erl | 32 +++++++++++++++++++++++++-------
1 file changed, 25 insertions(+), 7 deletions(-)
diff --git a/src/couch/src/couch_debug.erl b/src/couch/src/couch_debug.erl
index e2ee7f0d1..32549b922 100644
--- a/src/couch/src/couch_debug.erl
+++ b/src/couch/src/couch_debug.erl
@@ -25,6 +25,7 @@
-export([
process_name/1,
+ get_pid/1,
link_tree/1,
link_tree/2,
mapfold_tree/3,
@@ -49,6 +50,7 @@
-type throw(_Reason) :: no_return().
-type process_name() :: atom().
+-type process() :: process_name() | pid().
-type function_name() :: atom().
-type busy_properties() ::
heap_size
@@ -66,6 +68,7 @@ help() ->
opened_files_by_regexp,
opened_files_contains,
process_name,
+ get_pid,
link_tree,
mapfold,
map,
@@ -86,7 +89,7 @@ help(busy) ->
busy(ProcessList, Threshold, Property)
--------------
- Iterate over given list of named processes and returns the ones with
+ Iterate over given list of named processes or pids and returns the ones with
a Property value greater than provided Threshold.
If Property is not specified we use message box size
@@ -142,6 +145,16 @@ help(process_name) ->
- '$initial_call' key in process dictionary
- process_info(Pid, initial_call)
+ ---
+ ", []);
+help(get_pid) ->
+ io:format("
+ get_pid(PidOrName)
+ -----------------
+
+ Get the pid for a process name given either a name or pid. When a pid is given, it returns it as is.
+ This has the same functionality as whereis/1 except it will not crash when a pid is given.
+
---
", []);
help(restart) ->
@@ -330,21 +343,21 @@ help(Unknown) ->
io:format(" ---~n", []),
ok.
--spec busy(ProcessList :: [process_name()], Threshold :: pos_integer()) ->
+-spec busy(ProcessList :: [process()], Threshold :: pos_integer()) ->
[Name :: process_name()].
busy(ProcessList, Threshold) when Threshold > 0 ->
busy(ProcessList, Threshold, message_queue_len).
-spec busy(
- ProcessList :: [process_name()], Threshold :: pos_integer(), Property :: busy_properties()
+ [process()], Threshold :: pos_integer(), Property :: busy_properties()
) ->
[Name :: process_name()].
busy(ProcessList, Threshold, Property) when Threshold > 0 ->
lists:filter(
- fun(Name) ->
- case (catch process_info(whereis(Name), Property)) of
+ fun(Process) ->
+ case (catch process_info(get_pid(Process), Property)) of
{Property, Value} when is_integer(Value) andalso Value > Threshold ->
true;
_ ->
@@ -409,6 +422,11 @@ process_name(Pid) when is_pid(Pid) ->
process_name(Else) ->
iolist_to_list(io_lib:format("~p", [Else])).
+get_pid(Process) when is_pid(Process) ->
+ Process;
+get_pid(Process) ->
+ whereis(Process).
+
iolist_to_list(List) ->
binary_to_list(iolist_to_binary(List)).
@@ -671,7 +689,7 @@ restart_busy(ProcessList, Threshold) ->
restart_busy(ProcessList, Threshold, 1000).
-spec restart_busy(
- ProcessList :: [process_name()], Thershold :: pos_integer(), DelayInMsec :: pos_integer()
+ ProcessList :: [process_name()], Threshold :: pos_integer(), DelayInMsec :: pos_integer()
) ->
throw({timeout, Name :: process_name()}) | ok.
@@ -680,7 +698,7 @@ restart_busy(ProcessList, Threshold, DelayInMsec) ->
-spec restart_busy(
ProcessList :: [process_name()],
- Thershold :: pos_integer(),
+ Threshold :: pos_integer(),
DelayInMsec :: pos_integer(),
Property :: busy_properties()
) ->