diff options
author | Spencer T Brody <spencer@10gen.com> | 2020-04-07 13:43:17 -0700 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-04-07 21:12:37 +0000 |
commit | 3fc737f00d47fd2c59683579119c2083541ea5a2 (patch) | |
tree | 7affa1cfb3129d647e0184dd6e595d1df369864b /buildscripts/gdb | |
parent | 021db11a119f431d25afef650735cbf61a823a40 (diff) | |
download | mongo-3fc737f00d47fd2c59683579119c2083541ea5a2.tar.gz |
SERVER-45133 Dump mutex info in hang analyzer
Diffstat (limited to 'buildscripts/gdb')
-rw-r--r-- | buildscripts/gdb/mongo.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/buildscripts/gdb/mongo.py b/buildscripts/gdb/mongo.py index b1190231d53..baf0c9c1bbd 100644 --- a/buildscripts/gdb/mongo.py +++ b/buildscripts/gdb/mongo.py @@ -1,5 +1,7 @@ """GDB commands for MongoDB.""" +import datetime +import json import os import re import sys @@ -15,6 +17,7 @@ try: path = os.path.dirname(os.path.dirname(os.path.dirname(printers))) sys.path.insert(0, path) from libstdcxx.v6 import register_libstdcxx_printers + from libstdcxx.v6 import printers as stdlib_printers register_libstdcxx_printers(gdb.current_objfile()) print("Loaded libstdc++ pretty printers from '%s'" % printers) except Exception as e: @@ -349,6 +352,50 @@ class DumpMongoDSessionCatalog(gdb.Command): DumpMongoDSessionCatalog() +class DumpMongoDBMutexes(gdb.Command): + """Print out the state of mutexes in a mongodb (mongod or mongos) process.""" + + def __init__(self): + """Initialize DumpMongoDBMutexs.""" + RegisterMongoCommand.register(self, "mongodb-dump-mutexes", gdb.COMMAND_DATA) + + def invoke(self, args, _from_tty): # pylint: disable=unused-argument,no-self-use,too-many-locals,too-many-branches,too-many-statements + """Invoke DumpMongoDBMutexes.""" + + print("Dumping mutex info for all Clients") + + service_context = get_global_service_context() + client_set = absl_get_nodes(service_context["_clients"]) # pylint: disable=undefined-variable + for client_handle in client_set: + client = client_handle.dereference().dereference() + diagnostic_info_handle = get_decoration(client, "DiagnosticInfo")[1] + diagnostic_info_list = diagnostic_info_handle["list"] + + # Use the STL pretty-printer to iterate over the list + printer = stdlib_printers.StdForwardListPrinter( + str(diagnostic_info_list.type), diagnostic_info_list) + + # Prepare structured output doc + client_name = str(client["_desc"]) + # Chop off the "\"" from the beginning and end of the string + client_name = client_name[1:-1] + output_doc = {"client": client_name, "waiting": False} + + # This list will only ever have 0 or 1 element in it + for _, diag_info in printer.children(): + output_doc["waiting"] = True + output_doc["mutex"] = str(diag_info["_captureName"])[1:-1] + + millis = int(diag_info["_timestamp"]["millis"]) + dt = datetime.datetime.fromtimestamp(millis / 1000, tz=datetime.timezone.utc) + output_doc["since"] = dt.isoformat() + print(json.dumps(output_doc)) + + +# Register command +DumpMongoDBMutexes() + + class MongoDBDumpLocks(gdb.Command): """Dump locks in mongod process.""" |