Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion sentry_sdk/worker.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import datetime
import os
import threading

Expand All @@ -17,6 +18,15 @@

_TERMINATOR = object()

import cProfile


class ProfiledThread(threading.Thread):
# Overrides threading.Thread.run()
def run(self):
self._anton_profiler = cProfile.Profile()
return self._anton_profiler.runcall(threading.Thread.run, self)


class BackgroundWorker(object):
def __init__(self, queue_size=DEFAULT_QUEUE_SIZE):
Expand Down Expand Up @@ -63,7 +73,7 @@ def start(self):
# type: () -> None
with self._lock:
if not self.is_alive:
self._thread = threading.Thread(
self._thread = ProfiledThread(
target=self._target, name="raven-sentry.BackgroundWorker"
)
self._thread.daemon = True
Expand Down Expand Up @@ -94,6 +104,10 @@ def flush(self, timeout, callback=None):
if self.is_alive and timeout > 0.0:
self._wait_flush(timeout, callback)
logger.debug("background worker flushed")
# self._thread._anton_profiler.dump_stats('%s/profiles/%s.profile' % (os.getcwd(), datetime.datetime.now().strftime("%H%M%S"),))
self._thread._anton_profiler.dump_stats(
"/profiledata/%s.profile" % (datetime.datetime.now().strftime("%H%M%S"),)
)

def full(self):
# type: () -> bool
Expand Down