|
a/Allura/allura/lib/stats.py |
|
b/Allura/allura/lib/stats.py |
1 |
from __future__ import with_statement
|
1 |
from __future__ import with_statement
|
2 |
from time import time
|
2 |
from time import time
|
3 |
from contextlib import contextmanager
|
3 |
from contextlib import contextmanager
|
|
|
4 |
from pylons import request
|
4 |
|
5 |
|
5 |
class StatsRecord(object):
|
6 |
class StatsRecord(object):
|
6 |
|
7 |
|
7 |
def __init__(self, request, active):
|
8 |
def __init__(self, request, active):
|
8 |
self.timers = dict(
|
9 |
self.timers = dict(
|
|
... |
|
... |
45 |
|
46 |
|
46 |
def __init__(self, timer):
|
47 |
def __init__(self, timer):
|
47 |
self.timer = timer
|
48 |
self.timer = timer
|
48 |
|
49 |
|
49 |
def __call__(self, func):
|
50 |
def __call__(self, func):
|
50 |
from allura.lib.custom_middleware import environ
|
|
|
51 |
def inner(*l, **kw):
|
51 |
def inner(*l, **kw):
|
52 |
try:
|
52 |
try:
|
53 |
stats = environ['sf.stats']
|
53 |
stats = request.environ['sf.stats']
|
54 |
except KeyError:
|
54 |
except TypeError:
|
55 |
return func(*l, **kw)
|
55 |
return func(*l, **kw)
|
56 |
with stats.timing(self.timer):
|
56 |
with stats.timing(self.timer):
|
57 |
return func(*l, **kw)
|
57 |
return func(*l, **kw)
|
58 |
inner.__name__ = func.__name__
|
58 |
inner.__name__ = func.__name__
|
59 |
return inner
|
59 |
return inner
|