From patchwork Sat Jan 18 21:33:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 2684 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A18DE607B3 for ; Sat, 18 Jan 2020 22:34:07 +0100 (CET) Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 3DF939A1 for ; Sat, 18 Jan 2020 22:34:07 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1579383247; bh=TiQBI0GaiwpcgqVcUXxfoMW34+niDcTNiXYKy8/iTw0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=WEdLel0AU/2w37T5/hDKmpiEGDs9hcE2FlVLwMYP7RDQ2uZtmfagf55IMUFJhQPiI /iky0QjYHS6Y45ChuhXvp6nT15CaAQOwBk253DYbLYp+bjMlPb9X7PsQWcxiJKZb5Y TimlR/2vwFRn52TQv55DU7X6Wv/G4nGB4LFzxMcQ= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sat, 18 Jan 2020 23:33:47 +0200 Message-Id: <20200118213348.16561-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200118213348.16561-1-laurent.pinchart@ideasonboard.com> References: <20200118213348.16561-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/2] libcamera: thread: Add a method to return the ID of the current thread X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 18 Jan 2020 21:34:08 -0000 The current thread ID is useful when logging message to debug concurrency issues. Add a method to retrieve it. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund Reviewed-by: Kieran Bingham --- src/libcamera/include/thread.h | 2 ++ src/libcamera/thread.cpp | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/libcamera/include/thread.h b/src/libcamera/include/thread.h index 37edd4f5138b..819a9879ac56 100644 --- a/src/libcamera/include/thread.h +++ b/src/libcamera/include/thread.h @@ -9,6 +9,7 @@ #include #include +#include #include #include @@ -39,6 +40,7 @@ public: Signal finished; static Thread *current(); + static pid_t currentId(); EventDispatcher *eventDispatcher(); void setEventDispatcher(std::unique_ptr dispatcher); diff --git a/src/libcamera/thread.cpp b/src/libcamera/thread.cpp index 18ebd16a7e2f..fe32cd677596 100644 --- a/src/libcamera/thread.cpp +++ b/src/libcamera/thread.cpp @@ -9,6 +9,9 @@ #include #include +#include +#include +#include #include @@ -62,6 +65,7 @@ private: Thread *thread_; bool running_; + pid_t tid_; Mutex mutex_; @@ -108,6 +112,7 @@ ThreadData *ThreadData::current() * started, set it here. */ ThreadData *data = mainThread.data_; + data->tid_ = syscall(SYS_gettid); currentThreadData = data; return data; } @@ -189,6 +194,7 @@ void Thread::startThread() */ thread_local ThreadCleaner cleaner(this, &Thread::finishThread); + data_->tid_ = syscall(SYS_gettid); currentThreadData = data_; run(); @@ -308,6 +314,20 @@ Thread *Thread::current() return data->thread_; } +/** + * \brief Retrieve the ID of the current thread + * + * The thread ID corresponds to the Linux thread ID (TID) as returned by the + * gettid system call. + * + * \return The ID of the current thread + */ +pid_t Thread::currentId() +{ + ThreadData *data = ThreadData::current(); + return data->tid_; +} + /** * \brief Set the event dispatcher * \param[in] dispatcher Pointer to the event dispatcher From patchwork Sat Jan 18 21:33:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 2685 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id EFB58607C0 for ; Sat, 18 Jan 2020 22:34:07 +0100 (CET) Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 8F84997A for ; Sat, 18 Jan 2020 22:34:07 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1579383247; bh=Gk0IkXje+/XEZItjaqunjcjycI5ec76JYckGXi99qLY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=U0mcBsMoNZLi0OtbeWIz1rPrnl717wlJCw9zqn7/cb47uJ3T/+aOixHY3GV9QJer3 LBTXzmKIFwGyZi3SqmfOkpiied1UiYeykhyN+bp9HdzGc1s3lNqXXf55v8puvnzd4B 7a4pRrTo20+/ayLy43tRay7CSHTz2myIH5zThw3c= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sat, 18 Jan 2020 23:33:48 +0200 Message-Id: <20200118213348.16561-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200118213348.16561-1-laurent.pinchart@ideasonboard.com> References: <20200118213348.16561-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/2] libcamera: log: Print the thread ID in the log X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 18 Jan 2020 21:34:08 -0000 The current thread ID is useful when debugging concurrency issues. Print it in log messages. The syslog target is left out as the thread ID would have little use there, and partly duplicates the process ID. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund Reviewed-by: Kieran Bingham --- src/libcamera/log.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libcamera/log.cpp b/src/libcamera/log.cpp index f4eb8c11adc3..1dac4666b435 100644 --- a/src/libcamera/log.cpp +++ b/src/libcamera/log.cpp @@ -22,6 +22,7 @@ #include +#include "thread.h" #include "utils.h" /** @@ -196,7 +197,8 @@ void LogOutput::write(const LogMessage &msg) break; case LoggingTargetStream: case LoggingTargetFile: - str = "[" + utils::time_point_to_string(msg.timestamp()) + "]" + str = "[" + utils::time_point_to_string(msg.timestamp()) + "] [" + + std::to_string(Thread::currentId()) + "]" + log_severity_name(msg.severity()) + " " + msg.category().name() + " " + msg.fileInfo() + " " + msg.msg();