File: profile.py

package info (click to toggle)
subuser 0.6.2-3.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,216 kB
  • sloc: python: 5,204; sh: 380; makefile: 73; javascript: 43
file content (25 lines) | stat: -rwxr-xr-x 550 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# -*- coding: utf-8 -*-

"""
Profiling helper function. Taken from: https://zapier.com/engineering/profiling-python-boss/
"""

#external imports
import cProfile
import os
#internal imports
#import ...

def do_cprofile(func):
  if not "SUBUSER_RUN_PROFILER" in os.environ:
    return func
  def profiled_func(*args, **kwargs):
    profile = cProfile.Profile()
    try:
      profile.enable()
      result = func(*args, **kwargs)
      profile.disable()
      return result
    finally:
      profile.print_stats(sort='cumtime')
  return profiled_func