Skip to content

Commit

Permalink
Output score in separate file, add sort script
Browse files Browse the repository at this point in the history
  • Loading branch information
Synray committed Jan 25, 2020
1 parent 0044cf8 commit a17a56c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
13 changes: 13 additions & 0 deletions sort_cands.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

if [[ $1 < 2 ]]; then
echo "Usage: $0 output_dir"
echo "Ex: $0 nonmatchings/func_80000000"
exit 1
fi
if [[ ! -d $1 ]]; then
echo "Argument must be a directory"
exit 1
fi

find $1 -name score.txt -exec echo -n {}\ \; -exec cat {} \; | sort -rnk2
16 changes: 10 additions & 6 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ class EvalContext:
overall_profiler: Profiler = attr.ib(factory=Profiler)
permuters: List[Permuter] = attr.ib(factory=list)

def write_candidate(perm: Permuter, source: str) -> None:
def write_candidate(perm: Permuter, cand: Candidate) -> None:
"""Write the candidate's C source and score to the next output directory"""
ctr = 0
while True:
ctr += 1
Expand All @@ -166,10 +167,13 @@ def write_candidate(perm: Permuter, source: str) -> None:
break
except FileExistsError:
pass
fname = os.path.join(output_dir, 'source.c')
with open(fname, 'x') as f:
f.write(source)
print(f"wrote to {fname}")
source = os.path.join(output_dir, 'source.c')
score = os.path.join(output_dir, 'score.txt')
with open(source, 'x') as f:
f.write(cand.get_source())
with open(score, 'x') as f:
f.write(f"{cand.score_value}\n")
print(f"wrote to {output_dir}")

def post_score(context: EvalContext, permuter: Permuter, result: EvalResult) -> None:
if isinstance(result, EvalError):
Expand Down Expand Up @@ -213,7 +217,7 @@ def post_score(context: EvalContext, permuter: Permuter, result: EvalResult) ->
print(f"[{permuter.unique_name}] found different asm with same score")

source = cand.get_source()
write_candidate(permuter, source)
write_candidate(permuter, cand)
print("\b"*10 + " "*10 + "\r" + status_line, end='', flush=True)

def cycle_seeds(permuters: List[Permuter], force_seed: Optional[int]) -> Iterable[Tuple[int, int]]:
Expand Down

0 comments on commit a17a56c

Please sign in to comment.