[libcamera-devel,04/19] libcamera: log: Print the thread ID in the log

Message ID 20200120002437.6633-5-laurent.pinchart@ideasonboard.com
State Superseded
Headers show
Series
  • Initial libcamera threading model
Related show

Commit Message

Laurent Pinchart Jan. 20, 2020, 12:24 a.m. UTC
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 <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
---
 src/libcamera/log.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Jacopo Mondi Jan. 20, 2020, 11:33 a.m. UTC | #1
Hi Laurent

On Mon, Jan 20, 2020 at 02:24:22AM +0200, Laurent Pinchart wrote:
> 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 <laurent.pinchart@ideasonboard.com>
> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>

Thanks
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>

> ---
>  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 <libcamera/logging.h>
>
> +#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();
> --
> Regards,
>
> Laurent Pinchart
>
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel@lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel

Patch

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 <libcamera/logging.h>
 
+#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();