python 调用powershell 命令获得GPU利用率

python 调用powershell 命令获得GPU利用率

获取GPU使用率通过powershell, 输入get-counter -counter “\GPU Engine()\utilization percentage"
根据你使用的哪个软件的PID ,来获得这个程序的GPU使用率。
但是使用subprocees.Popen(cmd) , cmd = get-counter -counter "\GPU Engine(
)\utilization percentage” 会报错误,如term "*’ is not recognized as the name of a cmdlet.等错误。
最后查出是编码问题, python 3默认的编码是UTF8 ,而win10 cmd 默认的编码为437(OEM-United States), 中文win10是GBK.
所以命令行传入时需要加命令进行编码,

def get_gpu_video_codec0_utilization(self):
    """
    # this utilization will need adjustment according to OS version
    step1 : Get the powerdvd pip
    step2: powershell cmd to get the GPU usage
    """
    resp = subprocess.check_output('tasklist | findstr "PowerDVD.exe"', shell=True)
    powerdvd_pid = resp.decode().partition("PowerDVD.exe")[2].strip().split(" ")[0]
    print(powerdvd_pid)
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值