Return-Path: X-Original-To: apmail-couchdb-commits-archive@www.apache.org Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 65935184C9 for ; Thu, 25 Feb 2016 20:03:07 +0000 (UTC) Received: (qmail 16077 invoked by uid 500); 25 Feb 2016 20:03:04 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 15943 invoked by uid 500); 25 Feb 2016 20:03:04 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 15717 invoked by uid 99); 25 Feb 2016 20:03:04 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 25 Feb 2016 20:03:04 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id D6100E8F2A; Thu, 25 Feb 2016 20:03:03 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: chewbranca@apache.org To: commits@couchdb.apache.org Date: Thu, 25 Feb 2016 20:03:05 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [03/12] couch commit: updated refs/heads/2938-fix-5986-filtered-changes to 9171d5a Add couch_debug:opened_files/0 This function is for debugging purposes only. It iterates through all open ports and returns file descriptor and filename correspondent to every port. Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/08e2a04e Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/08e2a04e Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/08e2a04e Branch: refs/heads/2938-fix-5986-filtered-changes Commit: 08e2a04e435c02ab71a041dac671b616551d2753 Parents: f3b7f5a Author: ILYA Khlopotov Authored: Thu Jan 28 13:17:42 2016 -0800 Committer: ILYA Khlopotov Committed: Tue Feb 16 15:51:26 2016 -0800 ---------------------------------------------------------------------- src/couch_debug.erl | 33 +++++++++++++++++++++++++++++++++ src/couch_file.erl | 18 ++++++++++++++++++ 2 files changed, 51 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/08e2a04e/src/couch_debug.erl ---------------------------------------------------------------------- diff --git a/src/couch_debug.erl b/src/couch_debug.erl new file mode 100644 index 0000000..31b4c5c --- /dev/null +++ b/src/couch_debug.erl @@ -0,0 +1,33 @@ +% Licensed 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. + +-module(couch_debug). + +-export([opened_files/0]). + +-spec opened_files() -> + [{port(), CouchFilePid :: pid(), Fd :: pid() | tuple(), FilePath :: string()}]. + +opened_files() -> + Info = [couch_file_port_info(Port) + || Port <- erlang:ports(), + {name, "efile"} =:= erlang:port_info(Port, name)], + [I || I <- Info, is_tuple(I)]. + +couch_file_port_info(Port) -> + {connected, Pid} = erlang:port_info(Port, connected), + case couch_file:process_info(Pid) of + {Fd, FilePath} -> + {Port, Pid, Fd, FilePath}; + undefined -> + undefined + end. http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/08e2a04e/src/couch_file.erl ---------------------------------------------------------------------- diff --git a/src/couch_file.erl b/src/couch_file.erl index e6cd01a..f6c5a4f 100644 --- a/src/couch_file.erl +++ b/src/couch_file.erl @@ -42,6 +42,8 @@ -export([init/1, terminate/2, code_change/3]). -export([handle_call/3, handle_cast/2, handle_info/2]). +%% helper functions +-export([process_info/1]). %%---------------------------------------------------------------------- %% Args: Valid Options are [create] and [create,overwrite]. @@ -299,6 +301,8 @@ init({Filepath, Options, ReturnPid, Ref}) -> filelib:ensure_dir(Filepath), case file:open(Filepath, OpenOptions) of {ok, Fd} -> + %% Save Fd in process dictionary for debugging purposes + put(couch_file_fd, {Fd, Filepath}), {ok, Length} = file:position(Fd, eof), case Length > 0 of true -> @@ -330,6 +334,8 @@ init({Filepath, Options, ReturnPid, Ref}) -> case file:open(Filepath, [read, raw]) of {ok, Fd_Read} -> {ok, Fd} = file:open(Filepath, OpenOptions), + %% Save Fd in process dictionary for debugging purposes + put(couch_file_fd, {Fd, Filepath}), ok = file:close(Fd_Read), maybe_track_open_os_files(Options), {ok, Eof} = file:position(Fd, eof), @@ -592,3 +598,15 @@ is_idle(#file{is_sys=false}) -> {monitored_by, [_]} -> exit(tracker_monitoring_failed); _ -> false end. + +-spec process_info(CouchFilePid :: pid()) -> + {Fd :: pid() | tuple(), FilePath :: string()}. + +process_info(Pid) -> + {dictionary, Dict} = erlang:process_info(Pid, dictionary), + case lists:keyfind(couch_file_fd, 1, Dict) of + false -> + undefined; + {couch_file_fd, {Fd, InitialName}} -> + {Fd, InitialName} + end.