From 7d457b50962e803b3d8f4c26c4e495bb9e85c079 Mon Sep 17 00:00:00 2001 From: coleramos425 Date: Thu, 24 Aug 2023 15:54:00 -0500 Subject: [PATCH] Replacing subprocess with shutil Signed-off-by: coleramos425 --- src/common.py | 9 ++++----- src/omniperf | 19 +++++++------------ src/utils/perfagg.py | 2 +- 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/src/common.py b/src/common.py index e39a8c69c..fa2909573 100644 --- a/src/common.py +++ b/src/common.py @@ -44,10 +44,9 @@ def resolve_rocprof(returnPath=False): else: rocprof_cmd = os.environ["ROCPROF"] - rocprof_path = subprocess.run( - ["which", rocprof_cmd], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL - ) - if rocprof_path.returncode != 0: + rocprof_path = shutil.which(rocprof_cmd) + + if not rocprof_path: print("\nError: Unable to resolve path to %s binary" % rocprof_cmd) print( "Please verify installation or set ROCPROF environment variable with full path." @@ -55,7 +54,7 @@ def resolve_rocprof(returnPath=False): sys.exit(1) else: # Resolve any sym links in file path - rocprof_path = os.path.realpath(rocprof_path.stdout.decode("utf-8").rstrip("\n")) + rocprof_path = os.path.realpath(rocprof_path.rstrip("\n")) print("ROC Profiler: ", rocprof_path) if returnPath: return rocprof_path diff --git a/src/omniperf b/src/omniperf index b63cf093b..b64779935 100755 --- a/src/omniperf +++ b/src/omniperf @@ -35,6 +35,7 @@ import pandas as pd from datetime import datetime from pathlib import Path as path import warnings +import shutil from parser import parse from utils import specs @@ -438,10 +439,8 @@ def characterize_app(args, VER): def run_rocscope(args, fname): # profile the app if args.use_rocscope == True: - result = subprocess.run( - ["which", "rocscope"], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL - ) - if result.returncode == 0: + result = shutil.which("rocscope") + if result: rs_cmd = [ result.stdout.decode("ascii").strip(), "metrics", @@ -553,10 +552,8 @@ def omniperf_profile(args, VER): print(e) sys.exit(1) - result = subprocess.run( - ["which", "rocscope"], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL - ) - if result.returncode == 0: + result = shutil.which("rocscope") + if result: rs_cmd = [ result.stdout.decode("ascii").strip(), "top10", @@ -587,10 +584,8 @@ def omniperf_profile(args, VER): print(e) sys.exit(1) - result = subprocess.run( - ["which", "rocscope"], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL - ) - if result.returncode == 0: + result = shutil.which("rocscope") + if result: rs_cmd = [ result.stdout.decode("ascii").strip(), "summary", diff --git a/src/utils/perfagg.py b/src/utils/perfagg.py index 6ec4542a9..c486faccf 100755 --- a/src/utils/perfagg.py +++ b/src/utils/perfagg.py @@ -22,7 +22,7 @@ # SOFTWARE. ##############################################################################el -import sys, os, pathlib, shutil, subprocess, argparse, glob, re +import sys, os, shutil, glob, re import numpy as np import math import warnings