Skip to content

Instantly share code, notes, and snippets.

@teju85
Created July 23, 2024 13:04
Show Gist options
  • Save teju85/8d09c985d07faf40686ec0639ef06f36 to your computer and use it in GitHub Desktop.
Save teju85/8d09c985d07faf40686ec0639ef06f36 to your computer and use it in GitHub Desktop.
Analyze the output "nvcc -time ..."
#!/usr/bin/env python
import argparse
import pandas as pd
TO_MS = {
" s" : 1000,
" ms" : 1,
" us" : 0.001,
" ns" : 0.000001,
}
def parse_args():
argparser = argparse.ArgumentParser("`nvcc -time` visualizer")
argparser.add_argument("csv", type=str,
help="CSV file containing the output of `nvcc -time`")
args = argparser.parse_args()
return args
def phasewise(df):
df_by_phase = df.groupby(" phase name ")
phases = {
"phase" : [],
"time(ms)" : [],
}
for phase, grp in df_by_phase:
phases["phase"].append(phase)
phases["time(ms)"].append(grp["time(ms)"].sum())
phase = pd.DataFrame(phases)
phase.sort_values(by="time(ms)", ascending=False, inplace=True)
print("Total cpu time (in ms) spent phase-wise:")
for ind in phase.index:
print("%32s : %13.3f" % (phase["phase"][ind], phase["time(ms)"][ind]))
pass
def filewise(df):
df_by_file = df.groupby("source file name ")
files = {
"file" : [],
"time(ms)" : [],
}
for file, grp in df_by_file:
files["file"].append(file)
files["time(ms)"].append(grp["time(ms)"].sum())
file = pd.DataFrame(files)
file.sort_values(by="time(ms)", ascending=False, inplace=True)
breakdown = {}
print("Total cpu time (in ms) spent file-wise, across the top 10 files:")
for id, ind in enumerate(file.index):
f = file["file"][ind]
print("%13.3f : %s" % (file["time(ms)"][ind], f))
breakdown[f] = df_by_file.get_group(f).sort_values(by="time(ms)", ascending=False)
if id > 10:
break
print("Breakdown of total cpu time (in ms) spent file-wise, across the top 10 files:")
for id, ind in enumerate(file.index):
f = file["file"][ind]
print(" %s:" % f)
for j in breakdown[f].index:
print(" %32s : %13.3f" % (breakdown[f][" phase name "][j], breakdown[f]["time(ms)"][j]))
if id > 10:
break
pass
def main():
args = parse_args()
df = pd.read_csv(args.csv)
df["time(ms)"] = df.apply(lambda row: row[" metric "] * TO_MS[row[" unit"]], axis=1)
phasewise(df)
filewise(df)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment