Skip to content

Commit

Permalink
strict pep8 compliance
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberdelia committed Jun 13, 2012
1 parent d017747 commit f825408
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
27 changes: 12 additions & 15 deletions setup.py
@@ -1,27 +1,24 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys


import os, sys
from setuptools import setup from setuptools import setup


def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname)).read()

extra = {} extra = {}
if sys.version_info >= (3,): if sys.version_info >= (3,):
extra['use_2to3'] = True extra['use_2to3'] = True


setup( setup(
name = "statprof", name="statprof",
version = "0.1.2", version="0.1.2",
author = "Bryan O'Sullivan", author="Bryan O'Sullivan",
author_email = "bos@serpentine.com", author_email="bos@serpentine.com",
description = "Statistical profiling for Python", description="Statistical profiling for Python",
license = "LGPL", license="LGPL",
keywords = "profiling", keywords="profiling",
url = "http://packages.python.org/statprof", url="http://packages.python.org/statprof",
py_modules = ['statprof'], py_modules=['statprof'],
long_description = read('README.rst'), long_description=open('README.rst').read(),
classifiers = [ classifiers=[
"Development Status :: 3 - Alpha", "Development Status :: 3 - Alpha",
"Topic :: Utilities", "Topic :: Utilities",
"License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)", "License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)",
Expand Down
15 changes: 10 additions & 5 deletions statprof.py
Expand Up @@ -135,10 +135,10 @@ def reset(self, frequency=None):
self.sample_count = 0 self.sample_count = 0
# a float # a float
if frequency: if frequency:
self.sample_interval = 1.0/frequency self.sample_interval = 1.0 / frequency
elif not hasattr(self, 'sample_interval'): elif not hasattr(self, 'sample_interval'):
# default to 1000 Hz # default to 1000 Hz
self.sample_interval = 1.0/1000.0 self.sample_interval = 1.0 / 1000.0
else: else:
# leave the frequency as it was # leave the frequency as it was
pass pass
Expand All @@ -155,6 +155,7 @@ def accumulate_time(self, stop_time):


state = ProfileState() state = ProfileState()



class CodeKey(object): class CodeKey(object):
cache = {} cache = {}


Expand Down Expand Up @@ -186,6 +187,7 @@ def get(cls, frame):
cls.cache[k] = v cls.cache[k] = v
return v return v



class CallData(object): class CallData(object):
all_calls = {} all_calls = {}


Expand Down Expand Up @@ -223,6 +225,7 @@ def sample_stack_procs(frame):
for key in keys_seen: for key in keys_seen:
CallData.get(key).cum_sample_count += 1 CallData.get(key).cum_sample_count += 1



def profile_signal_handler(signum, frame): def profile_signal_handler(signum, frame):
if state.profile_level > 0: if state.profile_level > 0:
state.accumulate_time(clock()) state.accumulate_time(clock())
Expand All @@ -238,6 +241,7 @@ def profile_signal_handler(signum, frame):
def is_active(): def is_active():
return state.profile_level > 0 return state.profile_level > 0



def start(): def start():
'''Install the profiling signal handler, and start profiling.''' '''Install the profiling signal handler, and start profiling.'''
state.profile_level += 1 state.profile_level += 1
Expand All @@ -248,7 +252,8 @@ def start():
signal.signal(signal.SIGPROF, profile_signal_handler) signal.signal(signal.SIGPROF, profile_signal_handler)
signal.setitimer(signal.ITIMER_PROF, signal.setitimer(signal.ITIMER_PROF,
rpt or state.sample_interval, 0.0) rpt or state.sample_interval, 0.0)
state.gc_time_taken = 0 # dunno state.gc_time_taken = 0 # dunno



def stop(): def stop():
'''Stop profiling, and uninstall the profiling signal handler.''' '''Stop profiling, and uninstall the profiling signal handler.'''
Expand All @@ -259,7 +264,8 @@ def stop():
rpt = signal.setitimer(signal.ITIMER_PROF, 0.0, 0.0) rpt = signal.setitimer(signal.ITIMER_PROF, 0.0, 0.0)
signal.signal(signal.SIGPROF, signal.SIG_IGN) signal.signal(signal.SIGPROF, signal.SIG_IGN)
state.remaining_prof_time = rpt[0] state.remaining_prof_time = rpt[0]
state.gc_time_taken = 0 # dunno state.gc_time_taken = 0 # dunno



def reset(frequency=None): def reset(frequency=None):
'''Clear out the state of the profiler. Do not call while the '''Clear out the state of the profiler. Do not call while the
Expand Down Expand Up @@ -336,4 +342,3 @@ def display(fp=None):
print >> fp, ('---') print >> fp, ('---')
print >> fp, ('Sample count: %d' % state.sample_count) print >> fp, ('Sample count: %d' % state.sample_count)
print >> fp, ('Total time: %f seconds' % state.accumulated_time) print >> fp, ('Total time: %f seconds' % state.accumulated_time)

0 comments on commit f825408

Please sign in to comment.