Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-28233

Split up gdb/mongo.py into separate modules and support auto-registration via pkgutil

    • Server Tooling & Methods

      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

            Assignee:
            backlog-server-stm Backlog - Server Tooling and Methods (STM) (Inactive)
            Reporter:
            max.hirschhorn@mongodb.com Max Hirschhorn
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: