summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorILYA Khlopotov <iilyak@apache.org>2022-02-18 04:11:17 -0800
committerILYA Khlopotov <iilyak@apache.org>2022-02-22 11:13:15 -0800
commitd5a964abb543ae05083be1fc97cd1c49f4469636 (patch)
treedf8bd229d2845518058d894246fcd24f09f0d977
parentdfab067b2cb1e1e5223d6bb8229ed814b71f5c44 (diff)
downloadcouchdb-d5a964abb543ae05083be1fc97cd1c49f4469636.tar.gz
Fix couch_debug:print_linked_processes/1 to work with sharded couch_index_server
-rw-r--r--src/couch/src/couch_debug.erl47
-rw-r--r--src/couch_index/src/couch_index_server.erl6
2 files changed, 44 insertions, 9 deletions
diff --git a/src/couch/src/couch_debug.erl b/src/couch/src/couch_debug.erl
index a2f4cdc87..767822463 100644
--- a/src/couch/src/couch_debug.erl
+++ b/src/couch/src/couch_debug.erl
@@ -421,6 +421,15 @@ id(_IdStr, _Pid, _Props) ->
print_couch_index_server_processes() ->
Info = [reductions, message_queue_len, memory],
+ Trees = lists:map(
+ fun(Name) ->
+ link_tree(whereis(Name), Info, fun(P, Props) ->
+ IdStr = process_name(P),
+ {IdStr, [{id, id(IdStr, P, Props)} | Props]}
+ end)
+ end,
+ couch_index_server:names()
+ ),
TableSpec = [
{50, left, name},
{12, centre, reductions},
@@ -428,12 +437,7 @@ print_couch_index_server_processes() ->
{14, centre, memory},
{id}
],
-
- Tree = link_tree(whereis(couch_index_server), Info, fun(P, Props) ->
- IdStr = process_name(P),
- {IdStr, [{id, id(IdStr, P, Props)} | Props]}
- end),
- print_tree(Tree, TableSpec).
+ print_trees(Trees, TableSpec).
shorten_path(Path) ->
ViewDir = list_to_binary(config:get("couchdb", "view_index_dir")),
@@ -464,9 +468,36 @@ print_tree(Tree, TableSpec) ->
end),
ok.
+print_trees(Trees, TableSpec) ->
+ io:format("~s~n", [format(TableSpec)]),
+ io:format("~s~n", [separator(TableSpec)]),
+ lists:foreach(
+ fun(Tree) ->
+ map_tree(Tree, fun(_, {Id, Props}, Pos) ->
+ io:format("~s~n", [table_row(Id, Pos * 2, Props, TableSpec)])
+ end),
+ io:format("~s~n", [space(TableSpec)])
+ end,
+ Trees
+ ),
+ ok.
+
format(Spec) ->
Fields = [format_value(Format) || Format <- Spec],
- string:join(Fields, "|").
+ [$| | string:join(Fields, "|")].
+
+fill(Spec, [Char]) ->
+ fill(Spec, Char);
+fill(Spec, Char) when is_integer(Char) ->
+ Fields = [format_value(Format) || Format <- Spec],
+ Sizes = [length(F) || F <- Fields],
+ [$| | [string:join([string:chars(Char, F) || F <- Sizes], "|")]].
+
+space(Spec) ->
+ fill(Spec, " ").
+
+separator(Spec) ->
+ fill(Spec, "-").
format_value({Value}) -> term2str(Value);
format_value({Width, Align, Value}) -> string:Align(term2str(Value), Width).
@@ -486,7 +517,7 @@ term2str(Term) -> iolist_to_list(io_lib:format("~p", [Term])).
table_row(Key, Indent, Props, [{KeyWidth, Align, _} | Spec]) ->
Values = [bind_value(Format, Props) || Format <- Spec],
KeyStr = string:Align(term2str(Key), KeyWidth - Indent),
- [string:copies(" ", Indent), KeyStr, "|" | format(Values)].
+ [$|, string:copies(" ", Indent), KeyStr | format(Values)].
-ifdef(TEST).
-include_lib("couch/include/couch_eunit.hrl").
diff --git a/src/couch_index/src/couch_index_server.erl b/src/couch_index/src/couch_index_server.erl
index a72ec3b88..2e368bfc2 100644
--- a/src/couch_index/src/couch_index_server.erl
+++ b/src/couch_index/src/couch_index_server.erl
@@ -23,7 +23,7 @@
% Sharding functions
-export([num_servers/0, server_name/1, by_sig/1, by_pid/1, by_db/1]).
--export([aggregate_queue_len/0]).
+-export([aggregate_queue_len/0, names/0]).
% Exported for callbacks
-export([
@@ -382,6 +382,10 @@ name(BaseName, Arg) when is_binary(Arg) ->
name(BaseName, N) when is_integer(N), N > 0 ->
list_to_atom(BaseName ++ "_" ++ integer_to_list(N)).
+names() ->
+ N = num_servers(),
+ [server_name(I) || I <- lists:seq(1, N)].
+
aggregate_queue_len() ->
N = num_servers(),
Names = [server_name(I) || I <- lists:seq(1, N)],