importsysimportpandasaspdclassServer:def__init__(self,name:str,req:str,time:str):self.name=nameself.read_path="/root/Project/ab/result/result_"+self.name+"_r"+req+"_"+time+".txt"self.write_path="/root/Project/ab/summary/summary_"+self.name+"_r"+req+"_"+time+".txt"self.content,self.df=None,Noneself.req,self.con,self.fail,self.time,self.rps,self.tpr=[],[],[],[],[],[]defread(self):withopen(self.read_path,"r")asfile:self.content=file.readlines()defparse(self,msg:dict):forlineinself.content:ifmsg["req"]inline:self.req.append(line[len(msg["req"]):].strip())elifmsg["con"]inline:self.con.append(line[len(msg["con"]):].strip())elifmsg["fail"]inline:self.fail.append(line[len(msg["fail"]):].strip())elifmsg["time"]inline:self.time.append(line[len(msg["time"]):].strip().split("seconds")[0].strip())elifmsg["rps"]inline:self.rps.append(line[len(msg["rps"]):].strip().split("[#/sec]")[0].strip())elifmsg["tpr_1"]inlineandmsg["tpr_2"]notinline:self.tpr.append(line[len(msg["tpr_1"]):].strip().split("[ms]")[0].strip())defwrite(self):self.df=pd.DataFrame({"Requests":self.req,"Concurrency":self.con,"Failed":self.fail,"Total Time (sec.)":self.time,"Requests Per Second":self.rps,"Time Per Request (msec.)":self.tpr})self.df.to_csv(self.write_path)print(f"\n<<< {self.name.upper()} >>>\n{self.df}\n")defmain(req,time):msg={\
"req":"Complete requests:",\
"con":"Concurrency Level:",\
"fail":"Failed requests:",\
"time":"Time taken for tests:",\
"rps":"Requests per second:",\
"tpr_1":"Time per request:",\
"tpr_2":"across all concurrent requests"\
}fornamein("gunicorn","torchserve"):server=Server(name,req,time)server.read()server.parse(msg)server.write()if__name__=="__main__":req,time=sys.argv[1:]main(req,time)