Skip to content

Commit ddc3dc7

Browse files
committed
suppress plot messages using logging levels
- debug messages will not show on normal operation Signed-off-by: Jack Luar <[email protected]>
1 parent 0273570 commit ddc3dc7

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

tools/AutoTuner/scripts/plot.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import os
4343
import argparse
4444
import sys
45+
import logging
4546

4647
# Only does plotting for AutoTunerBase variants
4748
AT_REGEX = r"variant-AutoTunerBase-([\w-]+)-\w+"
@@ -53,6 +54,13 @@
5354
root_dir = os.path.join(cur_dir, "../../../")
5455
os.chdir(root_dir)
5556

57+
# Setup logging
58+
logger = logging.getLogger(__name__)
59+
logging.basicConfig(
60+
level=logging.INFO,
61+
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
62+
)
63+
5664

5765
def load_dir(dir: str) -> pd.DataFrame:
5866
"""
@@ -68,7 +76,7 @@ def load_dir(dir: str) -> pd.DataFrame:
6876
# Concatenate progress DFs
6977
progress_csvs = glob.glob(f"{dir}/*/progress.csv")
7078
if len(progress_csvs) == 0:
71-
print("No progress.csv files found.")
79+
logger.error("No progress.csv files found in the directory.")
7280
sys.exit(1)
7381
progress_df = pd.concat([pd.read_csv(f) for f in progress_csvs])
7482

@@ -91,24 +99,24 @@ def load_dir(dir: str) -> pd.DataFrame:
9199
params.append(_dict)
92100
except Exception as e:
93101
failed.append(metrics_fname)
94-
print("Failed to load", metrics_fname)
95-
print(e)
102+
logger.debug(f"Failed to load {params_fname} or {metrics_fname}.")
103+
logger.debug(f"Exception: {e}")
96104
continue
97105

98106
# Merge all dataframe
99107
params_df = pd.DataFrame(params)
100108
try:
101109
progress_df = progress_df.merge(params_df, on="trial_id")
102110
except KeyError:
103-
print(
111+
logger.error(
104112
"Unable to merge DFs due to missing trial_id in params.json (possibly due to failed trials.)"
105113
)
106114
sys.exit(1)
107115

108116
# Print failed, if any
109117
if failed:
110118
failed_files = "\n".join(failed)
111-
print(f"Failed to load {len(failed)} files:\n{failed_files}")
119+
logger.debug(f"Failed to load {len(failed)} files:\n{failed_files}")
112120
return progress_df
113121

114122

@@ -145,7 +153,7 @@ def preprocess(df: pd.DataFrame) -> pd.DataFrame:
145153
df["timestamp"] -= df["timestamp"].min()
146154
return df
147155
except KeyError as e:
148-
print(
156+
logger.error(
149157
f"KeyError: {e} in the DataFrame. Dataframe does not contain necessary columns."
150158
)
151159
sys.exit(1)
@@ -176,12 +184,12 @@ def plot(df: pd.DataFrame, key: str, dir: str):
176184
ax.plot(
177185
df["timestamp"],
178186
poly_func(df["timestamp"]),
179-
"r--",
187+
"r--logger.error",
180188
label=f"y={coeff[0]:.2f}x+{coeff[1]:.2f}",
181189
)
182190
ax.legend()
183191
except np.linalg.LinAlgError:
184-
print("Cannot fit a line to the data, plotting only scatter plot.")
192+
logger.info("Cannot fit a line to the data, plotting only scatter plot.")
185193

186194
fig.savefig(f"{dir}/{key}.png")
187195

@@ -209,16 +217,15 @@ def main(platform: str, design: str, experiment: str):
209217
img_dir = os.path.join(
210218
root_dir, f"./flow/reports/images/{platform}/{design}/{experiment}"
211219
)
212-
print("Processing results from", results_dir)
220+
logger.info(f"Processing results from {results_dir}")
213221
os.makedirs(img_dir, exist_ok=True)
214222
df = load_dir(results_dir)
215223
df = preprocess(df)
216224
keys = [METRIC] + ["runtime", "clk_period", "worst_slack"]
217225

218226
# Plot only if more than one entry
219227
if len(df) < 2:
220-
print("Less than 2 entries, skipping plotting.")
221-
sys.exit(0)
228+
logger.info("Less than 2 entries, skipping plotting.")
222229
for key in keys:
223230
plot(df, key, img_dir)
224231

0 commit comments

Comments
 (0)