Skip to content

Commit

Permalink
#10855: Change process_ops_logs to support clearing existing logs and…
Browse files Browse the repository at this point in the history
… returning the ops report
  • Loading branch information
jdesousa-TT committed Aug 23, 2024
1 parent 1111b13 commit 2649e7c
Showing 1 changed file with 26 additions and 19 deletions.
45 changes: 26 additions & 19 deletions tt_metal/tools/profiler/process_ops_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,9 @@ def append_device_data(ops, deviceLogFolder):
return deviceOps


def get_device_data_generate_report(deviceLogFolder, outputFolder, date, nameAppend):
def get_device_data_generate_report(
deviceLogFolder, outputFolder, date, nameAppend, export_csv=True, cleanup_device_log=False
):
deviceTimesLog = os.path.join(deviceLogFolder, PROFILER_DEVICE_SIDE_LOG)
devicePreOpTime = {}
deviceOps = {}
Expand All @@ -232,11 +234,12 @@ def get_device_data_generate_report(deviceLogFolder, outputFolder, date, nameApp
name += f"_{dateStr}"
outFolder = os.path.join(outFolder, dateStr)

allOpsCSVPath = os.path.join(outFolder, f"{name}.csv")
logger.info(f"Copying runtime artifacts")
os.system(f"rm -rf {outFolder}; mkdir -p {outFolder}")
if os.path.isfile(f"{PROFILER_LOGS_DIR / PROFILER_DEVICE_SIDE_LOG}"):
os.system(f"cp {PROFILER_LOGS_DIR / PROFILER_DEVICE_SIDE_LOG} {outFolder}")
if export_csv:
allOpsCSVPath = os.path.join(outFolder, f"{name}.csv")
logger.info(f"Copying runtime artifacts")
os.system(f"rm -rf {outFolder}; mkdir -p {outFolder}")
if os.path.isfile(f"{PROFILER_LOGS_DIR / PROFILER_DEVICE_SIDE_LOG}"):
os.system(f"cp {PROFILER_LOGS_DIR / PROFILER_DEVICE_SIDE_LOG} {outFolder}")

if os.path.isfile(deviceTimesLog):
logger.info(f"Getting device only ops data")
Expand Down Expand Up @@ -283,21 +286,25 @@ def get_device_data_generate_report(deviceLogFolder, outputFolder, date, nameApp
devicePreOpTime[device] = analysisData[0]["end_cycle"]
rowDicts.append(rowDict)

with open(allOpsCSVPath, "w") as allOpsCSV:
allHeaders = []
for header in OPS_CSV_HEADER:
if header in rowDicts[-1].keys():
allHeaders.append(header)
writer = csv.DictWriter(allOpsCSV, fieldnames=allHeaders)
writer.writeheader()
for rowDict in rowDicts:
for field, fieldData in rowDict.items():
rowDict[field] = str(fieldData).replace(",", ";")
writer.writerow(rowDict)
logger.info(f"Device only OPs csv generated at: {allOpsCSVPath}")
if export_csv:
with open(allOpsCSVPath, "w") as allOpsCSV:
allHeaders = []
for header in OPS_CSV_HEADER:
if header in rowDicts[-1].keys():
allHeaders.append(header)
writer = csv.DictWriter(allOpsCSV, fieldnames=allHeaders)
writer.writeheader()
for rowDict in rowDicts:
for field, fieldData in rowDict.items():
rowDict[field] = str(fieldData).replace(",", ";")
writer.writerow(rowDict)
logger.info(f"Device only OPs csv generated at: {allOpsCSVPath}")

if cleanup_device_log:
os.remove(deviceTimesLog)
else:
logger.info("No device logs found")
return deviceOps
return rowDicts


def generate_reports(ops, deviceOps, signposts, outputFolder, date, nameAppend):
Expand Down

0 comments on commit 2649e7c

Please sign in to comment.