Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added csv to gas-profiling #94

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion boa/profiling.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from boa.environment import Env
from boa.vyper.ast_utils import get_fn_name_from_lineno, get_line

import csv

@dataclass(unsafe_hash=True)
class LineInfo:
Expand Down Expand Up @@ -357,6 +358,10 @@ def get_line_profile_table(env: Env) -> Table:
gas_data
)

csv_file_name = "gas-profile.csv"
with open(csv_file_name, 'w', newline='') as csvfile: #rewrite if the file already exists
pass

table = _create_table(for_line_profile=True)
for (contract_name, contract_address), fn_data in contracts.items():
contract_file_path = os.path.split(contract_name)
Expand All @@ -367,6 +372,15 @@ def get_line_profile_table(env: Env) -> Table:
f"{'-'*52}"
)

with open(csv_file_name, 'a', newline='') as csvfile:
csvwriter = csv.writer(csvfile, delimiter=',')
csvwriter.writerows([[""], ["*" * 200]])
csvwriter.writerow(
["Contract", "Computation", "Count", "Mean", "Median", "Stdev", "Min", "Max"])
csvwriter.writerow([f"Path: {contract_file_path[0]}"])
csvwriter.writerow([f"Name: {contract_file_path[1]}"])
csvwriter.writerow([f"Address: {contract_address}"])

table.add_row(
contract_data_str,
"\n\n\n" + "-" * 74,
Expand Down Expand Up @@ -395,8 +409,14 @@ def get_line_profile_table(env: Env) -> Table:
cname = ""
if c == 0:
cname = f"Function: {fn_name}"
with open(csv_file_name, 'a', newline='') as csvfile:
csvwriter = csv.writer(csvfile, delimiter=',')
csvwriter.writerow([cname,*profile[2:]])
table.add_row(cname, *profile[2:])

with open(csv_file_name, 'a', newline='') as csvfile:
csvwriter = csv.writer(csvfile, delimiter=',')
csvwriter.writerow([""]) # empty row after each function

if not num_fn + 1 == len(fn_data):
table.add_row("-" * 52, "-" * 74, *["-----"] * (len(profile[2:]) - 1))
num_fn += 1
Expand Down
Loading