[libcamera-devel,v3,04/11] libcamera: request: Add a toString()
diff mbox series

Message ID 20210325134231.1400051-7-kieran.bingham@ideasonboard.com
State Accepted
Delegated to: Kieran Bingham
Headers show
Series
  • [libcamera-devel,v3,01/11] utils: ipc: proxy: Track IPA with a state machine
Related show

Commit Message

Kieran Bingham March 25, 2021, 1:42 p.m. UTC
Provide a toString helper to assist in printing Request state
for debug and logging contexts.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
---
 include/libcamera/request.h |  3 +++
 src/libcamera/request.cpp   | 30 +++++++++++++++++++++++++++---
 2 files changed, 30 insertions(+), 3 deletions(-)

Comments

Laurent Pinchart March 26, 2021, 2:08 a.m. UTC | #1
Hi Kieran,

Thank you for the patch.


On Thu, Mar 25, 2021 at 01:42:24PM +0000, Kieran Bingham wrote:
> Provide a toString helper to assist in printing Request state
> for debug and logging contexts.
> 
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> ---
>  include/libcamera/request.h |  3 +++
>  src/libcamera/request.cpp   | 30 +++++++++++++++++++++++++++---
>  2 files changed, 30 insertions(+), 3 deletions(-)
> 
> diff --git a/include/libcamera/request.h b/include/libcamera/request.h
> index cd5a24741f8a..4cf5ff3f7d3b 100644
> --- a/include/libcamera/request.h
> +++ b/include/libcamera/request.h
> @@ -10,6 +10,7 @@
>  #include <map>
>  #include <memory>
>  #include <stdint.h>
> +#include <string>
>  #include <unordered_set>
>  
>  #include <libcamera/class.h>
> @@ -56,6 +57,8 @@ public:
>  
>  	bool hasPendingBuffers() const { return !pending_.empty(); }
>  
> +	std::string toString() const;
> +
>  private:
>  	LIBCAMERA_DISABLE_COPY(Request)
>  
> diff --git a/src/libcamera/request.cpp b/src/libcamera/request.cpp
> index fc16b148a599..7b7ef6814686 100644
> --- a/src/libcamera/request.cpp
> +++ b/src/libcamera/request.cpp
> @@ -8,6 +8,7 @@
>  #include <libcamera/request.h>
>  
>  #include <map>
> +#include <sstream>
>  
>  #include <libcamera/buffer.h>
>  #include <libcamera/camera.h>
> @@ -261,6 +262,16 @@ FrameBuffer *Request::findBuffer(const Stream *stream) const
>   * otherwise
>   */
>  
> +/**
> + * \fn Request::toString()
> + * \brief Generate a string representation of the Request internals
> + *
> + * This function facilitates debugging of Request state while it is used
> + * internally within libcamera.
> + *
> + * \return A string representing the current state of the request
> + */
> +

Any reason why this isn't move below, just above the function ?

>  /**
>   * \brief Complete a queued request
>   *
> @@ -275,9 +286,7 @@ void Request::complete()
>  
>  	status_ = cancelled_ ? RequestCancelled : RequestComplete;
>  
> -	LOG(Request, Debug)
> -		<< "Request has completed - cookie: " << cookie_
> -		<< (cancelled_ ? " [Cancelled]" : "");
> +	LOG(Request, Debug) << toString();
>  
>  	LIBCAMERA_TRACEPOINT(request_complete, this);
>  }
> @@ -310,4 +319,19 @@ bool Request::completeBuffer(FrameBuffer *buffer)
>  	return !hasPendingBuffers();
>  }
>  
> +std::string Request::toString() const
> +{
> +	std::stringstream ss;
> +
> +	/* Pending, Completed, Cancelled(X). */
> +	static const char *statuses = "PCX";
> +
> +	/* Example Output: Request(55:P:1/2:6523524) */
> +	ss << "Request (" << sequence_ << ":" << statuses[status_] << ":"

s/Request /Request/

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> +	   << pending_.size() << "/" << bufferMap_.size() << ":"
> +	   << cookie_ << ")";
> +
> +	return ss.str();
> +}
> +
>  } /* namespace libcamera */
Kieran Bingham March 26, 2021, 3 p.m. UTC | #2
On 26/03/2021 02:08, Laurent Pinchart wrote:
> Hi Kieran,
> 
> Thank you for the patch.
> 
> 
> On Thu, Mar 25, 2021 at 01:42:24PM +0000, Kieran Bingham wrote:
>> Provide a toString helper to assist in printing Request state
>> for debug and logging contexts.
>>
>> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
>> ---
>>  include/libcamera/request.h |  3 +++
>>  src/libcamera/request.cpp   | 30 +++++++++++++++++++++++++++---
>>  2 files changed, 30 insertions(+), 3 deletions(-)
>>
>> diff --git a/include/libcamera/request.h b/include/libcamera/request.h
>> index cd5a24741f8a..4cf5ff3f7d3b 100644
>> --- a/include/libcamera/request.h
>> +++ b/include/libcamera/request.h
>> @@ -10,6 +10,7 @@
>>  #include <map>
>>  #include <memory>
>>  #include <stdint.h>
>> +#include <string>
>>  #include <unordered_set>
>>  
>>  #include <libcamera/class.h>
>> @@ -56,6 +57,8 @@ public:
>>  
>>  	bool hasPendingBuffers() const { return !pending_.empty(); }
>>  
>> +	std::string toString() const;
>> +
>>  private:
>>  	LIBCAMERA_DISABLE_COPY(Request)
>>  
>> diff --git a/src/libcamera/request.cpp b/src/libcamera/request.cpp
>> index fc16b148a599..7b7ef6814686 100644
>> --- a/src/libcamera/request.cpp
>> +++ b/src/libcamera/request.cpp
>> @@ -8,6 +8,7 @@
>>  #include <libcamera/request.h>
>>  
>>  #include <map>
>> +#include <sstream>
>>  
>>  #include <libcamera/buffer.h>
>>  #include <libcamera/camera.h>
>> @@ -261,6 +262,16 @@ FrameBuffer *Request::findBuffer(const Stream *stream) const
>>   * otherwise
>>   */
>>  
>> +/**
>> + * \fn Request::toString()
>> + * \brief Generate a string representation of the Request internals
>> + *
>> + * This function facilitates debugging of Request state while it is used
>> + * internally within libcamera.
>> + *
>> + * \return A string representing the current state of the request
>> + */
>> +
> 
> Any reason why this isn't move below, just above the function ?

Errmmmm ... this is odd ... I'm not even sure how that happened.

Of course it should be above the function.

> 
>>  /**
>>   * \brief Complete a queued request
>>   *
>> @@ -275,9 +286,7 @@ void Request::complete()
>>  
>>  	status_ = cancelled_ ? RequestCancelled : RequestComplete;
>>  
>> -	LOG(Request, Debug)
>> -		<< "Request has completed - cookie: " << cookie_
>> -		<< (cancelled_ ? " [Cancelled]" : "");
>> +	LOG(Request, Debug) << toString();
>>  
>>  	LIBCAMERA_TRACEPOINT(request_complete, this);
>>  }
>> @@ -310,4 +319,19 @@ bool Request::completeBuffer(FrameBuffer *buffer)
>>  	return !hasPendingBuffers();
>>  }
>>  
>> +std::string Request::toString() const
>> +{
>> +	std::stringstream ss;
>> +
>> +	/* Pending, Completed, Cancelled(X). */
>> +	static const char *statuses = "PCX";
>> +
>> +	/* Example Output: Request(55:P:1/2:6523524) */
>> +	ss << "Request (" << sequence_ << ":" << statuses[status_] << ":"
> 
> s/Request /Request/
> 
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Fixed up.

Thanks.

> 
>> +	   << pending_.size() << "/" << bufferMap_.size() << ":"
>> +	   << cookie_ << ")";
>> +
>> +	return ss.str();
>> +}
>> +
>>  } /* namespace libcamera */
>

Patch
diff mbox series

diff --git a/include/libcamera/request.h b/include/libcamera/request.h
index cd5a24741f8a..4cf5ff3f7d3b 100644
--- a/include/libcamera/request.h
+++ b/include/libcamera/request.h
@@ -10,6 +10,7 @@ 
 #include <map>
 #include <memory>
 #include <stdint.h>
+#include <string>
 #include <unordered_set>
 
 #include <libcamera/class.h>
@@ -56,6 +57,8 @@  public:
 
 	bool hasPendingBuffers() const { return !pending_.empty(); }
 
+	std::string toString() const;
+
 private:
 	LIBCAMERA_DISABLE_COPY(Request)
 
diff --git a/src/libcamera/request.cpp b/src/libcamera/request.cpp
index fc16b148a599..7b7ef6814686 100644
--- a/src/libcamera/request.cpp
+++ b/src/libcamera/request.cpp
@@ -8,6 +8,7 @@ 
 #include <libcamera/request.h>
 
 #include <map>
+#include <sstream>
 
 #include <libcamera/buffer.h>
 #include <libcamera/camera.h>
@@ -261,6 +262,16 @@  FrameBuffer *Request::findBuffer(const Stream *stream) const
  * otherwise
  */
 
+/**
+ * \fn Request::toString()
+ * \brief Generate a string representation of the Request internals
+ *
+ * This function facilitates debugging of Request state while it is used
+ * internally within libcamera.
+ *
+ * \return A string representing the current state of the request
+ */
+
 /**
  * \brief Complete a queued request
  *
@@ -275,9 +286,7 @@  void Request::complete()
 
 	status_ = cancelled_ ? RequestCancelled : RequestComplete;
 
-	LOG(Request, Debug)
-		<< "Request has completed - cookie: " << cookie_
-		<< (cancelled_ ? " [Cancelled]" : "");
+	LOG(Request, Debug) << toString();
 
 	LIBCAMERA_TRACEPOINT(request_complete, this);
 }
@@ -310,4 +319,19 @@  bool Request::completeBuffer(FrameBuffer *buffer)
 	return !hasPendingBuffers();
 }
 
+std::string Request::toString() const
+{
+	std::stringstream ss;
+
+	/* Pending, Completed, Cancelled(X). */
+	static const char *statuses = "PCX";
+
+	/* Example Output: Request(55:P:1/2:6523524) */
+	ss << "Request (" << sequence_ << ":" << statuses[status_] << ":"
+	   << pending_.size() << "/" << bufferMap_.size() << ":"
+	   << cookie_ << ")";
+
+	return ss.str();
+}
+
 } /* namespace libcamera */