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 <ag...@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 <ag...@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
signature.asc
Description: OpenPGP digital signature