On 3/23/22 16:57, Vladimir Sementsov-Ogievskiy wrote:

23.03.2022 13:53, Nikita Lapshin wrote:
From: Nikita Lapshin<nikita.laps...@virtuozzo.com>
This script is used for RAM capabilities test. But it cannot work
in case of no vm description in migration stream.
So new flag is added to allow work this script with ram-only
migration stream.
Signed-off-by: Nikita Lapshin<nikita.laps...@openvz.org>
---
   scripts/analyze-migration.py | 19 ++++++++++++-------
   1 file changed, 12 insertions(+), 7 deletions(-)
diff --git a/scripts/analyze-migration.py b/scripts/analyze-migration.py
index b82a1b0c58..80077a09bc 100755
--- a/scripts/analyze-migration.py
+++ b/scripts/analyze-migration.py
@@ -495,7 +495,7 @@ def __init__(self, filename):
           self.filename = filename
           self.vmsd_desc = None
-    def read(self, desc_only = False, dump_memory = False, write_memory = False):
+    def read(self, ram_only, desc_only = False, dump_memory = False, 
write_memory = False):
           # Read in the whole file
           file = MigrationFile(self.filename)
@@ -509,7 +509,8 @@ def read(self, desc_only = False, dump_memory = False, write_memory = False):
           if data != self.QEMU_VM_FILE_VERSION:
               raise Exception("Invalid version number %d" % data)
-        self.load_vmsd_json(file)
+        if not ram_only:
+            self.load_vmsd_json(file)
          # Read sections
           self.sections = collections.OrderedDict()
@@ -518,7 +519,10 @@ def read(self, desc_only = False, dump_memory = False, 
write_memory = False):
               return
          ramargs = {}
-        ramargs['page_size'] = self.vmsd_desc['page_size']
+        if ram_only:
+            ramargs['page_size'] = 4096
+        else:
+            ramargs['page_size'] = self.vmsd_desc['page_size']
           ramargs['dump_memory'] = dump_memory
           ramargs['write_memory'] = write_memory
           self.section_classes[('ram',0)][1] = ramargs
@@ -579,6 +583,7 @@ def default(self, o):
   parser.add_argument("-m", "--memory", help='dump RAM contents as well', 
action='store_true')
   parser.add_argument("-d", "--dump", help='what to dump ("state" or "desc")', 
default='state')
   parser.add_argument("-x", "--extract", help='extract contents into 
individual files', action='store_true')
+parser.add_argument("--ram-only", help='parse migration dump containing only 
RAM', action='store_true')
   args = parser.parse_args()
  jsonenc = JSONEncoder(indent=4, separators=(',', ': '))
@@ -586,14 +591,14 @@ def default(self, o):
   if args.extract:
       dump = MigrationDump(args.file)
could this ram_only instead be stored into object, so that we do
dump = MigrationDump(args.file, ram_only=args.ram_only)
and don't update each read call?

Yes, it could, don't see any problem with this.

-    dump.read(desc_only = True)
+    dump.read(desc_only = True, ram_only = args.ram_only)
       print("desc.json")
       f = open("desc.json", "w")
       f.truncate()
       f.write(jsonenc.encode(dump.vmsd_desc))
       f.close()
-    dump.read(write_memory = True)
+    dump.read(write_memory = True, ram_only = args.ram_only)
       dict = dump.getDict()
       print("state.json")
       f = open("state.json", "w")
@@ -602,12 +607,12 @@ def default(self, o):
       f.close()
   elif args.dump == "state":
       dump = MigrationDump(args.file)
-    dump.read(dump_memory = args.memory)
+    dump.read(dump_memory = args.memory, ram_only = args.ram_only)
       dict = dump.getDict()
       print(jsonenc.encode(dict))
   elif args.dump == "desc":
       dump = MigrationDump(args.file)
-    dump.read(desc_only = True)
+    dump.read(desc_only = True, ram_only = args.ram_only)
       print(jsonenc.encode(dump.vmsd_desc))
   else:
       raise Exception("Please specify either -x, -d state or -d desc")

Reply via email to