anchor.diff:  
   -define(MIN_LOG_INTERVAL, 5000).
   
  --record(state, {last_tstamp}).
  +-record(state, {last_tstamp,
  +                diag_pid}).
   
   %%%===================================================================
   %%% API
  
positive.code:     ns_couchdb_api:log_diagnostics(Err).
  
  do_log_diagnostics(Err) ->
      Pid = erlang:whereis(?MODULE),
      case Pid of
          undefined -> ok;
          _ ->
              try erlang:process_info(Pid, message_queue_len) of
                  {_, V} when V < 1 -> gen_server:cast(?MODULE, {diag, Err});
                  _ -> nothing
              catch _:_ -> nothing
              end
      end.
  
  %%--------------------------------------------------------------------
  %% @doc
  
negative.code: %% @spec terminate(Reason, State) -> void()
  %% @end
  %%--------------------------------------------------------------------
  terminate(_Reason, #state{diag_pid = DiagPid} = _State) ->
      case DiagPid of
          undefined ->
              ok;
          _ ->
              misc:terminate_and_wait(kill, DiagPid)
      end,
      ok.
  
  %%--------------------------------------------------------------------
  