Skip to content

Commit

Permalink
Profiler files path configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
javaguirre committed Aug 17, 2016
1 parent 0caa10d commit 0062bb6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
14 changes: 12 additions & 2 deletions silk/collector.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from threading import local

import os.path
import cProfile
import pstats
import logging
Expand Down Expand Up @@ -89,9 +90,13 @@ def silk_queries(self):
return self._get_objects('silk_queries')

def configure(self, request=None):
silky_config = SilkyConfig()

self.request = request
self.profiler_result_path = silky_config.SILKY_PYTHON_PROFILER_RESULT_PATH
self._configure()
if SilkyConfig().SILKY_PYTHON_PROFILER:

if silky_config.SILKY_PYTHON_PROFILER:
self.pythonprofiler = cProfile.Profile()
self.pythonprofiler.enable()

Expand Down Expand Up @@ -144,7 +149,12 @@ def finalise(self):
self.request.pyprofile = profile_text

if SilkyConfig().SILKY_PYTHON_PROFILER_BINARY:
file_name = "{}.prof".format(self.request.id)
file_name = "{}.prof".format(
os.path.join(
self.profiler_result_path,
self.request.id
)
)
with open(file_name, 'w+b') as f:
ps.dump_stats(f.name)
self.request.prof_file.save(f.name, File(f))
Expand Down
1 change: 1 addition & 0 deletions silk/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class SilkyConfig(six.with_metaclass(Singleton, object)):
'SILKY_INTERCEPT_PERCENT': 100,
'SILKY_INTERCEPT_FUNC': None,
'SILKY_PYTHON_PROFILER': False,
'SILKY_PYTHON_PROFILER_RESULT_PATH': ''
}

def _setup(self):
Expand Down

0 comments on commit 0062bb6

Please sign in to comment.