Exemple #1
0
def handler(req, handlerState, globalState):
    threadId = req.threadId
    LOG('RequestMonitor.DumpTrace', WARNING, 'Long running request',
        'Request %s "%s" running in thread %s since %ss\n%s' % (
      req.id,
      req.info,
      threadId,
      handlerState.monitorTime - req.startTime,
      ''.join(formatStack(current_frames()[threadId])),
      )
        )
 def __call__(self, req, handlerState, globalState):
     threadId = req.threadId
     stack_trace = "".join(formatStack(current_frames()[threadId]))
     if os.environ.get("DISABLE_HAUFE_MONITORING_ON_PDB") and stack_trace.find("  Module pdb,") > -1:
         return
     zLOG.LOG(
         "RequestMonitor.DumpTrace",
         self.loglevel,
         "Long running request",
         u'Request {0} "{1}" running in thread {2} since {3}s\n{4}'.format(
             req.id, req.info, threadId, handlerState.monitorTime - req.startTime, stack_trace
         ),
     )
def handler(req, handlerState, globalState):
    threadId = req.threadId
    stack_trace = ''.join(formatStack(current_frames()[threadId]))
    if os.environ.get('DISABLE_HAUFE_MONITORING_ON_PDB') and stack_trace.find("  Module pdb,")>-1:
        return
    LOG('RequestMonitor.DumpTrace', WARNING, 'Long running request',
        'Request %s "%s" running in thread %s since %ss\n%s' % (
      req.id,
      req.info,
      threadId,
      handlerState.monitorTime - req.startTime,
      stack_trace,
      )
        )
 def __call__(self, req, handlerState, globalState):
     threadId = req.threadId
     stack_trace = ''.join(formatStack(current_frames()[threadId]))
     if os.environ.get('DISABLE_HAUFE_MONITORING_ON_PDB')\
             and stack_trace.find("  Module pdb,") > -1:
         return
     log.log(
         self.loglevel,
         'Long running request Request {0} "{1}" running in thread {2} since {3}s\n{4}'
         .format(  # noqa: E501
             req.id,
             req.info,
             threadId,
             handlerState.monitorTime - req.startTime,
             stack_trace,
         ))
def dump_threads():
    """Dump running threads

    Returns a string with the tracebacks.
    """

    frames = current_frames()
    this_thread_id = thread.get_ident()
    now = time.strftime("%Y-%m-%d %H:%M:%S")
    res = ["Threads traceback dump at %s\n" % now]
    for thread_id, frame in frames.iteritems():
        if thread_id == this_thread_id:
            continue

        # Find request in frame
        reqinfo = ''
        f = frame
        while f is not None:
            co = f.f_code

           #reqinfo += '\n\t ' + co.co_name + '\t ' + co.co_filename

            if co.co_name == 'publish':
                if co.co_filename.endswith('/publisher/publish.py') or \
                   co.co_filename.endswith('/ZPublisher/Publish.py'):
                    request = f.f_locals.get('request')
                    if request is not None:
                        reqinfo += (request.get('REQUEST_METHOD', '') + ' ' +
                                   request.get('PATH_INFO', ''))
                        qs = request.get('QUERY_STRING')
                        if qs:
                            reqinfo += '?'+qs
                    break
            f = f.f_back
        if reqinfo:
            reqinfo = " (%s)" % reqinfo

        output = StringIO()
        traceback.print_stack(frame, file=output)
        res.append("Thread %s%s:\n%s" %
            (thread_id, reqinfo, output.getvalue()))

    frames = None
    res.append("End of dump")
    return '\n'.join(res)
Exemple #6
0
def get_full_thread_dump():
    """Returns a string containing a traceback for all threads"""
    output = io.StringIO()
    time = strftime("%Y-%m-%d %H:%M:%S", gmtime())
    thread_names = {}
    for thread in threading.enumerate():
        thread_names[thread.ident] = thread.name
    output.write("\n>>>> Begin stack trace (%s) >>>>\n" % time)
    for threadId, stack in current_frames().items():
        output.write("\n# ThreadID: %s (%s)\n" %
                     (threadId, thread_names.get(threadId, "unknown")))
        for filename, lineno, name, line in traceback.extract_stack(stack):
            output.write('File: "%s", line %d, in %s\n' %
                         (filename, lineno, name))
            if line:
                output.write("  %s\n" % (line.strip()))
    output.write("\n<<<< End stack trace <<<<\n\n")

    thread_dump = output.getvalue()
    output.close()
    return thread_dump