diff options
author | Robert Newson <rnewson@apache.org> | 2022-05-13 08:39:00 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-13 08:39:00 +0100 |
commit | 8b98e591c031b69cff33161ed7acefa0c58c9edb (patch) | |
tree | 1d9ef4d2b6421fde4226ca05c2676799567c0d5b | |
parent | 3cf88d638c8ad4c90435bf4d637d930e32ff0fdd (diff) | |
parent | 6a0d58880c5d856c1a49010eb88e09e533edbbc5 (diff) | |
download | couchdb-8b98e591c031b69cff33161ed7acefa0c58c9edb.tar.gz |
Merge pull request #3984 from noahshaw11/implement-memory_info-functions
Implement memory_info functions
-rw-r--r-- | src/couch/src/couch_debug.erl | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/couch/src/couch_debug.erl b/src/couch/src/couch_debug.erl index d3f00e60f..e2ee7f0d1 100644 --- a/src/couch/src/couch_debug.erl +++ b/src/couch/src/couch_debug.erl @@ -32,6 +32,8 @@ fold_tree/3, linked_processes_info/2, print_linked_processes/1, + memory_info/1, + memory_info/2, busy/2, busy/3, restart/1, @@ -70,6 +72,7 @@ help() -> fold, linked_processes_info, print_linked_processes, + memory_info, print_table, restart, restart_busy @@ -280,6 +283,23 @@ couch_index_server[<0.288.0>] | 478240 | 0 | --- ", []); +help(memory_info) -> + io:format(" + - memory_info(ProcessList) + - memory_info(ProcessList, InfoKeys) + - memory_info(Pid, InfoKeys) + -------------------------------- + + Obtains the values for a set of optional InfoKeys for each process in ProcessList. + - ProcessList: List of processes + - InfoKeys: List of desired keys to obtain values for. The supported keys are + [binary, dictionary, heap_size, links, memory, message_queue_len, monitored_by, + monitors, stack_size, total_heap_size] + - Pid: Initial Pid to start from + + The output is a list containing tuples of the form {Pid, ProcessName, #{InfoKey: InfoVal}} + for each process in ProcessList. + ", []); help(print_table) -> io:format(" print_table(Rows, TableSpec) @@ -535,6 +555,54 @@ print_linked_processes(Pid) when is_pid(Pid) -> Tree = linked_processes_info(Pid, Info), print_tree(Tree, TableSpec). +memory_info(ProcessList) -> + InfoKeys = [ + binary, + dictionary, + heap_size, + links, + memory, + message_queue_len, + monitored_by, + monitors, + stack_size, + total_heap_size + ], + memory_info(ProcessList, InfoKeys). + +memory_info(ProcessList, InfoKeys) when is_list(ProcessList) -> + lists:map( + fun(Process) -> + memory_info(Process, InfoKeys) + end, + ProcessList + ); +memory_info(Pid, InfoKeys) -> + case process_info(Pid, InfoKeys) of + undefined -> + {Pid, undefined, undefined}; + Values -> + DataMap = maps:from_list( + lists:map( + fun({K, _} = I) -> + {K, info_size(I)} + end, + Values + ) + ), + {Pid, process_name(Pid), DataMap} + end. + +info_size(InfoKV) -> + case InfoKV of + {monitors, L} -> length(L); + {monitored_by, L} -> length(L); + {links, L} -> length(L); + {dictionary, L} -> length(L); + {binary, BinInfos} -> lists:sum([S || {_, S, _} <- BinInfos]); + {_, V} -> V + end. + id("couch_file:init" ++ _, Pid, _Props) -> case couch_file:process_info(Pid) of {{file_descriptor, prim_file, {Port, Fd}}, FilePath} -> |