示例#1
0
def StackTraceAll(reason='(no reason stated)'):
    import stackless, traceback2, os, time
    logsFolder = blue.paths.ResolvePath(u'root:') + 'logs'
    if not os.path.exists(logsFolder):
        os.mkdir(logsFolder)
    y, m, wd, d, h, m, s, ms = blue.os.GetTimeParts(blue.os.GetWallclockTime())
    args = (boot.build, y, m, d, h, m, s)
    filename = logsFolder + '/#stacktrace b%d %.4d.%.2d.%.2d %.2d.%.2d.%.2d.txt' % args
    GetChannel('General').Log('Writing out stacktrace at ' + filename, LGERR)
    out = open(filename, 'w')
    out.write('Stack trace of all tasklets as requested: %s\n' % reason)
    out.write('Node ID: %s\n' %
              getattr(sm.services['machoNet'], 'nodeID', 'unknown'))
    out.write(time.ctime() + '\n\n')
    t = stackless.getcurrent()
    first = t
    no = 1
    while t:
        out.write(
            'Tasklet #%s -------------------------------------------------' %
            no + '\n')
        no += 1
        if str(t.frame).find('cframe') == -1:
            traceback2.print_stack(t.frame, file=out)
        else:
            out.write('%s\n' % t.frame)
        out.write('\n')
        t = t.next
        if t is None or t == first:
            break

    if postStackTraceAll:
        postStackTraceAll(out)
示例#2
0
    def test_stack_format(self):
        # Verify _stack functions. Note we have to use _getframe(1) to
        # compare them without this frame appearing in the output
        with captured_output("stderr") as ststderr:
            traceback.print_stack(sys._getframe(1))
        stfile = StringIO()
        traceback.print_stack(sys._getframe(1), file=stfile)
        self.assertEqual(ststderr.getvalue(), stfile.getvalue())

        stfmt = traceback.format_stack(sys._getframe(1))

        self.assertEqual(ststderr.getvalue(), "".join(stfmt))
    def test_stack_format(self):
        # Verify _stack functions. Note we have to use _getframe(1) to
        # compare them without this frame appearing in the output
        with captured_output("stderr") as ststderr:
            traceback.print_stack(sys._getframe(1))
        stfile = StringIO()
        traceback.print_stack(sys._getframe(1), file=stfile)
        self.assertEqual(ststderr.getvalue(), stfile.getvalue())

        stfmt = traceback.format_stack(sys._getframe(1))

        self.assertEqual(ststderr.getvalue(), "".join(stfmt))
示例#4
0
def StackTraceAll(reason = '(no reason stated)'):
    import stackless, traceback2, os, time
    logsFolder = blue.paths.ResolvePath(u'root:') + 'logs'
    if not os.path.exists(logsFolder):
        os.mkdir(logsFolder)
    y, m, wd, d, h, m, s, ms = blue.os.GetTimeParts(blue.os.GetWallclockTime())
    args = (boot.build,
     y,
     m,
     d,
     h,
     m,
     s)
    filename = logsFolder + '/#stacktrace b%d %.4d.%.2d.%.2d %.2d.%.2d.%.2d.txt' % args
    GetChannel('General').Log('Writing out stacktrace at ' + filename, LGERR)
    out = open(filename, 'w')
    out.write('Stack trace of all tasklets as requested: %s\n' % reason)
    out.write('Node ID: %s\n' % getattr(sm.services['machoNet'], 'nodeID', 'unknown'))
    out.write(time.ctime() + '\n\n')
    t = stackless.getcurrent()
    first = t
    no = 1
    while t:
        out.write('Tasklet #%s -------------------------------------------------' % no + '\n')
        no += 1
        if str(t.frame).find('cframe') == -1:
            traceback2.print_stack(t.frame, file=out)
        else:
            out.write('%s\n' % t.frame)
        out.write('\n')
        t = t.next
        if t is None or t == first:
            break

    if postStackTraceAll:
        postStackTraceAll(out)