-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
677b29e
commit c8e6c9f
Showing
5 changed files
with
183 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import random | ||
from pathlib import Path | ||
|
||
|
||
def select_files_randomly(population, sample_size): | ||
if sample_size > len(population): | ||
print("Sample size is larger than the population size.") | ||
return [] | ||
|
||
selected_files = random.sample(population, sample_size) | ||
|
||
return selected_files | ||
|
||
|
||
analysis_sensitivities = "../micro-benchmark/analysis_sensitivities" | ||
python_features = "../micro-benchmark/python_features" | ||
file_extension = "*.py" | ||
|
||
|
||
analysis_sensitivities_population = sorted(Path(analysis_sensitivities).rglob("*.py")) | ||
python_features_population = sorted(Path(python_features).rglob("*.py")) | ||
|
||
|
||
sample_size = 10 # Desired sample size | ||
selected_files_analysis_sensitivities = select_files_randomly( | ||
analysis_sensitivities_population, sample_size | ||
) | ||
selected_files_python_features = select_files_randomly( | ||
python_features_population, sample_size | ||
) | ||
|
||
print("Selected files for evaluation from analysis_sensitivities:") | ||
for file_name in selected_files_analysis_sensitivities: | ||
print(file_name) | ||
|
||
print("\n####\n") | ||
|
||
print("Selected files for evaluation from python_features:") | ||
for file_name in selected_files_python_features: | ||
print(file_name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import argparse | ||
import json | ||
import logging | ||
import os | ||
from pathlib import Path | ||
|
||
from scalpel.typeinfer.typeinfer import TypeInference | ||
|
||
# Create a logger | ||
logger = logging.getLogger("runner") | ||
logger.setLevel(logging.DEBUG) | ||
|
||
file_handler = logging.FileHandler("/tmp/scalpel_log.log") | ||
file_handler.setLevel(logging.DEBUG) | ||
|
||
console_handler = logging.StreamHandler() | ||
console_handler.setLevel(logging.DEBUG) | ||
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s") | ||
file_handler.setFormatter(formatter) | ||
console_handler.setFormatter(formatter) | ||
logger.addHandler(file_handler) | ||
logger.addHandler(console_handler) | ||
|
||
|
||
def list_python_files(folder_path): | ||
python_files = sorted(Path(folder_path).rglob("*.py")) | ||
return python_files | ||
|
||
|
||
def main_runner(args): | ||
python_files = list_python_files(args.bechmark_path) | ||
error_count = 0 | ||
for file in python_files: | ||
try: | ||
logger.info(file) | ||
inferer = TypeInference(name=file, entry_point=file) | ||
inferer.infer_types() | ||
inferred = inferer.get_types() | ||
json_file_path = str(file).replace(".py", "_result.json") | ||
|
||
with open(json_file_path, "w") as json_file: | ||
inferred_serializable = [ | ||
{k: list(v) if isinstance(v, set) else v for k, v in d.items()} | ||
for d in inferred | ||
] | ||
json.dump(inferred_serializable, json_file, indent=4) | ||
except Exception as e: | ||
logger.info(f"Command returned non-zero exit status: {e} for file: {file}") | ||
error_count += 1 | ||
|
||
logger.info(f"Runner finished with errors:{error_count}") | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument( | ||
"--bechmark_path", | ||
help="Specify the benchmark path", | ||
default="/tmp/micro-benchmark", | ||
) | ||
|
||
args = parser.parse_args() | ||
main_runner(args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters