module_trace: Support --trace_libvirt=all|mainloop

'all' means log even API calls that are invoked from threads
This commit is contained in:
Cole Robinson 2018-10-10 15:19:15 -04:00
parent 155ddcfc17
commit 390adc4e58
2 changed files with 14 additions and 7 deletions

View File

@ -122,8 +122,8 @@ def parse_commandline():
parser.set_defaults(domain=None) parser.set_defaults(domain=None)
# Trace every libvirt API call to debug output # Trace every libvirt API call to debug output
parser.add_argument("--trace-libvirt", parser.add_argument("--trace-libvirt", choices=["all", "mainloop"],
help=argparse.SUPPRESS, action="store_true") help=argparse.SUPPRESS)
# Don't load any connections on startup to test first run # Don't load any connections on startup to test first run
# PackageKit integration # PackageKit integration
@ -180,7 +180,9 @@ def main():
logging.debug("Libvirt tracing requested") logging.debug("Libvirt tracing requested")
import virtManager.module_trace import virtManager.module_trace
import libvirt import libvirt
virtManager.module_trace.wrap_module(libvirt, regex=None) virtManager.module_trace.wrap_module(libvirt,
mainloop=(options.trace_libvirt == "mainloop"),
regex=None)
# With F27 gnome+wayland we need to set these before GTK import # With F27 gnome+wayland we need to set these before GTK import
os.environ["GSETTINGS_SCHEMA_DIR"] = CLIConfig.gsettings_dir os.environ["GSETTINGS_SCHEMA_DIR"] = CLIConfig.gsettings_dir

View File

@ -15,7 +15,9 @@ import time
import traceback import traceback
from types import FunctionType from types import FunctionType
from types import MethodType
CHECK_MAINLOOP = False
def generate_wrapper(origfunc, name): def generate_wrapper(origfunc, name):
@ -35,7 +37,8 @@ def generate_wrapper(origfunc, name):
name.endswith(".connect") or name.endswith(".connect") or
name.startswith("libvirtError")) name.startswith("libvirtError"))
if not is_non_network_libvirt_call and is_main_thread: if (not is_non_network_libvirt_call and
(is_main_thread or not CHECK_MAINLOOP)):
tb = "" tb = ""
if is_main_thread: if is_main_thread:
tb = "\n%s" % "".join(traceback.format_stack()) tb = "\n%s" % "".join(traceback.format_stack())
@ -68,11 +71,13 @@ def wrap_class(classobj):
for name in dir(classobj): for name in dir(classobj):
obj = getattr(classobj, name) obj = getattr(classobj, name)
if isinstance(obj, MethodType): if isinstance(obj, FunctionType):
wrap_method(classobj, obj) wrap_method(classobj, obj)
def wrap_module(module, regex=None): def wrap_module(module, mainloop, regex):
global CHECK_MAINLOOP
CHECK_MAINLOOP = mainloop
for name in dir(module): for name in dir(module):
if regex and not re.match(regex, name): if regex and not re.match(regex, name):
continue continue