#!/usr/bin/env python
#-*- coding: utf-8 -*-
import sys
import datetime
import time
import psutil
from ctypes import *
"""
性能测试示例Python代码:
1、获取系统性能指标(内存、cpu、GDI、IO)
2、保存数据至日志文件 (./******.log)
3、可同时监控多个程序(xiadan:hexin)
"""
class PerfMonitor(object):
def __init__(self, pnames, monitor_time):
self.pnames = pnames
self.monitor_time = monitor_time
self.perflog = "./"
self.perfimg = "./"
def getGDIcount(self,PID):
PH = windll.kernel32.OpenProcess(5432, 0, PID)
GDIcount = windll.user32.GetGuiResources(PH, 0)
windll.kernel32.CloseHandle(PH)
return GDIcount
def time_wait(self,proc_name):
# 增加隐形等待时间
pid_list = []
now_data = time.time()
while time.time() < now_data + 35:
pid_data = list(filter(lambda x: x.name() == proc_name, psutil.process_iter()))
if pid_data != []:
pid_list.append(list(pid_data)[0].pid)
break
else:
time.sleep(0.1)
return pid_list
def get_pid(self,pnames):
# 获取进程号列表
pnames = map(lambda x : (x
【性能测试】获取性能系统指标之示例Python代码
最新推荐文章于 2023-10-01 20:53:11 发布