[SERVER-28233] Split up gdb/mongo.py into separate modules and support auto-registration via pkgutil Created: 07/Mar/17  Updated: 06/Dec/22

Status: Backlog
Project: Core Server
Component/s: Testing Infrastructure
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Max Hirschhorn Assignee: Backlog - Server Tooling and Methods (STM) (Inactive)
Resolution: Unresolved Votes: 0
Labels: move-sdp-candidate, neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Gantt Dependency
Assigned Teams:
Server Tooling & Methods
Participants:

 Description   

Proposed directory structure:

  • gdb/mongo/__init__.py: see below
  • gdb/mongo/commandutil.py: see below
  • gdb/mongo/backtrace.py: mongodb-uniqstack (SERVER-27877), mongodb-bt-active-only (SERVER-27727)
  • gdb/mongo/locking.py: mongodb-show-locks (SERVER-27874), mongodb-waitsfor-graph (SERVER-27874), mongodb-deadlock-detect (not filed yet)
  • gdb/mongo/printers.py: All XXPrinter classes and the build_pretty_printer() function from SERVER-26634

The .gdbinit file and hang_analyzer.py would then source buildscripts/gdb/mongo/.

gdb/mongo/__init__.py

from __future__ import absolute_import
 
import importlib as _importlib
import pkgutil as _pkgutil
 
def _load_all_modules():
    """Dynamically loads all modules in the 'mongo' package so that any
    commands declared within them are registered.
    """
 
    for (_, module, _) in _pkgutil.walk_packages(path=__path__):
        _importlib.import_module("." + module, package=__name__)
 
_load_all_modules()

gdb/mongo/commandutil.py

from __future__ import absolute_import
 
# TODO: Combine the logic of this function with register_mongo_command() to support the
# "mongodb-help" command.
def register(name, command_class, **kwargs):
    """Registers a gdb command.
 
    @commandutil.register("hello-world", gdb.COMMAND_USER)
    class HelloWorld(gdb.Command):
      '''Greet the whole world.'''
 
      def invoke(self, arg, from_tty):
        print("Hello, World!")
    """
 
    def wrapper(cls):
        # A GDB command is registered by calling gdb.Command.__init__(). We construct an instance of
        # 'cls' so the command is automatically registered as a result of decorating a class with
        # the register() function.
        cls(name, command_class, **kwargs)
        return cls
    return wrapper

CC mark.benvenuto, redbeard0531



 Comments   
Comment by Steven Vannelli [ 10/May/22 ]

Moving this ticket to the Backlog and removing the "Backlog" fixVersion as per our latest policy for using fixVersions.

Generated at Thu Feb 08 04:17:32 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.