Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Profiler files path configurable #135

Merged
merged 1 commit into from
Aug 17, 2016
Merged
Show file tree
Hide file tree
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
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,
str(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