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)
# Trace every libvirt API call to debug output
parser.add_argument("--trace-libvirt",
help=argparse.SUPPRESS, action="store_true")
parser.add_argument("--trace-libvirt", choices=["all", "mainloop"],
help=argparse.SUPPRESS)
# Don't load any connections on startup to test first run
# PackageKit integration
@ -180,7 +180,9 @@ def main():
logging.debug("Libvirt tracing requested")
import virtManager.module_trace
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
os.environ["GSETTINGS_SCHEMA_DIR"] = CLIConfig.gsettings_dir

View File

@ -15,7 +15,9 @@ import time
import traceback
from types import FunctionType
from types import MethodType
CHECK_MAINLOOP = False
def generate_wrapper(origfunc, name):
@ -35,7 +37,8 @@ def generate_wrapper(origfunc, name):
name.endswith(".connect") or
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 = ""
if is_main_thread:
tb = "\n%s" % "".join(traceback.format_stack())
@ -68,11 +71,13 @@ def wrap_class(classobj):
for name in dir(classobj):
obj = getattr(classobj, name)
if isinstance(obj, MethodType):
if isinstance(obj, FunctionType):
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):
if regex and not re.match(regex, name):
continue