コード例 #1
0
    def formatException(self, ei):
        etype, exc, tb = ei
        exception_list = traceback2.extract_tb(tb, extract_locals=True)
        if tb:
            caught_list = traceback2.extract_stack(tb.tb_frame)
        else:
            caught_list = traceback2.extract_stack(up=2)
        formatted_exception = traceback2.format_exception_only(etype, exc)
        stack, stackID = GetStack(exception_list,
                                  caught_list,
                                  show_locals=True)
        sio = cStringIO.StringIO()
        for line in stack:
            sio.write(line)

        for line in formatted_exception:
            sio.write(line)

        self._LogThreadLocals(sio)
        self._LogServerInfo(sio)
        try:
            sio.write('Stackhash: {}\n'.format(stackID[0]))
        except Exception:
            pass

        s = sio.getvalue()
        sio.close()
        return s
コード例 #2
0
def OldLockReport(threshold = None, out = None):
    if out is None:
        out = sys.stdout
    now = blue.os.GetWallclockTime()
    result = False
    import uthread
    for each in lockManager.GetLocks():
        if threshold is None or each.LockedAt() and (now - each.LockedAt()) * 1e-07 >= threshold:
            waiting = each.WaitingTasklets()
            if not waiting:
                continue
            result = True
            holding = each.HoldingTasklets()
            if each.LockedAt():
                dt = (now - each.LockedAt()) * 1e-07
            else:
                dt = -1
            print >> out, 'Semaphore %r has been held up for a long time (%ss).' % (each, dt)
            for t in waiting:
                print >> out, 'waiting thread: %r' % t
                if False:
                    try:
                        for s in traceback.format_list(traceback.extract_stack(t.frame, 40)):
                            print >> out, s,

                    except:
                        sys.exc_clear()

            for t in holding:
                print >> out, 'holding thread: %r' % t
                try:
                    for s in traceback.format_list(traceback.extract_stack(t.frame, 40)):
                        print >> out, s,

                except:
                    sys.exc_clear()

                if t.paused:
                    print >> out, "Holding thread is paused, let's restart it!!!  Oh, and tell Kristjan"
                    try:
                        t.insert()
                        print >> out, 'unpaused.'
                    except:
                        sys.exc_clear()

                elif not t.alive:
                    print >> out, 'Holding thread is dead.  Just release the semaphore and tell Kristjan'
                    if hasattr(each, 'Unblock'):
                        each.Unblock()
                        print >> out, 'semaphore released'
                    else:
                        try:
                            each.release(True)
                            print >> out, 'semaphore released'
                        except:
                            sys.exc_clear()

    return result
コード例 #3
0
ファイル: runner.py プロジェクト: kasiluote/behave
    def __setattr__(self, attr, value):
        if attr[0] == "_":
            self.__dict__[attr] = value
            return

        for frame in self._stack[1:]:
            if attr in frame:
                record = self._record[attr]
                params = {
                    "attr": attr,
                    "filename": record[0],
                    "line": record[1],
                    "function": record[3],
                }
                self._emit_warning(attr, params)

        stack_limit = 2
        if six.PY2:
            stack_limit += 1  # Due to traceback2 usage.
        stack_frame = traceback.extract_stack(limit=stack_limit)[0]
        self._record[attr] = stack_frame
        frame = self._stack[0]
        frame[attr] = value
        if attr not in self._origin:
            self._origin[attr] = self._mode
コード例 #4
0
ファイル: runner.py プロジェクト: Abdoctor/behave
    def __setattr__(self, attr, value):
        if attr[0] == "_":
            self.__dict__[attr] = value
            return

        for frame in self._stack[1:]:
            if attr in frame:
                record = self._record[attr]
                params = {
                    "attr": attr,
                    "filename": record[0],
                    "line": record[1],
                    "function": record[3],
                }
                self._emit_warning(attr, params)

        stack_limit = 2
        if six.PY2:
            stack_limit += 1     # Due to traceback2 usage.
        stack_frame = traceback.extract_stack(limit=stack_limit)[0]
        self._record[attr] = stack_frame
        frame = self._stack[0]
        frame[attr] = value
        if attr not in self._origin:
            self._origin[attr] = self._mode
コード例 #5
0
 def ReportThread(self, tid, frame):
     report = ['Thread %d:\n' % tid]
     if hasattr(frame, 'f_lineno'):
         stack = traceback.extract_stack(frame)
         report.extend(traceback.format_list(stack))
     else:
         report.append('No stack\n')
     return report
コード例 #6
0
def WhoCalledMe(up = 3):
    try:
        trc = traceback2.extract_stack(limit=1, up=up)[0]
        fileName = os.path.basename(trc[0])
        lineNum = trc[1]
        funcName = trc[2]
        ret = '%s(%s) in %s' % (fileName, lineNum, funcName)
    except:
        ret = 'unknown'

    return ret
コード例 #7
0
def WhoCalledMe(up=3):
    try:
        trc = traceback2.extract_stack(limit=1, up=up)[0]
        fileName = os.path.basename(trc[0])
        lineNum = trc[1]
        funcName = trc[2]
        ret = '%s(%s) in %s' % (fileName, lineNum, funcName)
    except:
        ret = 'unknown'

    return ret
コード例 #8
0
def LogTraceback(extraText='',
                 channel='general',
                 toConsole=1,
                 toAlertSvc=None,
                 toLogServer=1,
                 nthParent=0,
                 daStack=None,
                 severity=ERR,
                 show_locals=1,
                 limit=None):
    global traceID
    if logExceptionLevel > 0:
        return
    _tmpctx = blue.pyos.taskletTimer.EnterTasklet('Logging::LogTraceback')
    try:
        if daStack is None:
            daStack = traceback2.extract_stack(limit=limit,
                                               up=nthParent + 1,
                                               extract_locals=show_locals)
        if toAlertSvc is None:
            toAlertSvc = severity in (ERR, )
        stack, stackID = GetStack(daStack, None, show_locals, True)
        out = GetMultiplex(channel, severity, [toConsole, 0][toLogServer == 1],
                           toLogServer, 0, toAlertSvc, stackID)
        tmpTraceID = traceID
        traceID += 1
        logMessage = StringIO()
        logMessage.write(
            'STACKTRACE #%d logged at %s %s' %
            (tmpTraceID, blue.os.FormatUTC()[0], blue.os.FormatUTC()[2]))
        logMessage.write('\n')
        if extraText:
            logMessage.write(extraText)
            logMessage.write('\n')
        for line in stack:
            logMessage.write(line)

        _LogThreadLocals(logMessage)
        logMessage.write('STACKTRACE END')
        print >> out, logMessage.getvalue()
        out.flush()
        if toConsole:
            if toLogServer:
                if '/jessica' in blue.pyos.GetArg():
                    print >> sys.stderr, logMessage.getvalue()
                else:
                    print >> sys.stderr, 'A traceback has been generated.  It has been logged in the log server as stacktrace #%d' % tmpTraceID
            else:
                print >> sys.stderr, 'There is no useful information accompanying this traceback in the log server'
    finally:
        blue.pyos.taskletTimer.ReturnFromTasklet(_tmpctx)
コード例 #9
0
def LogTraceback(extraText='',
                 channel='general',
                 toConsole=1,
                 toAlertSvc=None,
                 toLogServer=1,
                 nthParent=0,
                 daStack=None,
                 severity=ERR,
                 show_locals=1,
                 limit=None):
    if logExceptionLevel > 0:
        return
    _tmpctx = blue.pyos.taskletTimer.EnterTasklet('logmodule::LogTraceback')
    try:
        if daStack is None:
            daStack = traceback2.extract_stack(limit=limit,
                                               up=nthParent + 1,
                                               extract_locals=show_locals)
        stack, stackID = GetStack(daStack, None, show_locals, True)
        if toAlertSvc is None:
            toAlertSvc = severity in (ERR, )
        toMsgWindow = False
        multiplexToConsole = False if toLogServer else toConsole
        out = GetMultiplex(channel, severity, multiplexToConsole, toLogServer,
                           toMsgWindow, toAlertSvc, stackID)
        traceID = NextTraceID()
        logMessage = StringIO()
        logMessage.write('STACKTRACE #%d logged at %s %s : %s\n' %
                         (traceID, blue.os.FormatUTC()[0],
                          blue.os.FormatUTC()[2], extraText))
        logMessage.write(' \n')
        for line in stack:
            logMessage.write(line)

        logMessage.write(' \n')
        _LogThreadLocals(logMessage)
        logMessage.write('Stackhash: %s\n' % stackID[0])
        logMessage.write('Reported from: ' + __name__ + '\n')
        logMessage.write('STACKTRACE END')
        print >> out, logMessage.getvalue()
        out.flush()
        if toConsole:
            if toLogServer:
                if '/jessica' in blue.pyos.GetArg():
                    print >> sys.stderr, '#nolog: ' + logMessage.getvalue()
                else:
                    print >> sys.stderr, '#nolog: A traceback has been generated. It has been logged in the log server as stacktrace #%d' % traceID
            else:
                print >> sys.stderr, 'There is no useful information accompanying this traceback in the log server'
    finally:
        blue.pyos.taskletTimer.ReturnFromTasklet(_tmpctx)
コード例 #10
0
    def CallDown(self, packet):
        try:
            return self.ForwardCallDown(packet)
        except UnMachoDestination as e:
            if getattr(packet.destination, 'nodeID', None):
                if packet.destination.nodeID < const.maxNodeID and macho.mode == 'server':
                    self.machoNet.HandleUnMachoDestination(packet.destination.nodeID, packet)
            raise 
        except MachoWrappedException as e:
            serverStack = None
            if len(e.payload) > 1:
                clientStack, clientStackKey = log.GetStack(traceback2.extract_stack())
                serverStack = e.payload[1][1]
                serverStackVariables = e.payload[1][2]
                fullReport = []
                fullReport.append('<-- top of local (%s) info -->\n' % macho.mode)
                fullReport += clientStack
                fullReport.append('<-- here we crossed the wire -->\n')
                fullReport += serverStack
                fullReport += serverStackVariables
                fullReport.append('<-- bottom of remote (%s) info -->\n' % e.payload[1][6])
                if e.payload[1][0]:
                    filefunc = self.machoNet.LogfileError
                    level = log.LGERR
                    m = 'Error'
                else:
                    filefunc = self.machoNet.LogfileWarn
                    m = 'Warning'
                with filefunc() as f:
                    print >> f, 'Exception traceback, origin %s:' % e.payload[1][3]
                    for each in fullReport:
                        print >> f, each,

                fullReport = ''.join(fullReport)
                serverStackKey = e.payload[1][4]
                combinedStack = clientStackKey[1] + serverStackKey[1]
                combinedStackKey = [zlib.adler32(combinedStack), combinedStack]
                sm.GetService('alert').SendStackTraceAlert(combinedStackKey, fullReport, m, nextErrorKeyHash=serverStackKey[0], nodeID=e.payload[1][5])
                if macho.mode == 'client':
                    windowStream = log.MsgWindowStream()
                    if windowStream:
                        print >> windowStream, 'Exception Traceback-'
                        print >> windowStream, fullReport,
                        windowStream.flush()
            newException = macho.LoadsSanitized(e.payload[0])
            if prefs.clusterMode in ('LOCAL', 'TEST', 'MASTER'):
                if 'proxy' == macho.mode and prefs.GetValue('crestSendExceptionsToClient', 0):
                    newException.serverStack = serverStack
            raise newException
コード例 #11
0
def WhoCalledMe(up=3):
    """
        return a textual string to tell us who the caller of a specific function is
        This allows developers to quickly write out who the caller of a specific function is
        without having to StackTrace() it.
        The format is the same as for exceptions for easy grepping: 
        [file name]([line number]) in [function name]
        example: "assetinfo.py(173) in GetAllAssets"
    """
    try:
        trc = traceback2.extract_stack(limit=1, up=up)[0]
        fileName = os.path.basename(trc[0])
        lineNum = trc[1]
        funcName = trc[2]
        ret = '%s(%s) in %s' % (fileName, lineNum, funcName)
    except:
        ret = 'unknown'

    return ret
コード例 #12
0
def LogTraceback(extraText = '', channel = 'general', toConsole = 1, toAlertSvc = None, toLogServer = 1, nthParent = 0, daStack = None, severity = ERR, show_locals = 1, limit = None):
    if logExceptionLevel > 0:
        return
    _tmpctx = blue.pyos.taskletTimer.EnterTasklet('logmodule::LogTraceback')
    try:
        if daStack is None:
            daStack = traceback2.extract_stack(limit=limit, up=nthParent + 1, extract_locals=show_locals)
        stack, stackID = GetStack(daStack, None, show_locals, True)
        if toAlertSvc is None:
            toAlertSvc = severity in (ERR,)
        toMsgWindow = False
        multiplexToConsole = False if toLogServer else toConsole
        out = GetMultiplex(channel, severity, multiplexToConsole, toLogServer, toMsgWindow, toAlertSvc, stackID)
        traceID = NextTraceID()
        logMessage = StringIO()
        logMessage.write('STACKTRACE #%d logged at %s %s : %s\n' % (traceID,
         blue.os.FormatUTC()[0],
         blue.os.FormatUTC()[2],
         extraText))
        logMessage.write(' \n')
        for line in stack:
            logMessage.write(line)

        logMessage.write(' \n')
        _LogThreadLocals(logMessage)
        logMessage.write('Stackhash: %s\n' % stackID[0])
        logMessage.write('Reported from: ' + __name__ + '\n')
        logMessage.write('STACKTRACE END')
        print >> out, logMessage.getvalue()
        out.flush()
        if toConsole:
            if toLogServer:
                if '/jessica' in blue.pyos.GetArg():
                    print >> sys.stderr, '#nolog: ' + logMessage.getvalue()
                else:
                    print >> sys.stderr, '#nolog: A traceback has been generated. It has been logged in the log server as stacktrace #%d' % traceID
            else:
                print >> sys.stderr, 'There is no useful information accompanying this traceback in the log server'
    finally:
        blue.pyos.taskletTimer.ReturnFromTasklet(_tmpctx)
コード例 #13
0
ファイル: log.py プロジェクト: Pluckyduck/eve
def LogTraceback(extraText = '', channel = 'general', toConsole = 1, toAlertSvc = None, toLogServer = 1, nthParent = 0, daStack = None, severity = ERR, show_locals = 1, limit = None):
    global traceID
    if logExceptionLevel > 0:
        return
    _tmpctx = blue.pyos.taskletTimer.EnterTasklet('Logging::LogTraceback')
    try:
        if daStack is None:
            daStack = traceback2.extract_stack(limit=limit, up=nthParent + 1, extract_locals=show_locals)
        if toAlertSvc is None:
            toAlertSvc = severity in (ERR,)
        stack, stackID = GetStack(daStack, None, show_locals, True)
        out = GetMultiplex(channel, severity, [toConsole, 0][toLogServer == 1], toLogServer, 0, toAlertSvc, stackID)
        tmpTraceID = traceID
        traceID += 1
        logMessage = StringIO()
        logMessage.write('STACKTRACE #%d logged at %s %s' % (tmpTraceID, blue.os.FormatUTC()[0], blue.os.FormatUTC()[2]))
        logMessage.write('\n')
        if extraText:
            logMessage.write(extraText)
            logMessage.write('\n')
        for line in stack:
            logMessage.write(line)

        _LogThreadLocals(logMessage)
        logMessage.write('STACKTRACE END')
        print >> out, logMessage.getvalue()
        out.flush()
        if toConsole:
            if toLogServer:
                if '/jessica' in blue.pyos.GetArg():
                    print >> sys.stderr, logMessage.getvalue()
                else:
                    print >> sys.stderr, 'A traceback has been generated.  It has been logged in the log server as stacktrace #%d' % tmpTraceID
            else:
                print >> sys.stderr, 'There is no useful information accompanying this traceback in the log server'
    finally:
        blue.pyos.taskletTimer.ReturnFromTasklet(_tmpctx)
コード例 #14
0
def _LogException(exc_info, extraText, channel, toConsole, toLogServer, toAlertSvc, toMsgWindow, severity, show_locals):
    exctype, exc, tb = exc_info
    exception_list = traceback2.extract_tb(tb, extract_locals=show_locals)
    if tb:
        caught_list = traceback2.extract_stack(tb.tb_frame)
    else:
        caught_list = traceback2.extract_stack(up=2)
    stack, stackID = GetStack(exception_list, caught_list, show_locals=show_locals)
    if severity is None:
        severity = (ERR, WARN)[isinstance(exc, UserError)]
    if toAlertSvc is None:
        toAlertSvc = severity in (ERR,)
    if toMsgWindow and isinstance(exc, UserError) and boot.role == 'client':
        toMsgWindow = 0
        uiMessageFunc(*exc.args)
    multiplexToConsole = False if toLogServer else toConsole
    out = GetMultiplex(channel, severity, multiplexToConsole, toLogServer, toMsgWindow, toAlertSvc, stackID)
    formatted_exception = traceback2.format_exception_only(exctype, exc)
    if not extraText:
        try:
            extraText = 'Info: %s' % formatted_exception[-1].strip()
        except:
            extraText = 'Info: <none>'

    prefix = 'REMOTE ' if channel == 'remote.exc' else ''
    traceID = NextTraceID()
    print >> out, '%sEXCEPTION #%d logged at %s %s : %s ' % (prefix,
     traceID,
     blue.os.FormatUTC()[0],
     blue.os.FormatUTC()[2],
     extraText)
    print >> out, ' '
    print >> out, 'Formatted exception info:',
    for line in formatted_exception:
        print >> out, line,

    print >> out, ' '
    for line in stack:
        print >> out, line,

    print >> out, ' '
    if exctype is MemoryError:
        try:
            DumpMemoryStatus(out)
            DumpMemHistory(out)
        except:
            pass

    try:
        _LogThreadLocals(out)
    except MemoryError:
        pass

    if boot.role != 'client':
        try:
            ram = blue.sysinfo.GetMemory().pageFile / 1024 / 1024
            cpuLoad = sm.GetService('machoNet').GetCPULoad()
            memLeft = blue.sysinfo.GetMemory().availablePhysical / 1024 / 1024
            txt = 'System Information: '
            txt += ' Node ID: %s' % sm.GetService('machoNet').GetNodeID()
            if boot.role == 'server':
                txt += ' | Node Name: %s' % sm.GetService('machoNet').GetLocalHostName()
            txt += ' | Total CPU load: %s%%' % int(cpuLoad)
            txt += ' | Process memory in use: %s MB' % ram
            txt += ' | Physical memory left: %s MB' % memLeft
            print >> out, txt
        except Exception as e:
            sys.exc_clear()

    try:
        print >> out, 'Stackhash: %s' % stackID[0]
    except Exception:
        pass

    print >> out, 'Reported from: ', __name__
    print >> out, '%sEXCEPTION END' % (prefix,)
    out.flush()
    if toConsole:
        if toLogServer:
            print >> sys.stderr, '#nolog: An exception has occurred. It has been logged in the log server as exception #%d' % traceID
        else:
            print >> sys.stderr, 'There is no useful information accompanying this exception in the log server'
コード例 #15
0
ファイル: log.py プロジェクト: Pluckyduck/eve
def _LogException(exc_info, extraText, channel, toConsole, toLogServer, toAlertSvc, toMsgWindow, severity, show_locals):
    global traceID
    exctype, exc, tb = exc_info
    exception_list = traceback2.extract_tb(tb, extract_locals=show_locals)
    if tb:
        caught_list = traceback2.extract_stack(tb.tb_frame)
    else:
        caught_list = traceback2.extract_stack(up=2)
    formatted_exception = traceback2.format_exception_only(exctype, exc)
    stack, stackID = GetStack(exception_list, caught_list, show_locals=show_locals)
    if severity is None:
        severity = (ERR, WARN)[isinstance(exc, UserError)]
    if toAlertSvc is None:
        toAlertSvc = severity in (ERR,)
    if toMsgWindow and isinstance(exc, UserError) and boot.role == 'client':
        toMsgWindow = 0
        uiMessageFunc(*exc.args)
    out = GetMultiplex(channel, severity, [toConsole, 0][toLogServer == 1], toLogServer, toMsgWindow, toAlertSvc, stackID)
    pre = ('', 'REMOTE')[channel == 'remote.exc']
    tmpTraceID = traceID
    traceID += 1
    print >> out, '%sEXCEPTION #%d logged at ' % (pre, tmpTraceID), blue.os.FormatUTC()[0], blue.os.FormatUTC()[2], extraText
    for line in stack:
        print >> out, line,

    for line in formatted_exception:
        print >> out, line,

    if exctype is MemoryError:
        try:
            DumpMemoryStatus(out)
            DumpMemHistory(out)
        except:
            pass

    try:
        _LogThreadLocals(out)
    except MemoryError:
        pass

    try:
        print >> out, 'Stackhash:%s\n' % stackID[0]
    except Exception:
        pass

    print >> out
    if boot.role != 'client':
        try:
            nodeID = getattr(sm.services['machoNet'], 'nodeID', None)
            ram = blue.win32.GetProcessMemoryInfo()['PagefileUsage'] / 1024 / 1024
            cpuLoad = sm.GetService('machoNet').GetCPULoad()
            m = blue.win32.GlobalMemoryStatus()
            memLeft = m['AvailPhys'] / 1024 / 1024
            txt = 'System Information: '
            txt += ' Node ID: %s' % sm.GetService('machoNet').GetNodeID()
            if boot.role == 'server':
                txt += ' | Node Name: %s' % sm.GetService('machoNet').GetNodeName()
            txt += ' | Total CPU load: %s%%' % int(cpuLoad)
            txt += ' | Process memory in use: %s MB' % ram
            txt += ' | Physical memory left: %s MB' % memLeft
            print >> out, txt
        except Exception as e:
            sys.exc_clear()

    print >> out, '%sEXCEPTION END' % (pre,)
    out.flush()
    if toConsole:
        if toLogServer:
            print >> sys.stderr, 'An exception has occurred.  It has been logged in the log server as exception #%d' % tmpTraceID
        else:
            print >> sys.stderr, 'There is no useful information accompanying this exception in the log server'
コード例 #16
0
def LockCycleReport(graph = None, out = None, timeLimit = None, pathLimit = 10):
    if not graph:
        g = GetDependencyGraph()
    else:
        g = graph
    if out is None:
        out = sys.stdout
    cycles = g.FindCycles()
    roots = g.FindRoots()
    npaths = 0
    paths = []
    for r in roots:
        p = g.PathsFrom(r)
        npaths += len(p)
        longest = max(p, key=lambda e: len(e))
        paths.append(longest)

    def PathTime(p):
        return sum((getattr(g[n], 'time', 0) for n in p))

    pathtimes = [ (p, PathTime(p)) for p in paths ]
    if timeLimit:
        pathtimes = [ (p, t) for p, t in pathtimes if t is None or t > timeLimit ]
    if not cycles and not pathtimes:
        return False
    pathtimes.sort(key=lambda e: (e[1], len(e[0])), reverse=True)
    if pathLimit:
        del pathtimes[pathLimit:]
    paths = [ p for p, t in pathtimes ]
    pathtimes = [ t for p, t in pathtimes ]
    players = []
    seen = set()
    for p in cycles + paths:
        for n in p:
            if n not in seen:
                seen.add(n)
                players.append(n)

    nc = 0
    map = {}
    for p in players:
        map[p] = 'N%d' % nc
        nc += 1

    print >> out, 'Found %s cycles' % len(cycles)
    for i, cycle in enumerate(cycles):
        print >> out, '%2d: ' % i,
        for e in cycle:
            print >> out, '%s -> ' % map[e],

        print >> out

    print >> out, 'Found %s roots in %s paths (showing longest path for each root)' % (len(paths), npaths)
    for i, path in enumerate(paths):
        time = pathtimes[i]
        if time is not None:
            print >> out, '%2d, t=%4.0fs: ' % (i, time),
        else:
            print >> out, '%2d,        : ' % (i,),
        for e in path[:-1]:
            print >> out, '%s -> ' % map[e],

        print >> out, '%s' % map[path[-1]]

    minimum = 0
    if cycles:
        minimum = max(minimum, len(cycles[0]))
    if paths:
        minimum = max(minimum, len(paths[0]))
    maximum = max(minimum, 10)
    print >> out, 'where:'
    for v in players[0:maximum]:
        k = map[v]
        print >> out, ' %3s = %r' % (k, v)
        if stackless and isinstance(v, stackless.tasklet):
            try:
                if not v.alive:
                    print >> out, 'dead'
                elif v.frame:
                    for s in traceback.format_list(traceback.extract_stack(v.frame, 40), format=FORMAT):
                        print >> out, '       ' + s,

                else:
                    print >> out, 'no frame'
            except:
                pass

    return True
コード例 #17
0
def LockCycleReport(graph=None, out=None, timeLimit=None, pathLimit=10):
    if not graph:
        g = GetDependencyGraph()
    else:
        g = graph
    if out is None:
        out = sys.stdout
    cycles = g.FindCycles()
    roots = g.FindRoots()
    npaths = 0
    paths = []
    for r in roots:
        p = g.PathsFrom(r)
        npaths += len(p)
        longest = max(p, key=lambda e: len(e))
        paths.append(longest)

    def PathTime(p):
        return sum((getattr(g[n], 'time', 0) for n in p))

    pathtimes = [(p, PathTime(p)) for p in paths]
    if timeLimit:
        pathtimes = [(p, t) for p, t in pathtimes
                     if t is None or t > timeLimit]
    if not cycles and not pathtimes:
        return False
    pathtimes.sort(key=lambda e: (e[1], len(e[0])), reverse=True)
    if pathLimit:
        del pathtimes[pathLimit:]
    paths = [p for p, t in pathtimes]
    pathtimes = [t for p, t in pathtimes]
    players = []
    seen = set()
    for p in cycles + paths:
        for n in p:
            if n not in seen:
                seen.add(n)
                players.append(n)

    nc = 0
    map = {}
    for p in players:
        map[p] = 'N%d' % nc
        nc += 1

    print >> out, 'Found %s cycles' % len(cycles)
    for i, cycle in enumerate(cycles):
        print >> out, '%2d: ' % i,
        for e in cycle:
            print >> out, '%s -> ' % map[e],

        print >> out

    print >> out, 'Found %s roots in %s paths (showing longest path for each root)' % (
        len(paths), npaths)
    for i, path in enumerate(paths):
        time = pathtimes[i]
        if time is not None:
            print >> out, '%2d, t=%4.0fs: ' % (i, time),
        else:
            print >> out, '%2d,        : ' % (i, ),
        for e in path[:-1]:
            print >> out, '%s -> ' % map[e],

        print >> out, '%s' % map[path[-1]]

    minimum = 0
    if cycles:
        minimum = max(minimum, len(cycles[0]))
    if paths:
        minimum = max(minimum, len(paths[0]))
    maximum = max(minimum, 10)
    print >> out, 'where:'
    for v in players[0:maximum]:
        k = map[v]
        print >> out, ' %3s = %r' % (k, v)
        if stackless and isinstance(v, stackless.tasklet):
            try:
                if not v.alive:
                    print >> out, 'dead'
                elif v.frame:
                    for s in traceback.format_list(traceback.extract_stack(
                            v.frame, 40),
                                                   format=FORMAT):
                        print >> out, '       ' + s,

                else:
                    print >> out, 'no frame'
            except:
                pass

    return True
コード例 #18
0
def _LogException(exc_info, extraText, channel, toConsole, toLogServer,
                  toAlertSvc, toMsgWindow, severity, show_locals):
    if raven_client:
        raven_client(message=extraText, exc_info=exc_info)
    exctype, exc, tb = exc_info
    exception_list = traceback2.extract_tb(tb, extract_locals=show_locals)
    if tb:
        caught_list = traceback2.extract_stack(tb.tb_frame)
    else:
        caught_list = traceback2.extract_stack(up=2)
    stack, stackID = GetStack(exception_list,
                              caught_list,
                              show_locals=show_locals)
    if severity is None:
        severity = (ERR, WARN)[isinstance(exc, UserError)]
    if toAlertSvc is None:
        toAlertSvc = severity in (ERR, )
    if toMsgWindow and isinstance(exc, UserError) and boot.role == 'client':
        toMsgWindow = 0
        uiMessageFunc(*exc.args)
    multiplexToConsole = False if toLogServer else toConsole
    out = GetMultiplex(channel, severity, multiplexToConsole, toLogServer,
                       toMsgWindow, toAlertSvc, stackID)
    formatted_exception = traceback2.format_exception_only(exctype, exc)
    if not extraText:
        try:
            extraText = 'Info: %s' % formatted_exception[-1].strip()
        except:
            extraText = 'Info: <none>'

    prefix = 'REMOTE ' if channel == 'remote.exc' else ''
    traceID = NextTraceID()
    print >> out, '%sEXCEPTION #%d logged at %s %s : %s ' % (
        prefix, traceID, blue.os.FormatUTC()[0], blue.os.FormatUTC()[2],
        extraText)
    print >> out, ' '
    print >> out, 'Formatted exception info:',
    for line in formatted_exception:
        print >> out, line,

    print >> out, ' '
    for line in stack:
        print >> out, line,

    print >> out, ' '
    if exctype is MemoryError:
        try:
            DumpMemoryStatus(out)
            DumpMemHistory(out)
        except:
            pass

    try:
        _LogThreadLocals(out)
    except MemoryError:
        pass

    if boot.role != 'client':
        try:
            ram = blue.sysinfo.GetMemory().pageFile / 1024 / 1024
            cpuLoad = sm.GetService('machoNet').GetCPULoad()
            memLeft = blue.sysinfo.GetMemory().availablePhysical / 1024 / 1024
            txt = 'System Information: '
            txt += ' Node ID: %s' % sm.GetService('machoNet').GetNodeID()
            if boot.role == 'server':
                txt += ' | Node Name: %s' % sm.GetService(
                    'machoNet').GetLocalHostName()
            txt += ' | Total CPU load: %s%%' % int(cpuLoad)
            txt += ' | Process memory in use: %s MB' % ram
            txt += ' | Physical memory left: %s MB' % memLeft
            print >> out, txt
        except Exception as e:
            sys.exc_clear()

    try:
        print >> out, 'Stackhash: %s' % stackID[0]
    except Exception:
        pass

    print >> out, 'Reported from: ', __name__
    print >> out, '%sEXCEPTION END' % (prefix, )
    out.flush()
    if toConsole:
        if toLogServer:
            print >> sys.stderr, '#nolog: An exception has occurred. It has been logged in the log server as exception #%d' % traceID
        else:
            print >> sys.stderr, 'There is no useful information accompanying this exception in the log server'
コード例 #19
0
def _LogException(exc_info, extraText, channel, toConsole, toLogServer,
                  toAlertSvc, toMsgWindow, severity, show_locals):
    exctype, exc, tb = exc_info
    exception_list = traceback2.extract_tb(tb, extract_locals=show_locals)
    if tb:
        caught_list = traceback2.extract_stack(tb.tb_frame)
    else:
        caught_list = traceback2.extract_stack(up=2)
    formatted_exception = traceback2.format_exception_only(exctype, exc)
    stack, stackID = GetStack(exception_list,
                              caught_list,
                              show_locals=show_locals)
    if severity is None:
        severity = (ERR, WARN)[isinstance(exc, UserError)]
    if toAlertSvc is None:
        toAlertSvc = severity in (ERR, )
    if toMsgWindow and isinstance(exc, UserError) and boot.role == 'client':
        toMsgWindow = 0
        uiMessageFunc(*exc.args)
    out = GetMultiplex(channel, severity, [toConsole, 0][toLogServer == 1],
                       toLogServer, toMsgWindow, toAlertSvc, stackID)
    pre = ('', 'REMOTE')[channel == 'remote.exc']
    traceID = NextTraceID()
    print >> out, '%sEXCEPTION #%d logged at ' % (
        pre,
        traceID), blue.os.FormatUTC()[0], blue.os.FormatUTC()[2], extraText
    for line in stack:
        print >> out, line,

    for line in formatted_exception:
        print >> out, line,

    if exctype is MemoryError:
        try:
            DumpMemoryStatus(out)
            DumpMemHistory(out)
        except:
            pass

    try:
        _LogThreadLocals(out)
    except MemoryError:
        pass

    try:
        print >> out, 'Stackhash:%s\n' % stackID[0]
    except Exception:
        pass

    print >> out
    if boot.role != 'client':
        try:
            ram = blue.win32.GetProcessMemoryInfo(
            )['PagefileUsage'] / 1024 / 1024
            cpuLoad = sm.GetService('machoNet').GetCPULoad()
            m = blue.win32.GlobalMemoryStatus()
            memLeft = m['AvailPhys'] / 1024 / 1024
            txt = 'System Information: '
            txt += ' Node ID: %s' % sm.GetService('machoNet').GetNodeID()
            if boot.role == 'server':
                txt += ' | Node Name: %s' % sm.GetService(
                    'machoNet').GetLocalHostName()
            txt += ' | Total CPU load: %s%%' % int(cpuLoad)
            txt += ' | Process memory in use: %s MB' % ram
            txt += ' | Physical memory left: %s MB' % memLeft
            print >> out, txt
        except Exception as e:
            sys.exc_clear()

    print >> out, '%sEXCEPTION END' % (pre, )
    out.flush()
    if toConsole:
        if toLogServer:
            print >> sys.stderr, 'An exception has occurred.  It has been logged in the log server as exception #%d' % traceID
        else:
            print >> sys.stderr, 'There is no useful information accompanying this exception in the log server'