Beispiel #1
0
def app(environ, start_response):
    status = '200 OK'
    headers = [('Content-type', 'text/plain')]
    start_response(status, headers)

    #: You can use a single timer
    timer = pynba.timer(tag1='foo', tag2='bar')
    timer.start()
    sleep(.1)
    timer.stop()

    #: Or benchmark an algorhythm with a context processor
    with pynba.timer(tag3='foo', tag4='bar'):
        sleep(.1)

    #: Evently benchmark a function with a decorator
    @pynba.timer(tag5='foo', tag6='bar')
    def long_process(self):
        sleep(.1)

    long_process()

    return """
    Type
        SELECT * FROM  `request`
    on MySQL to found the current request {scriptname}.

    Type
        SELECT * FROM  `timer`
    on MySQL to found the assocated timer.
    """.format(scriptname=pynba.scriptname)
Beispiel #2
0
def app(environ, start_response):
    status = '200 OK'
    headers = [('Content-type', 'text/plain')]
    start_response(status, headers)

    #: You can use a single timer
    timer = pynba.timer(tag1='foo', tag2='bar')
    timer.start()
    sleep(.1)
    timer.stop()

    #: Or benchmark an algorhythm with a context processor
    with pynba.timer(tag3='foo', tag4='bar'):
        sleep(.1)

    #: Evently benchmark a function with a decorator
    @pynba.timer(tag5='foo', tag6='bar')
    def long_process(self):
        sleep(.1)

    long_process()


    return """
    Type
        SELECT * FROM  `request`
    on MySQL to found the current request {scriptname}.

    Type
        SELECT * FROM  `timer`
    on MySQL to found the assocated timer.
    """.format(scriptname= pynba.scriptname)
Beispiel #3
0
def app(environ, start_response):
    pynba.scriptname = '[lol]' + pynba.scriptname

    if environ.get('PATH_INFO', None) == '/favicon.ico':
        pynba.enabled = False

    logging.debug('enter simple app')

    # TODO: implement a flush

    logging.debug('init first timer without starting it')
    timer1 = pynba.timer(foo=['foo', 'foo2'], bar=['bar', 'bar2'], baz='baz')

    logging.debug('init 2nd timer with multivalues tag')
    timer2 = pynba.timer(multi_bar=['multi1', 'multi2'], baz='baz').start()

    status = '200 OK'
    headers = [('Content-type', 'text/plain')]
    logging.debug('init 3rd as a context')
    with pynba.timer(context_bar='bar', context_baz='baz'):
        sleep(1)

    logging.debug('init 4th as a decorator')
    @pynba.timer(decorator_bar='bar', decorator_baz='baz')
    def trololo():
        return "foo"

    logging.debug('call decorated 5 times')
    trololo()
    trololo()
    trololo()
    trololo()
    trololo()

    outside()
    outside()

    start_response(status, headers)

    ret = ["%s: %s\n" % (key, value)
           for key, value in environ.iteritems()]
    return ret
Beispiel #4
0
def app(environ, start_response):
    pynba.scriptname = '[lol]' + pynba.scriptname

    if environ.get('PATH_INFO', None) == '/favicon.ico':
        pynba.enabled = False

    logging.debug('enter simple app')

    # TODO: implement a flush

    logging.debug('init first timer without starting it')
    timer1 = pynba.timer(foo=['foo', 'foo2'], bar=['bar', 'bar2'], baz='baz')

    logging.debug('init 2nd timer with multivalues tag')
    timer2 = pynba.timer(multi_bar=['multi1', 'multi2'], baz='baz').start()

    status = '200 OK'
    headers = [('Content-type', 'text/plain')]
    logging.debug('init 3rd as a context')
    with pynba.timer(context_bar='bar', context_baz='baz'):
        sleep(1)

    logging.debug('init 4th as a decorator')

    @pynba.timer(decorator_bar='bar', decorator_baz='baz')
    def trololo():
        return "foo"

    logging.debug('call decorated 5 times')
    trololo()
    trololo()
    trololo()
    trololo()
    trololo()

    outside()
    outside()

    start_response(status, headers)

    ret = ["%s: %s\n" % (key, value) for key, value in environ.iteritems()]
    return ret