Closed dkbiswas closed 1 year ago
cProfile: 1846819 function calls (1836595 primitive calls) in 1.702 seconds
Ordered by: internal time
ncalls tottime percall cumtime percall filename:lineno(function)
262 0.337 0.001 0.337 0.001 {method 'read' of '_ssl._SSLSocket' objects}
36539 0.149 0.000 0.472 0.000 SoapAdapter.py:660(StartElementHandler)
36539 0.128 0.000 0.361 0.000 SoapAdapter.py:721(EndElementHandler)
129 0.119 0.001 0.976 0.008 {method 'ParseFile' of 'pyexpat.xmlparser' objects}
104346 0.071 0.000 0.071 0.000 VmomiSupport.py:461(GetPropertyInfo)
8815 0.070 0.000 0.166 0.000 VmomiSupport.py:624(init)
72738 0.051 0.000 0.074 0.000 SoapAdapter.py:636(SplitTag)
32359/31862 0.049 0.000 0.074 0.000 VmomiSupport.py:1034(CheckField)
326816 0.047 0.000 0.047 0.000 {built-in method builtins.isinstance}
25 0.035 0.001 0.035 0.001 {built-in method _imp.create_dynamic}
289917 0.031 0.000 0.031 0.000 {built-in method builtins.issubclass}
31608 0.031 0.000 0.121 0.000 VmomiSupport.py:662(setattr)
9311 0.028 0.000 0.065 0.000 VmomiSupport.py:649(_GetPropertyList)
20975 0.027 0.000 0.036 0.000 VmomiSupport.py:656(
declaring vm properties : vm_properties = ["name", "config.name", "summary.runtime.connectionState", "config.uuid", "summary.config.name", "config.instanceUuid", "config.changeTrackingEnabled", "capability.changeTrackingSupported", "config.guestFullName", "config.version", "config.ftInfo", "config.template", "datastore", "resourcePool", "runtime.host"] """ vm_properties.append(["config.hardware.device", "config.extraConfig"]) """ vm_properties = ["config.template"]
parser = cli.Parser() args = parser.get_args() si = service_instance.connect(args) atexit.register(endit)
root_folder = si.content.rootFolder view = pchelper.get_container_view(si, obj_type=[vim.VirtualMachine]) vm_data = pchelper.collect_properties(si, view_ref=view, obj_type=vim.VirtualMachine, path_set=vm_properties, include_mors=True) would make faster to get vm information.
Describe the bug
` [root@$ samples]# cat getallvms2.py
!/usr/bin/env python
VMware vSphere Python SDK
Copyright (c) 2008-2021 VMware, Inc. All Rights Reserved.
#
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
#
http://www.apache.org/licenses/LICENSE-2.0
#
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
""" Python program for listing the VMs on an ESX / vCenter host """
import re from pyVmomi import vmodl, vim from tools import cli, service_instance
def print_vm_info(virtual_machine): """ Print information for a particular virtual machine or recurse into a folder with depth protection """ vm_config = {} summary = virtual_machine.summary host_ref = virtual_machine.runtime.host if not host_ref: print("Can't find host ref") accessibility = summary.runtime.connectionState extra_config = virtual_machine.config.extraConfig vname = summary.config.name
def main(): """ Simple command-line program for listing the virtual machines on a system. """
Start program
if name == "main": main()
Time is taken by the above python script to list VMs with required attributes. ` real 0m4.137s user 0m3.021s sys 0m0.074s
If similar perl prog takin near ~1 mili sec. Can someone suggest, how to improve the above python script running time to nearly or equivalent to Perl.
Reproduction steps
...
Expected behavior
expected to run near about ~1 mili sec.
Additional context
No response