<s> import datetime <EOL> from plop . collector import Collector , PlopFormatter <EOL> from tornado import gen <EOL> from tornado . httpclient import AsyncHTTPClient <EOL> from tornado . ioloop import IOLoop <EOL> from tornado . options import parse_command_line , define , options <EOL> from tornado . web import Application , RequestHandler , asynchronous <EOL> define ( '<STR_LIT:port>' , default = <NUM_LIT> ) <EOL> define ( '<STR_LIT>' , default = '<STR_LIT>' ) <EOL> class HelloHandler ( RequestHandler ) : <EOL> @ asynchronous <EOL> @ gen . engine <EOL> def get ( self ) : <EOL> yield gen . Task ( IOLoop . instance ( ) . add_callback ) <EOL> self . render ( "<STR_LIT>" , name = "<STR_LIT>" ) <EOL> class ProfileHandler ( RequestHandler ) : <EOL> @ asynchronous <EOL> def get ( self ) : <EOL> self . collector = Collector ( ) <EOL> self . collector . start ( ) <EOL> IOLoop . instance ( ) . add_timeout ( datetime . timedelta ( seconds = <NUM_LIT> ) , <EOL> self . finish_profile ) <EOL> def finish_profile ( self ) : <EOL> self . collector . stop ( ) <EOL> formatter = PlopFormatter ( ) <EOL> self . finish ( formatter . format ( self . collector ) ) <EOL> @ gen . engine <EOL> def generate_traffic ( ) : <EOL> client = AsyncHTTPClient ( ) <EOL> while True : <EOL> resp = yield gen . Task ( client . fetch , <EOL> '<STR_LIT>' % options . port ) <EOL> assert resp . body . strip ( ) . decode ( "<STR_LIT:utf-8>" ) == '<STR_LIT>' <EOL> def main ( ) : <EOL> parse_command_line ( ) <EOL> app = Application ( [ <EOL> ( '<STR_LIT:/>' , HelloHandler ) , <EOL> ( '<STR_LIT>' , ProfileHandler ) , <EOL> ] , log_function = lambda x : None ) <EOL> app . listen ( options . port , address = '<STR_LIT:localhost>' ) <EOL> generate_traffic ( ) <EOL> IOLoop . instance ( ) . start ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
