Skip to content

Commit

Permalink
Merge pull request #276 from tomhea/feature/bugfix
Browse files Browse the repository at this point in the history
Feature/bugfix
  • Loading branch information
tomhea authored Aug 19, 2024
2 parents aa01b31 + 1023b15 commit aaeb6ff
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
9 changes: 5 additions & 4 deletions flipjump/interpretter/debugging/macro_usage_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def _prepare_first_and_second_level_significant_macros(
if len(k_split) != 2:
continue
parent, name = k_split
if float(v) / macro_code_size[parent] < child_significance_min_thresh:
if macro_code_size[parent] == 0 or float(v) / macro_code_size[parent] < child_significance_min_thresh:
continue
if len(name.split(':')) == 4: # if it's a rep
continue
Expand Down Expand Up @@ -60,9 +60,10 @@ def _show_macro_usage_graph(chosen_macros: List[Tuple[str, int]]) -> None:
ordered_chosen_macros = sorted(chosen_macros, key=lambda name_count: name_count[1], reverse=True)
total_ops = sum([count for name, count in chosen_macros])

print('\n\n\nThe most used macros are:\n')
for macro_name, ops_count in ordered_chosen_macros:
print(f' {macro_name}: {ops_count:,} ops ({ops_count / total_ops:.2%})')
if total_ops > 0:
print('\n\n\nThe most used macros are:\n')
for macro_name, ops_count in ordered_chosen_macros:
print(f' {macro_name}: {ops_count:,} ops ({ops_count / total_ops:.2%})')
print(
"\n\n* The statistics can be displayed in an interactive graph - "
"that feature requires the plotly python library. *\n"
Expand Down
8 changes: 6 additions & 2 deletions flipjump/interpretter/fjm_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ def print(
@param output_to_print: if specified and terminated not by looping - print the given output.
"""

flips_percentage = self.flip_counter / self.op_counter * 100
jumps_percentage = self.jump_counter / self.op_counter * 100
if self.op_counter:
flips_percentage = self.flip_counter / self.op_counter * 100
jumps_percentage = self.jump_counter / self.op_counter * 100
else:
flips_percentage = 0
jumps_percentage = 0

last_ops_str = ''
output_str = ''
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ mypy = { version = "^1.7.1", optional = true }
flake8 = { version = "^6.1.0", optional = true }
tox = { version = "^4.11.4", optional = true }
bandit = { version = "^1.7.6", optional = true }
black = { version = "^23.12.0", optional = true }
black = { version = "^24.8.0", optional = true }

[tool.poetry.extras]
tests = [
Expand Down

0 comments on commit aaeb6ff

Please sign in to comment.