Exemple #1
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
 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
Exemple #3
0
def FormatList(extracted_list, show_locals = 0, show_lines = True):
    l = []
    for line in extracted_list:
        l2 = list(line)
        l2[0] = GetStackFileName(l2[0])[0]
        if not show_lines:
            l2[3] = ''
        l.append(l2)

    lines = traceback2.format_list(l, show_locals, format=traceback2.FORMAT_LOGSRV | traceback2.FORMAT_SINGLE)
    return lines
Exemple #4
0
def FormatList(extracted_list, show_locals=0, show_lines=True):
    l = []
    for line in extracted_list:
        l2 = list(line)
        if not show_lines:
            l2[3] = ''
        l.append(l2)

    lines = traceback2.format_list(l,
                                   show_locals,
                                   format=traceback2.FORMAT_LOGSRV
                                   | traceback2.FORMAT_SINGLE)
    return lines
Exemple #5
0
def FormatList(traceback_list, show_locals=0, show_lines=True):
    cleaned_list = []
    for line in traceback_list:
        l2 = list(line)
        l2[0] = GetFriendlyPathName(l2[0])
        if not show_lines:
            l2[3] = ''
        cleaned_list.append(l2)

    lines = traceback2.format_list(cleaned_list,
                                   show_locals,
                                   format=traceback2.FORMAT_LOGSRV
                                   | traceback2.FORMAT_SINGLE)
    return lines
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
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