From 9462d332dcd4ee871f3e07c59e5482aebb043ada Mon Sep 17 00:00:00 2001 From: Darren Ranalli Date: Thu, 29 Apr 2010 01:25:11 +0000 Subject: [PATCH] upload client stack dump to event logs --- direct/src/showbase/ExceptionVarDump.py | 35 ++++++++++++++++++++----- direct/src/showbase/ShowBase.py | 7 +++-- direct/src/task/Task.py | 2 +- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/direct/src/showbase/ExceptionVarDump.py b/direct/src/showbase/ExceptionVarDump.py index ddc2216353..8601fb0242 100755 --- a/direct/src/showbase/ExceptionVarDump.py +++ b/direct/src/showbase/ExceptionVarDump.py @@ -64,20 +64,22 @@ def _varDump__print(exc): oldExcepthook = None # store these values here so that Task.py can always reliably access them # from its main exception handler -wantVariableDump = False +wantStackDumpLog = False +wantStackDumpUpload = False +variableDumpReasons = [] dumpOnExceptionInit = False class _AttrNotFound: pass def _excepthookDumpVars(eType, eValue, tb): - excStrs = traceback.format_exception(eType, eValue, tb) + origTb = tb + excStrs = traceback.format_exception(eType, eValue, origTb) s = 'printing traceback in case variable repr crashes the process...\n' for excStr in excStrs: s += excStr notify.info(s) s = 'DUMPING STACK FRAME VARIABLES' - origTb = tb #import pdb;pdb.set_trace() #foundRun = False foundRun = True @@ -158,15 +160,34 @@ def _excepthookDumpVars(eType, eValue, tb): if foundRun: s += '\n' - notify.info(s) + if wantStackDumpLog: + notify.info(s) + if wantStackDumpUpload: + excStrs = traceback.format_exception(eType, eValue, origTb) + for excStr in excStrs: + s += excStr + timeMgr = None + try: + timeMgr = base.cr.timeManager + except: + try: + timeMgr = simbase.air.timeManager + except: + pass + if timeMgr: + timeMgr.setStackDump(s) + oldExcepthook(eType, eValue, origTb) -def install(): +def install(log, upload): global oldExcepthook - global wantVariableDump + global wantStackDumpLog + global wantStackDumpUpload global dumpOnExceptionInit - wantVariableDump = True + wantStackDumpLog = log + wantStackDumpUpload = upload + dumpOnExceptionInit = config.GetBool('variable-dump-on-exception-init', 0) if dumpOnExceptionInit: # this mode doesn't completely work because exception objects diff --git a/direct/src/showbase/ShowBase.py b/direct/src/showbase/ShowBase.py index 8c0f1192ba..c7d06bb25a 100644 --- a/direct/src/showbase/ShowBase.py +++ b/direct/src/showbase/ShowBase.py @@ -56,8 +56,11 @@ class ShowBase(DirectObject.DirectObject): def __init__(self, fStartDirect = True, windowType = None): __builtin__.__dev__ = config.GetBool('want-dev', 0) - if config.GetBool('want-variable-dump', 0): - ExceptionVarDump.install() + logStackDump = (config.GetBool('log-stack-dump', 0) or + config.GetBool('client-log-stack-dump', 0)) + uploadStackDump = config.GetBool('upload-stack-dump', (not __dev__)) + if logStackDump or uploadStackDump: + ExceptionVarDump.install(logStackDump, uploadStackDump) # Locate the directory containing the main program self.mainDir = ExecutionEnvironment.getEnvironmentVariable("MAIN_DIR") diff --git a/direct/src/task/Task.py b/direct/src/task/Task.py index 84df84f5cb..83d9cdfbee 100644 --- a/direct/src/task/Task.py +++ b/direct/src/task/Task.py @@ -519,7 +519,7 @@ class TaskManager: self.stop() print_exc_plus() else: - if (ExceptionVarDump.wantVariableDump and + if (ExceptionVarDump.wantStackDumpLog and ExceptionVarDump.dumpOnExceptionInit): ExceptionVarDump._varDump__print(e) raise