qemu/tests/migration/guestperf/report.py
<<
>>
Prefs
   1#
   2# Migration test output result reporting
   3#
   4# Copyright (c) 2016 Red Hat, Inc.
   5#
   6# This library is free software; you can redistribute it and/or
   7# modify it under the terms of the GNU Lesser General Public
   8# License as published by the Free Software Foundation; either
   9# version 2.1 of the License, or (at your option) any later version.
  10#
  11# This library is distributed in the hope that it will be useful,
  12# but WITHOUT ANY WARRANTY; without even the implied warranty of
  13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14# Lesser General Public License for more details.
  15#
  16# You should have received a copy of the GNU Lesser General Public
  17# License along with this library; if not, see <http://www.gnu.org/licenses/>.
  18#
  19
  20import json
  21
  22from guestperf.hardware import Hardware
  23from guestperf.scenario import Scenario
  24from guestperf.progress import Progress
  25from guestperf.timings import Timings
  26
  27class Report(object):
  28
  29    def __init__(self,
  30                 hardware,
  31                 scenario,
  32                 progress_history,
  33                 guest_timings,
  34                 qemu_timings,
  35                 vcpu_timings,
  36                 binary,
  37                 dst_host,
  38                 kernel,
  39                 initrd,
  40                 transport,
  41                 sleep):
  42
  43        self._hardware = hardware
  44        self._scenario = scenario
  45        self._progress_history = progress_history
  46        self._guest_timings = guest_timings
  47        self._qemu_timings = qemu_timings
  48        self._vcpu_timings = vcpu_timings
  49        self._binary = binary
  50        self._dst_host = dst_host
  51        self._kernel = kernel
  52        self._initrd = initrd
  53        self._transport = transport
  54        self._sleep = sleep
  55
  56    def serialize(self):
  57        return {
  58            "hardware": self._hardware.serialize(),
  59            "scenario": self._scenario.serialize(),
  60            "progress_history": [progress.serialize() for progress in self._progress_history],
  61            "guest_timings": self._guest_timings.serialize(),
  62            "qemu_timings": self._qemu_timings.serialize(),
  63            "vcpu_timings": self._vcpu_timings.serialize(),
  64            "binary": self._binary,
  65            "dst_host": self._dst_host,
  66            "kernel": self._kernel,
  67            "initrd": self._initrd,
  68            "transport": self._transport,
  69            "sleep": self._sleep,
  70        }
  71
  72    @classmethod
  73    def deserialize(cls, data):
  74        return cls(
  75            Hardware.deserialize(data["hardware"]),
  76            Scenario.deserialize(data["scenario"]),
  77            [Progress.deserialize(record) for record in data["progress_history"]],
  78            Timings.deserialize(data["guest_timings"]),
  79            Timings.deserialize(data["qemu_timings"]),
  80            Timings.deserialize(data["vcpu_timings"]),
  81            data["binary"],
  82            data["dst_host"],
  83            data["kernel"],
  84            data["initrd"],
  85            data["transport"],
  86            data["sleep"])
  87
  88    def to_json(self):
  89        return json.dumps(self.serialize(), indent=4)
  90
  91    @classmethod
  92    def from_json(cls, data):
  93        return cls.deserialize(json.loads(data))
  94
  95    @classmethod
  96    def from_json_file(cls, filename):
  97        with open(filename, "r") as fh:
  98            return cls.deserialize(json.load(fh))
  99