forked from django-oscar/django-oscar
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request django-oscar#622 into releases/0.5
- Loading branch information
Showing
8 changed files
with
70 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import cProfile | ||
import pstats | ||
import time | ||
|
||
|
||
def profile(fn): | ||
""" | ||
Profile the decorated function, storing the profile output in /tmp | ||
Inspired by https://speakerdeck.com/rwarren/a-brief-intro-to-profiling-in-python | ||
""" | ||
def profiled_fn(*args, **kwargs): | ||
filepath = "/tmp/%s.profile" % fn.__name__ | ||
prof = cProfile.Profile() | ||
|
||
start = time.time() | ||
result = prof.runcall(fn, *args, **kwargs) | ||
duration = time.time() - start | ||
|
||
print "Function ran in %.6f seconds - output written to %s" % ( | ||
duration, filepath) | ||
prof.dump_stats(filepath) | ||
|
||
print "Printing stats" | ||
stats = pstats.Stats(filepath) | ||
stats.sort_stats('cumulative') | ||
stats.print_stats() | ||
|
||
return result | ||
return profiled_fn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters