Skip to content

Commit

Permalink
Fixed solution analyses
Browse files Browse the repository at this point in the history
  • Loading branch information
AryazE committed Sep 9, 2023
1 parent f038255 commit ef72f20
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
12 changes: 1 addition & 11 deletions tutorial/solution-analyses/CallGraphAnalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,4 @@ def end_execution(self):
DynaPyt hook for end of execution
"""
# to avoid serialization failures in converting dict to json
try:
logging.info(json.dumps(self.graph))
except Exception:
logging.info("{")
for idx, key in enumerate(self.graph):
values = ['"{}"'.format(x) for x in self.graph[key]]
if not idx == (len(self.graph.keys()) - 1):
logging.info('"{}" : {}, '.format(key, values))
else:
logging.info('"{}" : {}'.format(key, values))
logging.info("}")
print(self.graph)
13 changes: 10 additions & 3 deletions tutorial/solution-analyses/SlowStringConcatAnalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,15 @@ def __init__(self):
self.threshold = 5

def enter_for(self, dyn_ast: str, iid: int, next_value, iterable: Iterable):
self.in_loop.append((dyn_ast, iid))
self.concat_count.append(0)
if (
self.in_loop
and self.in_loop[-1][0] == dyn_ast
and self.in_loop[-1][1] == iid
):
pass
else:
self.in_loop.append((dyn_ast, iid))
self.concat_count.append(0)

def exit_for(self, dyn_ast: str, iid: int):
curr = self.in_loop.pop()
Expand All @@ -21,7 +28,7 @@ def exit_for(self, dyn_ast: str, iid: int):

def add_assign(self, dyn_ast: str, iid: int, lhs, rhs):
if self.in_loop:
if isinstance(lhs, str) and isinstance(rhs, str):
if isinstance(rhs, str):
self.concat_count[-1] += 1
if self.concat_count[-1] >= self.threshold:
print(f"Possible slow string concatenation in {dyn_ast} at {iid}")

0 comments on commit ef72f20

Please sign in to comment.