def main():
    try:
        options,datafile_json=optparse_lib().parse_args()

        cmdstr="""nohup python easystatserver.py > /dev/null 2>&1 &"""
        #cmdstr="""nohup ./easystatserver > /dev/null 2>&1 &"""
        #status,output=cmd_execute(cmdstr)
        import os
        os.system(cmdstr)

        print(u"start benchmark test...")
        if(options.processnum != -1):
            process.fork_processes(options.processnum)
        '''logging.basicConfig(level=logging.DEBUG,format='[%(levelname)s] (%(asctime)s) <%(message)s>',datefmt='%a,%Y-%m-%d %H:%M:%S',
            filename="./log/process."+str(tornado.process.task_id())+".log",filemode='w')'''
        logging.basicConfig(level=logging.ERROR,
                    format='[%(levelname)s] [%(asctime)s] [%(filename)s-line:%(lineno)d] [%(funcName)s-%(threadName)s] %(message)s',
                    datefmt='%a,%Y-%m-%d %H:%M:%S',
                    filename="./log/easyhttpbenchmark.log",
                    filemode='a')
        easyhttpbc=easyhttpbenchmark(options.maxclientnum,options.clientnum,options.testtime,options.flag,datafile_json)
        easyhttpbc.benchmark_test()
        print(u"benchmark test end...")
    except Exception as e:
        logging.error(str(e))

    try:
        from xmlrpclib import ServerProxy
        cfg_json=json.load(open("./conf/easyhttpbenchmark.conf", "r"),encoding='utf-8')
        stat_rpc_server=cfg_json['stat_rpc_server']
        stat_rpc_port=cfg_json['stat_rpc_port']
        svr=ServerProxy("http://"+stat_rpc_server+":"+stat_rpc_port)
        """print("total_req_cnt:"+str(easyhttpbc.total_req_cnt))
        print("total_res_cnt:"+str(easyhttpbc.total_res_cnt))
        print("total_err_cnt:"+str(easyhttpbc.total_err_cnt))
        print("total_nul_cnt:"+str(easyhttpbc.total_nul_cnt))
        print("total_res_time(ms):"+str("%0.2f" %easyhttpbc.total_res_time))
        if easyhttpbc.total_res_cnt!=0:
            avg_res_time=easyhttpbc.total_res_time/easyhttpbc.total_req_cnt
        else:
            avg_res_time=0
        print("avg_res_time(ms):"+str("%0.2f" %avg_res_time))
        print("max_res_time(ms):"+str("%0.2f" %easyhttpbc.max_res_time))
        print("min_res_time(ms):"+str("%0.2f" %easyhttpbc.min_res_time))"""
        import multiprocessing
        cpu_count=multiprocessing.cpu_count()
        if(options.processnum != 0):
            svr.stat_maxclientnum(options.processnum*options.maxclientnum)
            svr.stat_clientnum(options.processnum*options.clientnum)
        else:
            svr.stat_maxclientnum(cpu_count*options.maxclientnum)
            svr.stat_clientnum(cpu_count*options.clientnum)

        svr.set_test_time(easyhttpbc.testtime)
        svr.stat_total_req_cnt(easyhttpbc.total_req_cnt)
        svr.stat_total_res_cnt(easyhttpbc.total_res_cnt)
        svr.stat_total_err_cnt(easyhttpbc.total_err_cnt)
        svr.stat_total_nul_cnt(easyhttpbc.total_nul_cnt)

        svr.stat_total_below_10(easyhttpbc.below_10)
        svr.stat_total_between_10_20(easyhttpbc.between_10_20)
        svr.stat_total_between_20_30(easyhttpbc.between_20_30)
        svr.stat_total_over_30(easyhttpbc.over_30)
        svr.stat_total_res_time(easyhttpbc.total_res_time)
        svr.stat_max_res_time(easyhttpbc.max_res_time)
        svr.stat_min_res_time(easyhttpbc.min_res_time)
    except Exception as e:
        logging.error(str(e))