qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Max Reitz <mreitz@redhat.com>
To: zhenwei pi <zhenwei.pi@youruncloud.com>,
	pbonzini@redhat.com, kwolf@redhat.com
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] qemu-progress: redirct qemu progress message to another file stream
Date: Wed, 18 Apr 2018 15:06:13 +0200	[thread overview]
Message-ID: <0e4da059-da4c-64ff-65f0-068fdd68fdcd@redhat.com> (raw)
In-Reply-To: <1523864788-15800-1-git-send-email-zhenwei.pi@youruncloud.com>

[-- Attachment #1: Type: text/plain, Size: 2691 bytes --]

On 2018-04-16 09:46, zhenwei pi wrote:
> currently qemu progress message only print into stdout, and other thread may
> print some log into stdout at the same time.
> add a new api qemu_progress_set_output to redirect progress message to
> another file stream.
> 
> Signed-off-by: zhenwei pi <zhenwei.pi@youruncloud.com>
> ---
>  include/qemu-common.h |  1 +
>  util/qemu-progress.c  | 22 +++++++++++++++++++---
>  2 files changed, 20 insertions(+), 3 deletions(-)

Well, but after this patch, qemu will still only print progress to
stdout because qemu_progress_set_output() isn't used anywhere...

> diff --git a/include/qemu-common.h b/include/qemu-common.h
> index 8a4f63c..511e7e0 100644
> --- a/include/qemu-common.h
> +++ b/include/qemu-common.h
> @@ -128,6 +128,7 @@ ssize_t qemu_co_send_recv(int sockfd, void *buf, size_t bytes, bool do_send);
>  void qemu_progress_init(int enabled, float min_skip);
>  void qemu_progress_end(void);
>  void qemu_progress_print(float delta, int max);
> +int qemu_progress_set_output(FILE *output);
>  const char *qemu_get_vm_name(void);
>  
>  #define QEMU_FILE_TYPE_BIOS   0
> diff --git a/util/qemu-progress.c b/util/qemu-progress.c
> index 3c2223c..dd7aa52 100644
> --- a/util/qemu-progress.c
> +++ b/util/qemu-progress.c
> @@ -31,6 +31,7 @@ struct progress_state {
>      float min_skip;
>      void (*print)(void);
>      void (*end)(void);
> +    FILE *output;
>  };
>  
>  static struct progress_state state;
> @@ -43,17 +44,18 @@ static volatile sig_atomic_t print_pending;
>   */
>  static void progress_simple_print(void)
>  {
> -    printf("    (%3.2f/100%%)\r", state.current);
> -    fflush(stdout);
> +    fprintf(state.output, "    (%3.2f/100%%)\r", state.current);
> +    fflush(state.output);

Also, I'm not sure we should use \r when printing to anything but stdout.

Max

>  }
>  
>  static void progress_simple_end(void)
>  {
> -    printf("\n");
> +    fprintf(state.output, "\n");
>  }
>  
>  static void progress_simple_init(void)
>  {
> +    state.output = stdout;
>      state.print = progress_simple_print;
>      state.end = progress_simple_end;
>  }
> @@ -129,6 +131,20 @@ void qemu_progress_end(void)
>  }
>  
>  /*
> + * Redirect progress into another file stream.
> + * @output is the new file stream.
> + */
> +int qemu_progress_set_output(FILE *output)
> +{
> +    if (!output) {
> +        return -EINVAL;
> +    }
> +
> +    state.output = output;
> +    return 0;
> +}
> +
> +/*
>   * Report progress.
>   * @delta is how much progress we made.
>   * If @max is zero, @delta is an absolut value of the total job done.
> 



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2018-04-18 13:06 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-16  7:46 [Qemu-devel] [PATCH] qemu-progress: redirct qemu progress message to another file stream zhenwei pi
2018-04-18 13:06 ` Max Reitz [this message]
2018-04-19  1:00   ` Zhenwei.Pi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0e4da059-da4c-64ff-65f0-068fdd68fdcd@redhat.com \
    --to=mreitz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=zhenwei.pi@youruncloud.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).