summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Wallace <mikewallace1979@googlemail.com>2014-07-29 12:13:51 +0100
committerJay Doane <jaydoane@apache.org>2021-04-19 00:34:24 -0700
commitdd57fe1bd0eebf1abaf7793532ed26d3c1114243 (patch)
treef1a6db9159f0ec208e75d8a15ace1dc9600f153f
parentecde7fcf8e13a5b54f321660643aec59c3aa140d (diff)
downloadcouchdb-dd57fe1bd0eebf1abaf7793532ed26d3c1114243.tar.gz
Add check for processes by first/current call
Add a diagnostic check for the number of processes in sharing first and current function calls. This is useful from a diagnostic point of view because it gives an idea of the work being carried out on the node. BugzID: 32911
-rw-r--r--src/weatherreport/src/weatherreport_check_process_calls.erl99
1 files changed, 99 insertions, 0 deletions
diff --git a/src/weatherreport/src/weatherreport_check_process_calls.erl b/src/weatherreport/src/weatherreport_check_process_calls.erl
new file mode 100644
index 000000000..cb1747df9
--- /dev/null
+++ b/src/weatherreport/src/weatherreport_check_process_calls.erl
@@ -0,0 +1,99 @@
+%% -------------------------------------------------------------------
+%%
+%% weatherreport - automated diagnostic tools for CouchDB
+%%
+%% Copyright (c) 2014 Cloudant
+%%
+%% This file is provided to you under the Apache License,
+%% Version 2.0 (the "License"); you may not use this file
+%% except in compliance with the License. You may obtain
+%% a copy of the License at
+%%
+%% http://www.apache.org/licenses/LICENSE-2.0
+%%
+%% Unless required by applicable law or agreed to in writing,
+%% software distributed under the License is distributed on an
+%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+%% KIND, either express or implied. See the License for the
+%% specific language governing permissions and limitations
+%% under the License.
+%%
+%% -------------------------------------------------------------------
+
+%% @doc Diagnostic that checks for large numbers of processes sharing
+%% the same current or initial function call
+-module(weatherreport_check_process_calls).
+-behaviour(weatherreport_check).
+
+-export([description/0,
+ valid/0,
+ check/0,
+ format/1]).
+
+-define(THRESHOLD, 1000).
+
+-spec description() -> string().
+description() ->
+ "Check for large numbers of processes with the same current/initial call".
+
+-spec valid() -> boolean().
+valid() ->
+ weatherreport_node:can_connect().
+
+fold_processes([], Acc, _Lim, _) ->
+ Acc;
+fold_processes(_, Acc, 0, _) ->
+ Acc;
+fold_processes([{Count, {M, F, A}} | T], Acc, Lim, CallType) ->
+ Level = case Count > ?THRESHOLD of
+ true ->
+ warning;
+ _ ->
+ info
+ end,
+ case application:get_env(weatherreport, expert_mode) of
+ {ok, true} ->
+ PidFun = list_to_atom("find_by_" ++ CallType ++ "_call"),
+ Pids = weatherreport_node:local_command(recon, PidFun, [M, F]),
+ lists:map(fun(Pid) ->
+ Pinfo = weatherreport_node:local_command(recon, info, [Pid]),
+ weatherreport_util:log(
+ Level,
+ "Process info for ~w:~n~p",
+ [Pid, Pinfo]
+ )
+ end, lists:sublist(Pids, 10));
+ _ ->
+ ok
+ end,
+ Message = {Level, {process_count, {CallType, Count, M, F, A}}},
+ fold_processes(T, [Message | Acc], Lim - 1, CallType).
+
+-spec check() -> [{atom(), term()}].
+check() ->
+ CurrentCallCounts = weatherreport_node:local_command(
+ recon,
+ show_current_call_counts,
+ []
+ ),
+ CurrentCallMessages = fold_processes(
+ CurrentCallCounts,
+ [],
+ 10,
+ "current"
+ ),
+ FirstCallCounts = weatherreport_node:local_command(
+ recon,
+ show_first_call_counts,
+ []
+ ),
+ lists:reverse(fold_processes(
+ FirstCallCounts,
+ CurrentCallMessages,
+ 10,
+ "first"
+ )).
+
+-spec format(term()) -> {io:format(), [term()]}.
+format({process_count, {CallType, Count, M, F, A}}) ->
+ {"~w processes with ~s call ~w:~w/~w", [Count, CallType, M, F, A]}.