Uploaded image for project: 'Couchbase Server'
  1. Couchbase Server
  2. MB-47995

Sort Erlang processes by reductions

    XMLWordPrintable

Details

    • Improvement
    • Resolution: Won't Fix
    • Minor
    • 7.1.0
    • 7.1.0
    • ns_server
    • None
    • 1

    Description

      Suggest to make a slight change to timeout_diag_logger.erl by adding few more fields and sorting processes in reduction order

      do_diag(Error) ->
          Processes =
              lists:filtermap(
                fun (Pid) ->
                        case catch diag_handler:grab_process_info(Pid) of
                            undefined ->
                                %% Pid gone, skip it
                                false;
                            Info ->
                                {true, {Pid, Info}}
                        end
                end, erlang:processes()),
          ?log_error("Got timeout ~p~nProcesses snapshot is: ~n", [Error]),
          lists:foreach(fun (Item) ->
                                ?log_error("~n~p", [Item])
                        end, Processes).
      
      

      This is a proposal for more process attributes and how we can sort:

      Keys = [registered_name,reductions,memory, message_queue_len, monitored_by, monitors].
      Pids = [ lists:append([{pid, Pid}], erlang:process_info(Pid, Keys)) || Pid <- erlang:processes(), erlang:process_info(Pid, Keys) =/= undefined ].
      SPids = lists:sort(fun(A, B) -> proplists:get_value(reductions, A) > proplists:get_value(reductions, B) end, Pids).
      

      Same should be applied on a similar code in diag_handler.erl:

      grab_process_infos() ->
          grab_process_infos_loop(erlang:processes(), []).
       
      grab_process_infos_loop([], Acc) ->
          Acc;
      grab_process_infos_loop([P | RestPids], Acc) ->
          case catch grab_process_info(P) of
              undefined ->
                  %% Pid gone, skip it.
                  grab_process_infos_loop(RestPids, Acc);
              Info ->
                  NewAcc = [{P, Info} | Acc],
                  grab_process_infos_loop(RestPids, NewAcc)
          end.
      

      In fact, we should probably consolidate and add a common implementation in misc.erl

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            dfinlay Dave Finlay
            meni.hillel Meni Hillel (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes

                PagerDuty