Move error logging to util.py

Signed-off-by: colramos-amd <colramos@amd.com>


[ROCm/rocprofiler-compute commit: b99d448d3b]
このコミットが含まれているのは:
colramos-amd
2023-12-11 09:55:15 -06:00
committed by Karl W. Schulz
コミット 8540fde54a
8個のファイルの変更33行の追加49行の削除
+6 -11
ファイルの表示
@@ -29,7 +29,7 @@ import sys
import copy
from collections import OrderedDict
from pathlib import Path
from utils.utils import demarcate
from utils.utils import demarcate, error
from utils import schema, file_io, parser
import pandas as pd
from tabulate import tabulate
@@ -42,11 +42,6 @@ class OmniAnalyze_Base():
self.__options = options
self._output = None #NB: I made this public so children can modify/add to obj properties
def error(self,message):
logging.error("")
logging.error("[ERROR]: " + message)
logging.error("")
sys.exit(1)
def get_args(self):
return self.__args
@@ -91,7 +86,7 @@ class OmniAnalyze_Base():
)
sys.exit(0)
else:
self.error("Unsupported arch")
error("Unsupported arch")
@demarcate
def load_options(self, normalization_filter):
@@ -109,7 +104,7 @@ class OmniAnalyze_Base():
for i in range(len(args.path) - 1):
args.gpu_kernel.extend(args.gpu_kernel)
else:
self.error("Error: the number of --filter-kernels doesn't match the number of --dir.")
error("Error: the number of --filter-kernels doesn't match the number of --dir.")
@demarcate
def initalize_runs(self, avail_socs, normalization_filter=None):
@@ -143,16 +138,16 @@ class OmniAnalyze_Base():
"""Perform sanitization of inputs
"""
if not self.__args.list_metrics and not self.__args.path:
self.error("The following arguments are required: -p/--path")
error("The following arguments are required: -p/--path")
# verify not accessing parent directories
if ".." in str(self.__args.path):
self.error("Access denied. Cannot access parent directories in path (i.e. ../)")
error("Access denied. Cannot access parent directories in path (i.e. ../)")
# ensure absolute path
for dir in self.__args.path:
full_path = os.path.abspath(dir[0])
dir[0] = full_path
if not os.path.isdir(dir[0]):
self.error("Invalid directory {}\nPlease try again.".format(dir[0]))
error("Invalid directory {}\nPlease try again.".format(dir[0]))
#----------------------------------------------------
# Required methods to be implemented by child classes
+2 -2
ファイルの表示
@@ -23,7 +23,7 @@
##############################################################################el
from omniperf_analyze.analysis_base import OmniAnalyze_Base
from utils.utils import demarcate
from utils.utils import demarcate, error
from utils import file_io, parser, tty
from utils.csv_processor import kernel_name_shortener
@@ -38,7 +38,7 @@ class cli_analysis(OmniAnalyze_Base):
"""
super().pre_processing(omni_soc)
if self.get_args().random_port:
self.error("--gui flag is required to enable --random-port")
error("--gui flag is required to enable --random-port")
for d in self.get_args().path:
# demangle and overwrite original 'KernelName'
kernel_name_shortener(d[0], self.get_args().kernel_verbose)
+4 -10
ファイルの表示
@@ -29,7 +29,7 @@ import os
from pathlib import Path
import shutil
from utils.specs import get_machine_specs
from utils.utils import demarcate, trace_logger, get_version, get_version_display, detect_rocprof
from utils.utils import demarcate, trace_logger, get_version, get_version_display, detect_rocprof, error
from argparser import omniarg_parser
import config
import pandas as pd
@@ -107,12 +107,6 @@ class Omniperf:
self.__version["ver_pretty"] = get_version_display(vData["version"], vData["sha"], vData["mode"])
return
def error(self,message):
logging.error("")
logging.error("[ERROR]: " + message)
logging.error("")
sys.exit(1)
def detect_profiler(self):
#TODO:
# Currently this will only be called in profile mode
@@ -150,7 +144,7 @@ class Omniperf:
elif arch == "gfx90a":
target = "mi200"
else:
self.error("Unsupported SoC -> %s" % arch)
error("Unsupported SoC -> %s" % arch)
self.__soc_name.add(target)
if hasattr(self.__args, 'target'):
@@ -189,7 +183,7 @@ class Omniperf:
if self.__args.mode == None:
parser.print_help(sys.stderr)
self.error("Omniperf requires a valid mode.")
error("Omniperf requires a valid mode.")
return
@@ -248,7 +242,7 @@ class Omniperf:
from omniperf_analyze.analysis_webui import webui_analysis
analyzer = webui_analysis(self.__args,self.__options)
else:
self.error("Unsupported anlaysis mode -> %s" % self.__analyze_mode)
error("Unsupported anlaysis mode -> %s" % self.__analyze_mode)
#-----------------------
# run analysis workflow
+9 -15
ファイルの表示
@@ -27,7 +27,7 @@ import logging
import glob
import sys
import os
from utils.utils import capture_subprocess_output, run_prof, gen_sysinfo, run_rocscope
from utils.utils import capture_subprocess_output, run_prof, gen_sysinfo, run_rocscope, error
import config
class OmniProfiler_Base():
@@ -38,12 +38,6 @@ class OmniProfiler_Base():
self.__perfmon_dir = os.path.join(str(config.omniperf_home), "perfmon_configs")
def error(self,message):
logging.error("")
logging.error("[ERROR]: " + message)
logging.error("")
sys.exit(1)
def get_args(self):
return self.__args
@@ -58,22 +52,22 @@ class OmniProfiler_Base():
# verify not accessing parent directories
if ".." in str(self.__args.path):
self.error("Access denied. Cannot access parent directories in path (i.e. ../)")
error("Access denied. Cannot access parent directories in path (i.e. ../)")
# verify correct formatting for application binary
self.__args.remaining = self.__args.remaining[1:]
if self.__args.remaining:
if not os.path.isfile(self.__args.remaining[0]):
self.error("Your command %s doesn't point to a executable. Please verify." % self.__args.remaining[0])
error("Your command %s doesn't point to a executable. Please verify." % self.__args.remaining[0])
self.__args.remaining = " ".join(self.__args.remaining)
else:
self.error("Profiling command required. Pass application executable after -- at the end of options.\n\t\ti.e. omniperf profile -n vcopy -- ./vcopy 1048576 256")
error("Profiling command required. Pass application executable after -- at the end of options.\n\t\ti.e. omniperf profile -n vcopy -- ./vcopy 1048576 256")
# verify name meets MongoDB length requirements and no illegal chars
if len(self.__args.name) > 35:
self.error("-n/--name exceeds 35 character limit. Try again.")
error("-n/--name exceeds 35 character limit. Try again.")
if self.__args.name.find(".") != -1 or self.__args.name.find("-") != -1:
self.error("'-' and '.' are not permitted in -n/--name")
error("'-' and '.' are not permitted in -n/--name")
@abstractmethod
def run_profiling(self, version:str, prog:str):
@@ -112,7 +106,7 @@ class OmniProfiler_Base():
)
# log output from profile filtering
if not success:
self.error(output)
error(output)
else:
logging.debug(output)
@@ -129,7 +123,7 @@ class OmniProfiler_Base():
)
# log output from profile filtering
if not success:
self.error(output)
error(output)
else:
logging.debug(output)
logging.info("\nCurrent input file: %s" % fname)
@@ -141,7 +135,7 @@ class OmniProfiler_Base():
run_rocscope(self.__args, fname)
else:
#TODO: Finish logic
self.error("profiler not supported")
error("profiler not supported")
@abstractmethod
def post_processing(self):
+2 -2
ファイルの表示
@@ -25,7 +25,7 @@
import os
import config
from omniperf_soc.soc_base import OmniSoC_Base
from utils.utils import demarcate
from utils.utils import demarcate, error
class gfx906_soc (OmniSoC_Base):
def __init__(self,args):
@@ -72,7 +72,7 @@ class gfx906_soc (OmniSoC_Base):
"""
super().profiling_setup()
if self.get_args().roof_only:
self.error("%s does not support roofline analysis" % self.get_soc())
error("%s does not support roofline analysis" % self.get_soc())
# Perfmon filtering
self.perfmon_filter()
+2 -2
ファイルの表示
@@ -25,7 +25,7 @@
import os
import config
from omniperf_soc.soc_base import OmniSoC_Base
from utils.utils import demarcate
from utils.utils import demarcate, error
class gfx908_soc (OmniSoC_Base):
def __init__(self,args):
@@ -73,7 +73,7 @@ class gfx908_soc (OmniSoC_Base):
"""
super().profiling_setup()
if self.get_args().roof_only:
self.error("%s does not support roofline analysis" % self.get_soc())
error("%s does not support roofline analysis" % self.get_soc())
# Perfmon filtering
self.perfmon_filter(self.get_args().roof_only)
+2 -7
ファイルの表示
@@ -28,7 +28,7 @@ import os
import sys
import time
from dash import dcc
from utils.utils import mibench, gen_sysinfo, demarcate
from utils.utils import mibench, gen_sysinfo, demarcate, error
from dash import html
import plotly.graph_objects as go
from utils.roofline_calc import calc_ai, constuct_roof
@@ -40,11 +40,6 @@ class Roofline:
def __init__(self, args):
self.__args = args
def error(self,message):
logging.error("")
logging.error("[ERROR]: " + message)
logging.error("")
sys.exit(1)
def roof_setup(self):
# set default workload path if not specified
if self.__args.path == os.path.join(os.getcwd(), 'workloads'):
@@ -80,7 +75,7 @@ class Roofline:
if not os.path.isfile(app_path):
logging.info("[roofline] pmc_perf.csv not found. Generating...")
if not self.__args.remaining:
self.error("An <app_cmd> is required to run.\nomniperf profile -n test -- <app_cmd>")
error("An <app_cmd> is required to run.\nomniperf profile -n test -- <app_cmd>")
#TODO: Add an equivelent of characterize_app() to run profiling directly out of this module
elif self.__args.no_roof:
+6
ファイルの表示
@@ -47,6 +47,12 @@ def demarcate(function):
return result
return wrap_function
def error(message):
logging.error("")
logging.error("[ERROR]: " + message)
logging.error("")
sys.exit(1)
def trace_logger(message, *args, **kwargs):
logging.log(logging.TRACE, message, *args, **kwargs)