[virt-tools-list] [virt-manager PATCH] osdict: lazy load devices data
Cole Robinson
crobinso at redhat.com
Mon May 19 21:58:20 UTC 2014
On 05/16/2014 08:13 AM, Giuseppe Scrivano wrote:
> Do not load the devices data for each OS as most of this data will
> will not be used by virt-manager. It makes the "Create new VM" wizard
> faster on the first time it is accessed (~0.5s faster on my machine).
>
I noticed too that the create wizard startup is really sluggish. ACK to this bit.
I also ran:
python -m cProfile -s time virt-manager --connect test:///default
--show-domain-creator --no-fork
Which show:
1 0.366 0.366 0.366 0.366 osdict.py:517(_get_os_loader)
6223/566 0.283 0.000 0.310 0.001 osdict.py:323(is_os_related_to)
Which are both one time costs but still make the dialog noticeably slow. Maybe
we can take the initial OS list population bits in create.py and stuff them in
an idle callback on first run. So the dialog will open quicker, and that stuff
will be done in the background hopefully before the user starts actually
interacting with the UI
- Cole
> Signed-off-by: Giuseppe Scrivano <gscrivan at redhat.com>
> ---
> virtinst/osdict.py | 24 ++++++++++++++----------
> 1 file changed, 14 insertions(+), 10 deletions(-)
>
> diff --git a/virtinst/osdict.py b/virtinst/osdict.py
> index 16bb807..7ffecb1 100644
> --- a/virtinst/osdict.py
> +++ b/virtinst/osdict.py
> @@ -23,6 +23,7 @@ _SENTINEL = -1234
> _allvariants = {}
> from datetime import datetime
> from gi.repository import Libosinfo as libosinfo
> +from inspect import isfunction
>
> _aliases = {
> "altlinux" : "altlinux1.0",
> @@ -463,17 +464,17 @@ class _OsVariantOsInfo(_OSVariant):
> acpi = self._is_acpi()
> apic = self._is_apic()
> clock = self._get_clock()
> - netmodel = self._get_netmodel()
> - videomodel = self._get_videomodel()
> - diskbus = self._get_diskbus()
> - inputtype = self._get_inputtype()
> - inputbus = self.get_inputbus()
> xen_disable_acpi = self._get_xen_disable_acpi()
> - virtiodisk = self._is_virtiodisk()
> - virtionet = self._is_virtionet()
> virtiommio = self._is_virtiommio()
> - virtioconsole = self._is_virtioconsole()
> qemu_ga = self._is_qemu_ga()
> + virtioconsole = lambda: self._is_virtioconsole()
> + netmodel = lambda: self._get_netmodel()
> + videomodel = lambda: self._get_videomodel()
> + diskbus = lambda: self._get_diskbus()
> + inputtype = lambda: self._get_inputtype()
> + inputbus = lambda: self.get_inputbus()
> + virtiodisk = lambda: self._is_virtiodisk()
> + virtionet = lambda: self._is_virtionet()
> _OSVariant.__init__(self, name=name, label=label, is_type=is_type,
> typename=typename, sortby=sortby, parent="generic",
> urldistro=urldistro, supported=supported,
> @@ -572,9 +573,12 @@ def lookup_osdict_key(variant, key, default):
> _load_os_data()
> val = _SENTINEL
> if variant is not None:
> - if not hasattr(lookup_os(variant), key):
> + os = lookup_os(variant)
> + if not hasattr(os, key):
> raise ValueError("Unknown osdict property '%s'" % key)
> - val = getattr(lookup_os(variant), key)
> + val = getattr(os, key)
> + if isfunction(val):
> + return val()
> if val == _SENTINEL:
> val = default
> return val
>
More information about the virt-tools-list
mailing list