countMethod(name) from buildbot.process.metrics import countMethod
@countMethod('foo_called')
def foo():
return "foo!"
Timer(name)Timer objects can be used to make timing events easier. When Timer.stop() is called, a MetricTimeEvent is logged with the elapsed time since timer.start() was called.
from buildbot.process.metrics import Timer
def foo():
t = Timer('time_foo')
t.start()
try:
for i in range(1000):
calc(i)
return "foo!"
finally:
t.stop()
Timer objects also provide a pair of decorators, startTimer/stopTimer to decorate other functions.
from buildbot.process.metrics import Timer
t = Timer('time_thing')
@t.startTimer
def foo():
return "foo!"
@t.stopTimer
def bar():
return "bar!"
foo()
bar()
timeMethod(name)Timer is better in this case.
from buildbot.process.metrics import timeMethod
@timeMethod('time_foo')
def foo():
for i in range(1000):
calc(i)
return "foo!"