This is an automated email from the ASF dual-hosted git repository.

jiahuili430 pushed a commit to branch improve-couch-debug
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit aac7a9aef247e6693973179c328f0545c3173938
Author: Jiahui Li <[email protected]>
AuthorDate: Wed May 14 14:33:08 2025 -0500

    Improve `couch_debug.erl`
    
    - Use `module_info(exports)` instead of hardcoding.
    - Export `print_tree/2` as it's already documented in `couch_debug:help/1` 
function.
    - Add a new line after each resource hoggers snapshot table for better 
viewing.
    - Add `couch_debug:ping_live_cluster_nodes/0`, and 
`ping_live_cluster_nodes/1`.
---
 src/couch/src/couch_debug.erl                      | 65 ++++++++++------------
 .../src/{couch_debug.erl => couch_debug.erl.orig}  |  9 ++-
 2 files changed, 36 insertions(+), 38 deletions(-)

diff --git a/src/couch/src/couch_debug.erl b/src/couch/src/couch_debug.erl
index 9889a50a8..0c05ebd6a 100644
--- a/src/couch/src/couch_debug.erl
+++ b/src/couch/src/couch_debug.erl
@@ -48,7 +48,8 @@
     dead_nodes/1,
     ping/1,
     ping/2,
-    ping_nodes/0,
+    ping_live_cluster_nodes/0,
+    ping_live_cluster_nodes/1,
     ping_nodes/1,
     ping_nodes/2,
     node_events/0
@@ -57,9 +58,12 @@
 -export([
     print_table/2,
     print_report/1,
-    print_report_with_info_width/2
+    print_report_with_info_width/2,
+    print_tree/2
 ]).
 
+-define(PING_TIMEOUT_IN_MS, 60000).
+
 -type throw(_Reason) :: no_return().
 
 -type process_name() :: atom().
@@ -75,34 +79,7 @@
 -spec help() -> [function_name()].
 
 help() ->
-    [
-        busy,
-        opened_files,
-        opened_files_by_regexp,
-        opened_files_contains,
-        process_name,
-        get_pid,
-        link_tree,
-        mapfold_tree,
-        fold_tree,
-        map_tree,
-        linked_processes_info,
-        print_linked_processes,
-        memory_info,
-        resource_hoggers,
-        resource_hoggers_snapshot,
-        analyze_resource_hoggers,
-        print_table,
-        print_report,
-        print_report_with_info_width,
-        print_tree,
-        restart,
-        restart_busy,
-        dead_nodes,
-        ping,
-        ping_nodes,
-        node_events
-    ].
+    lists:uniq([F || {F, _A} <- couch_debug:module_info(exports)]) -- [help, 
module_info].
 
 -spec help(Function :: function_name()) -> ok.
 %% erlfmt-ignore
@@ -472,18 +449,27 @@ help(ping) ->
 
         Ping a node and return either a time in microseconds or an error term.
 
+        ---
+    ", []);
+help(ping_live_cluster_nodes) ->
+    io:format("
+        ping_live_cluster_nodes()
+        ping_live_cluster_nodes(Timeout)
+        --------------------------------
+
+        Ping the currently connected cluster nodes. Returns a list of
+        {Node, Result} tuples or an empty list.
+
         ---
     ", []);
 help(ping_nodes) ->
     io:format("
-        ping_nodes()
-        ping_nodes(Timeout)
+        ping_nodes(Nodes)
         ping_nodes(Nodes, Timeout)
         --------------------------------
 
-        Ping the list of currently connected nodes. Return a list of {Node,
-        Result} tuples where Result is either a time in microseconds or an
-        error term.
+        Ping the list of nodes. Return a list of {Node, Result} tuples where
+        Result is either a time in microseconds or an error term.
 
         ---
     ", []);
@@ -773,6 +759,7 @@ info_size(InfoKV) ->
         {binary, BinInfos} -> lists:sum([S || {_, S, _} <- BinInfos]);
         {_, V} -> V
     end.
+
 resource_hoggers(MemoryInfo, InfoKey) ->
     KeyFun = fun
         ({_Pid, _Id, undefined}) -> undefined;
@@ -981,12 +968,15 @@ ping(Node) ->
 ping(Node, Timeout) ->
     mem3:ping(Node, Timeout).
 
-ping_nodes() ->
+ping_live_cluster_nodes() ->
     mem3:ping_nodes().
 
-ping_nodes(Timeout) ->
+ping_live_cluster_nodes(Timeout) ->
     mem3:ping_nodes(Timeout).
 
+ping_nodes(Nodes) ->
+    mem3:ping_nodes(Nodes, ?PING_TIMEOUT_IN_MS).
+
 ping_nodes(Nodes, Timeout) ->
     mem3:ping_nodes(Nodes, Timeout).
 
@@ -1012,6 +1002,7 @@ print_table(Rows, TableSpec) ->
         end,
         Rows
     ),
+    io:format("~n", []),
     ok.
 
 print_report(Report) ->
diff --git a/src/couch/src/couch_debug.erl b/src/couch/src/couch_debug.erl.orig
similarity index 99%
copy from src/couch/src/couch_debug.erl
copy to src/couch/src/couch_debug.erl.orig
index 9889a50a8..cf65c376f 100644
--- a/src/couch/src/couch_debug.erl
+++ b/src/couch/src/couch_debug.erl.orig
@@ -57,7 +57,8 @@
 -export([
     print_table/2,
     print_report/1,
-    print_report_with_info_width/2
+    print_report_with_info_width/2,
+    print_tree/2
 ]).
 
 -type throw(_Reason) :: no_return().
@@ -75,6 +76,7 @@
 -spec help() -> [function_name()].
 
 help() ->
+<<<<<<< HEAD
     [
         busy,
         opened_files,
@@ -103,6 +105,9 @@ help() ->
         ping_nodes,
         node_events
     ].
+=======
+    lists:uniq([F || {F, _A} <- couch_debug:module_info(exports)]).
+>>>>>>> c5c9cee74 (Use `module_info(exports)` instead of hardcoding)
 
 -spec help(Function :: function_name()) -> ok.
 %% erlfmt-ignore
@@ -773,6 +778,7 @@ info_size(InfoKV) ->
         {binary, BinInfos} -> lists:sum([S || {_, S, _} <- BinInfos]);
         {_, V} -> V
     end.
+
 resource_hoggers(MemoryInfo, InfoKey) ->
     KeyFun = fun
         ({_Pid, _Id, undefined}) -> undefined;
@@ -1012,6 +1018,7 @@ print_table(Rows, TableSpec) ->
         end,
         Rows
     ),
+    io:format("~n", []),
     ok.
 
 print_report(Report) ->

Reply via email to