Skip to content

Instantly share code, notes, and snippets.

@visualzhou
Last active August 31, 2019 00:06
Show Gist options
  • Save visualzhou/2d5661acb7a538350991b3afcf229de7 to your computer and use it in GitHub Desktop.
Save visualzhou/2d5661acb7a538350991b3afcf229de7 to your computer and use it in GitHub Desktop.
Set up a spawnhost automatically
set print static-members off
set print pretty on
set pagination off
python
import os, sys, glob
pp = glob.glob("/opt/mongodbtoolchain/v3/share/gcc-*/python/libstdcxx/v6/printers.py")
printers = pp[0]
path = os.path.dirname(os.path.dirname(os.path.dirname(printers)))
sys.path.insert(0, path)
from libstdcxx.v6 import register_libstdcxx_printers
register_libstdcxx_printers(gdb.current_objfile())
print("Loaded libstdc++ pretty printers from '%s'" % printers)
end
python
import sys
sys.path.insert(1, './Boost-Pretty-Printer')
import boost
boost.register_printers(boost_version=(1,60,0))
end
source buildscripts/gdb/mongo.py
source buildscripts/gdb/mongo_lock.py
source buildscripts/gdb/mongo_printers.py
python
from bson import ObjectId
import datetime
import re
oid_re = re.compile("""^(?:ObjectId\(['"])?([0-9a-f]{24})(?:['"]\))?$""")
ts_re = re.compile("(\d+), (\d+)")
hex_re = re.compile("^([0-9a-f]+):([0-9a-f]{2})$")
all_hex_re = re.compile('^([0-9A-Fa-f]{1,8})([0-9A-Fa-f]{8})$')
"""
accepts anything of the form:
6483433440334053560
`Timestamp(1509541981, 44)`, `(1509541981, 44)`, `1509541981, 44`
'59f9c740:d1'
'5A15B1B000001B79'
ObjectId('5b0848e633e9bc492d197886'), '5b0848e633e9bc492d197886'
"""
def ts(v):
# expects ts as int in seconds.
def _norm(ts, inc):
dt = datetime.datetime.utcfromtimestamp(ts)
return "Timestamp({}, {}) -> {} -> {:x}:{:x} -> {} -> ObjectId('{}')".format(ts, inc, ((ts << 32) + inc), ts, inc, dt.isoformat(), ObjectId.from_datetime(dt))
if type(v) == int:
print("number")
return _norm(v>>32, v % (1<<32))
if oid_re.findall(str(v)):
print("oid_re")
capture = oid_re.findall(v)[0]
oid = ObjectId(capture)
return _norm(int(oid.generation_time.strftime("%s")), 0)
if ts_re.findall(str(v)):
print("ts_re")
ts, inc = ts_re.findall(v)[0]
return _norm(int(ts), int(inc))
if hex_re.findall(str(v)):
print("hex_re")
ts, inc = hex_re.findall(v)[0]
return _norm(int(ts, 16), int(inc, 16))
if all_hex_re.findall(str(v)):
print("all_hex_re")
ts, inc = all_hex_re.findall(str(v))[0]
return _norm(int(ts, 16), int(inc, 16))
return "Unknown"
end
#!/bin/bash
cd /data/mci
BIN_ARCHIVE=`ls /data/mci/artifacts-*compile/mongo-mongodb*.tgz`
tar --wildcards --strip-components=2 -xzf $BIN_ARCHIVE '*/bin/mongod' &
DBG_ARCHIVE=`ls /data/mci/artifacts-*compile/debugsymbols*.tgz`
tar --wildcards --strip-components=1 -xzf $DBG_ARCHIVE '*/mongod.debug' &
SRC_DIR=`find /data/mci/ -maxdepth 1 | grep source`
ln -s $SRC_DIR/src src
ln -s $SRC_DIR/buildscripts buildscripts
COREDUMP_ARCHIVE=`find /data/mci/ | grep artifacts | grep coredumps`
tar -xzf $COREDUMP_ARCHIVE &
set +x
echo "Waiting for background tar processes to complete."
while [ `ps | grep tar | wc -l` -gt 0 ]; do
sleep 1
done
# Strip the "bin" directory of debug symbol if it exists (after SERVER-41672)
if [ -e bin/mongod.debug ]
then
mv bin/mongod.debug .
fi
git clone git@github.com:ruediger/Boost-Pretty-Printer.git
echo "set auto-load safe-path /" >> ~/.gdbinit
export SOURCE_PATH=$(find /data/mci -name source*)
SCRIPT_GIT_PATH=https://gist.githubusercontent.com/visualzhou/2d5661acb7a538350991b3afcf229de7/raw
curl -o /data/mci/.gdbinit $SCRIPT_GIT_PATH/.gdbinit
/opt/mongodbtoolchain/v3/bin/python3 -m pip install -r /data/mci/buildscripts/requirements.txt
echo "Analyze core dumps with one of the following commands:"
for f in dump*; do
echo "/opt/mongodbtoolchain/gdb/bin/gdb ./mongod ./$f"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment