[2/2] criu: pie, log -- Print tid of writting process

Submitted by Cyrill Gorcunov on May 19, 2016, 7:12 p.m.

Details

Message ID 1463685145-14229-2-git-send-email-gorcunov@openvz.org
State Rejected
Series "Series without cover letter"
Headers show

Commit Message

Cyrill Gorcunov May 19, 2016, 7:12 p.m.
For more convenient log parsing.

Reported-by: Pavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
---
 criu/pie/log-simple.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/pie/log-simple.c b/criu/pie/log-simple.c
index f4470af57f66..d4336264ae81 100644
--- a/criu/pie/log-simple.c
+++ b/criu/pie/log-simple.c
@@ -8,6 +8,7 @@ 
 struct simple_buf {
 	char buf[LOG_SIMPLE_CHUNK];
 	char *bp;
+	size_t prefix_len;
 	void (*flush)(struct simple_buf *b);
 };
 
@@ -18,18 +19,35 @@  static void sbuf_log_flush(struct simple_buf *b);
 
 static void sbuf_log_init(struct simple_buf *b)
 {
+	char pid_buf[12], *s;
+	size_t n;
+
+	/*
+	 * Format:
+	 *
+	 * pie: pid: string-itself
+	 */
+	b->prefix_len = vprint_num(pid_buf, sizeof(pid_buf), sys_gettid(), &s);
 	b->buf[0] = 'p';
 	b->buf[1] = 'i';
 	b->buf[2] = 'e';
 	b->buf[3] = ':';
 	b->buf[4] = ' ';
-	b->bp = b->buf + 5;
+
+	for (n = 0; n < b->prefix_len; n++)
+		b->buf[n + 5] = s[n];
+	b->buf[n + 5] = ' ';
+	b->buf[n + 6] = ':';
+	b->buf[n + 6] = ' ';
+	b->prefix_len += 8;
+
+	b->bp = b->buf + b->prefix_len;
 	b->flush = sbuf_log_flush;
 }
 
 static void sbuf_log_flush(struct simple_buf *b)
 {
-	if (b->bp == b->buf + 5)
+	if (b->bp == b->buf + b->prefix_len)
 		return;
 
 	sys_write(logfd, b->buf, b->bp - b->buf);

Comments

Andrey Vagin May 19, 2016, 8:16 p.m.
On Thu, May 19, 2016 at 10:12:25PM +0300, Cyrill Gorcunov wrote:
> For more convenient log parsing.
> 
> Reported-by: Pavel Emelyanov <xemul@virtuozzo.com>
> Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
> ---
>  criu/pie/log-simple.c | 22 ++++++++++++++++++++--
>  1 file changed, 20 insertions(+), 2 deletions(-)
> 
> diff --git a/criu/pie/log-simple.c b/criu/pie/log-simple.c
> index f4470af57f66..d4336264ae81 100644
> --- a/criu/pie/log-simple.c
> +++ b/criu/pie/log-simple.c
> @@ -8,6 +8,7 @@
>  struct simple_buf {
>  	char buf[LOG_SIMPLE_CHUNK];
>  	char *bp;
> +	size_t prefix_len;
>  	void (*flush)(struct simple_buf *b);
>  };
>  
> @@ -18,18 +19,35 @@ static void sbuf_log_flush(struct simple_buf *b);
>  
>  static void sbuf_log_init(struct simple_buf *b)
>  {

Can we call sbuf_log_init() only when tid is changed? In other cases, a
prefix isn't changed and we can reuse it.

> +	char pid_buf[12], *s;
> +	size_t n;
> +
> +	/*
> +	 * Format:
> +	 *
> +	 * pie: pid: string-itself
> +	 */
> +	b->prefix_len = vprint_num(pid_buf, sizeof(pid_buf), sys_gettid(), &s);
>  	b->buf[0] = 'p';
>  	b->buf[1] = 'i';
>  	b->buf[2] = 'e';
>  	b->buf[3] = ':';
>  	b->buf[4] = ' ';
> -	b->bp = b->buf + 5;
> +
> +	for (n = 0; n < b->prefix_len; n++)
> +		b->buf[n + 5] = s[n];
> +	b->buf[n + 5] = ' ';
> +	b->buf[n + 6] = ':';
> +	b->buf[n + 6] = ' ';
> +	b->prefix_len += 8;
> +
> +	b->bp = b->buf + b->prefix_len;
>  	b->flush = sbuf_log_flush;
>  }
>  
>  static void sbuf_log_flush(struct simple_buf *b)
>  {
> -	if (b->bp == b->buf + 5)
> +	if (b->bp == b->buf + b->prefix_len)
>  		return;
>  
>  	sys_write(logfd, b->buf, b->bp - b->buf);
-	sbuf_log_init(b);
+	b->bp = b->buf + b->prefix_len;
> -- 
> 2.5.5
>
Cyrill Gorcunov May 19, 2016, 8:55 p.m.
On Thu, May 19, 2016 at 01:16:20PM -0700, Andrey Vagin wrote:
> >  
> >  static void sbuf_log_init(struct simple_buf *b)
> >  {
> 
> Can we call sbuf_log_init() only when tid is changed? In other cases, a
> prefix isn't changed and we can reuse it.
> 

I think we could make such optimization, yeah. Will do it tomorrow,
or do it on top if you have a spare minutes.