All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: Alexander Graf <agraf@suse.de>, qemu-devel@nongnu.org
Cc: amit.shah@redhat.com, pbonzini@redhat.com, afaerber@suse.de,
	quintela@redhat.com
Subject: Re: [Qemu-devel] [PATCH v3 5/5] Add migration stream analyzation script
Date: Tue, 06 Jan 2015 09:05:03 -0700	[thread overview]
Message-ID: <54AC07AF.80108@redhat.com> (raw)
In-Reply-To: <1419604968-87437-6-git-send-email-agraf@suse.de>

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

On 12/26/2014 07:42 AM, Alexander Graf wrote:
> This patch adds a python tool to the scripts directory that can read
> a dumped migration stream if it contains the JSON description of the
> device states. I constructs a human readable JSON stream out of it.
> 
> It's very simple to use:
> 
>   $ qemu-system-x86_64
>     (qemu) migrate "exec:cat > mig"
>   $ ./scripts/analyze_migration.py -f mig
> 
> Signed-off-by: Alexander Graf <agraf@suse.de>
> 
> ---

> diff --git a/scripts/analyze-migration.py b/scripts/analyze-migration.py
> new file mode 100755
> index 0000000..3363172
> --- /dev/null
> +++ b/scripts/analyze-migration.py
> @@ -0,0 +1,592 @@
> +#!/usr/bin/env python
> +#
> +#  Migration Stream Analyzer
> +#
> +#  Copyright (c) 2013 Alexander Graf <agraf@suse.de>

Started in 2013, but you may want to add 2014 and 2015 by the time this
patch is polished.

> +
> +    # The VMSD description is at the end of the file, after EOF. Look for
> +    # the last NULL byte, then for the beginning brace of JSON.

Hmm, you picked up on an optimization that I missed in my ramblings
about 4/5 :)  Since a well-formed JSON description contains no NUL bytes
or control characters, a pipeline read of a migration stream can just
continually look for every '\6' marker byte followed by '{' as the
potential start of an object, and reset that search every time a '\0' or
another '\6' byte is seen; eventually, this will result in just the tail
of the file being seen as the JSON object (assuming that we never add
any other tail metadata - or that all other tail metadata is added as
backwards-compatible extensions to the JSON).  It STILL might be worth
the efficiency gain of stashing an offset in the file somewhere (as it
is faster to seek to an offset than it is to scan for particular
patterns), but at least your scan works forwards rather than in reverse.

> +
> +        # Find the last NULL byte, then the first brace after that. This should
> +        # be the beginning of our JSON data.
> +        nulpos = data.rfind("\0")
> +        jsonpos = data.find("{", nulpos)

Are you sure that there will NEVER be a '{' somewhere between the last
NUL and the end-of-stream marker?  Shouldn't you really be searching for
the last QEMU_VM_VMDESCRIPTION ('\6') magic byte, rather than NUL?

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


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

  reply	other threads:[~2015-01-06 16:05 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-26 14:42 [Qemu-devel] [PATCH v3 0/5] Migration Deciphering aid Alexander Graf
2014-12-26 14:42 ` [Qemu-devel] [PATCH v3 1/5] QJSON: Add JSON writer Alexander Graf
2015-01-06 15:41   ` Eric Blake
2015-01-06 21:39     ` Alexander Graf
2014-12-26 14:42 ` [Qemu-devel] [PATCH v3 2/5] " Alexander Graf
2015-01-06 15:44   ` Eric Blake
2015-01-06 21:16     ` Alexander Graf
2014-12-26 14:42 ` [Qemu-devel] [PATCH v3 3/5] qemu-file: Add fast ftell code path Alexander Graf
2015-01-06 15:46   ` Eric Blake
2014-12-26 14:42 ` [Qemu-devel] [PATCH v3 4/5] migration: Append JSON description of migration stream Alexander Graf
2015-01-06 15:56   ` Eric Blake
2015-01-06 21:25     ` Alexander Graf
2015-01-20 10:30   ` Amit Shah
2014-12-26 14:42 ` [Qemu-devel] [PATCH v3 5/5] Add migration stream analyzation script Alexander Graf
2015-01-06 16:05   ` Eric Blake [this message]
2015-01-06 21:29     ` Alexander Graf
2015-01-20 10:31 ` [Qemu-devel] [PATCH v3 0/5] Migration Deciphering aid Amit Shah
2015-01-20 10:54   ` Alexander Graf
2015-01-21  6:05     ` Amit Shah

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=54AC07AF.80108@redhat.com \
    --to=eblake@redhat.com \
    --cc=afaerber@suse.de \
    --cc=agraf@suse.de \
    --cc=amit.shah@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.