def process(self):
logger = logging.getLogger()
hdlr = logging.FileHandler('C:\pt.log')
formatter = logging.Formatter('[%(asctime)s]%(levelname)-8s"%(message)s"','%Y-%m-%d %a %H:%M:%S')
hdlr.setFormatter(formatter)
logger.addHandler(hdlr)
logger.setLevel(logging.INFO)
timesum = 3600
countsum = 0
while(timesum > 0):
result = self.keywords.fileop.executeCommand('top -b -d 1 -n 2 | grep \'Mem\|Cpu\' |awk \'{if(NR==3) print }\'')
logger.info(result)
result = self.keywords.fileop.executeCommand('top -b -d 1 -n 2 | grep \'Mem\|Cpu\' |awk \'{if(NR==4) print }\'')
logger.info(result)
time.sleep(120)
timesum = timesum - 120
result = self.keywords.fileop.executeCommand('top -b -d 1 -n 2 | grep \'Mem\|Cpu\' |awk \'{if(NR==3) print }\'')
logger.info(result)
result = self.keywords.fileop.executeCommand('top -b -d 1 -n 2 | grep \'Mem\|Cpu\' |awk \'{if(NR==4) print }\'')
logger.info(result)
result = self.keywords.fileop.executeCommand(self.keywords.test_dir + 'count.sh')
logger.info(result)
logger.info('countSume = :' + str(countsum))
pids = self.keywords.fileop.executeCommand("ps aux|grep top |awk '{printf \" \"$2}'")
pidlist = pids.split(' ')
for i in pidlist:
if i is not pidlist[0]:
result = self.keywords.fileop.executeCommand('kill -9 ' + i)
self.keywords.writeLineFormated(result)
self.keywords.fileop.closeAllConnections()
# t.pleaseStop()
return True
一个python的性能检测脚本
最新推荐文章于 2024-01-22 20:47:06 发布