Skip to content

Commit

Permalink
Merge pull request #35 from PDXCapstoneF/tl-reformatdev
Browse files Browse the repository at this point in the history
Reformat dev and update gitignore
  • Loading branch information
mbottini authored Apr 18, 2018
2 parents bfdd032 + 4f90099 commit 635cef9
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 86 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,9 @@ ENV/

# mypy
.mypy_cache/

# PyCharm project settings
.idea

# MacOS auto-generated
.DS_Store
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ install:
- pipenv install --dev
script:
- python -m unittest discover
- python main.py -h
- python mainCLI.py -h
before_deploy:
- pipenv uninstall --all # clean out any dev dependencies
- pipenv install # only add what we need
- pip install pyinstaller # install pyinstaller
- pyinstaller --onefile main.py # make our one-file executable
- pyinstaller --onefile mainCLI.py # make our one-file executable
deploy:
provider: releases
api_key: ${GITHUB_OAUTH_TOKEN}
Expand Down
28 changes: 20 additions & 8 deletions dialogue.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import json


def write_json(filename, python_dict):
"""
Serialize python_dict (dictionary) to filename (text file).
Expand All @@ -16,6 +17,7 @@ def write_json(filename, python_dict):
with open(filename, 'w') as f:
json.dump(python_dict, f, indent=4)


def read_json(filename):
"""
Deserializes json formatted string from filename (text file) as a dictionary.
Expand All @@ -24,6 +26,7 @@ def read_json(filename):
with open(filename) as f:
return json.load(f)


def create_run_dict(runtype, *args):
"""
Returns a dictionary of a run-type option object deserialized
Expand All @@ -41,13 +44,15 @@ def create_run_dict(runtype, *args):
return return_dict
return {}


def create_run_dict_list(runtype, args):
"""
Returns a dictionary of run-type option objects.
:param runtype: (HBIR || HBIR_RT || PRESET || LOADLEVEL)
"""
return create_run_dict(runtype, *args)


def create_run_sh_invocation(run_dict):
"""
Builds a string to be used to invoke the `run.sh` script in ~/workloads. The
Expand Down Expand Up @@ -78,6 +83,7 @@ def execute_run(run_dict):
return True
return False


def execute_runs(run_dict_list):
"""
A wrapper for `execute_run(...)`, which is invoked repeatedly for each set
Expand All @@ -87,25 +93,21 @@ def execute_runs(run_dict_list):
return [execute_run(run_dict) for run_dict in run_dict_list]








# Utility functions.

def print_dict(d):
for key, value in sorted(d.items(), key=lambda x : x[0]):
print("{}: {}".format(key, value))


# Level-one layer of dialogue.

def print_all_runs(run_dict, runtype_dict):
for k, v in sorted(run_dict.items(), key=lambda x : x[0]):
print('Run {}'.format(k))
print_dict(v)


def create_run(run_dict, runtype_dict):
run_name = input('Input a name for the run. ')
if run_name in run_dict:
Expand All @@ -122,6 +124,7 @@ def create_run(run_dict, runtype_dict):
return
run_dict[run_name] = create_run_dialogue(runtype_dict[run_type])


def create_runtype(run_dict, runtype_dict):
option_set = set()
user_input = input('Input a name for the runtype. ')
Expand All @@ -140,6 +143,7 @@ def create_runtype(run_dict, runtype_dict):
if runtype_name.lower() not in ['q', 'quit']:
runtype_dict[runtype_name] = list(option_set)


def delete_run(run_dict, runtype_dict):
try:
print('Input the tag of the run you want to delete.')
Expand All @@ -153,6 +157,7 @@ def delete_run(run_dict, runtype_dict):
return
print('Run deleted.')


def copy_run(run_dict, runtype_dict):
try:
print('Input the tag of the run you want to copy.')
Expand All @@ -166,6 +171,7 @@ def copy_run(run_dict, runtype_dict):
print('Unable to copy tag {}.'.format(old_run))
print('Run copied to {}.'.format(new_run))


def edit_run(run_dict, runtype_dict):
try:
print('Input the tag of the run you want to edit.')
Expand All @@ -178,6 +184,7 @@ def edit_run(run_dict, runtype_dict):
return
print('Run edited.')


def save_runlist(run_dict, runtype_dict):
filename = input('Input a filename to save the RunDict. ')
try:
Expand All @@ -187,6 +194,7 @@ def save_runlist(run_dict, runtype_dict):
return
print('Saved to {}'.format(filename))


def load_runlist(run_dict, runtype_dict):
filename = input('Input a filename to load a RunDict from. ')
try:
Expand All @@ -196,6 +204,7 @@ def load_runlist(run_dict, runtype_dict):
return
print('RunDict loaded from {}'.format(filename))


def new_runlist(run_dict, runtype_dict):
user_input = input('Are you sure? This will remove all runs from the RunDict!')
if user_input.lower() in ['y', 'yes']:
Expand All @@ -204,22 +213,26 @@ def new_runlist(run_dict, runtype_dict):
else:
print('RunDict has not been modified.')


def error(run_dict, runtype_dict):
print('Invalid input.')



def create_run_dialogue(arg_list):
new_run = {}
for arg in arg_list:
new_run[arg] = input("Input value for {}: ".format(arg))
return new_run


def edit_run_dialogue(old_run):
new_run = {}
for key, value in sorted(old_run.items(), key=lambda x : x[0]):
new_run[key] = input("Input value for {}. Current value = {}. ".format(
key, value))
return new_run


def dialogue():
"""
A dialogue function for creating a RunDict.
Expand Down Expand Up @@ -280,4 +293,3 @@ def dialogue():
if user_input.lower() not in ['q', 'quit']:
function_dict.get(user_input, error)(run_dict, runtype_dict)
print('Exiting.')

42 changes: 21 additions & 21 deletions example_config.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
{
"specjbb": {
"run_type": "LOADLEVEL",
"kit_version": "RC3",
"tag": "Run-Identifier",
"jdk": "jdk.8-u121",
"rt_start": 30,
"duration": 60,
"jvm_options": [
"-Xms29g",
"-Xmx29g",
"-Xmn27g",
"-XX:ParallelGCThreads=48"
],
"numa_node": 4,
"data": "NONE",
"t": [
154,
45,
23
]
}
"specjbb": {
"run_type": "LOADLEVEL",
"kit_version": "RC3",
"tag": "Run-Identifier",
"jdk": "jdk.8-u121",
"rt_start": 30,
"duration": 60,
"jvm_options": [
"-Xms29g",
"-Xmx29g",
"-Xmn27g",
"-XX:ParallelGCThreads=48"
],
"numa_node": 4,
"data": "NONE",
"t": [
154,
45,
23
]
}
}
13 changes: 8 additions & 5 deletions main.py → mainCLI.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""SPECtate.
Usage:
main.py run <config> [--props <props>]
main.py (-h | --help)
main.py --version
main.py dialogue
mainCLI.py run <config> [--props <props>]
mainCLI.py (-h | --help)
mainCLI.py --version
mainCLI.py dialogue
"""
# library imports
import json
Expand All @@ -17,6 +17,7 @@
# source imports
import dialogue


def to_list(s):
if s['run_type'].lower() in ["hbir", "hbir_rt"]:
return [
Expand Down Expand Up @@ -48,6 +49,7 @@ def to_list(s):
s["t"][2], # t3
]


def do_run(arguments):
"""
Does a run using scripts/run.sh from the provided property template and configuration.
Expand All @@ -60,11 +62,11 @@ def do_run(arguments):
cwd=os.path.join(os.path.dirname(__file__), 'scripts')
)


def do_dialogue(arguments):
dialogue.dialogue()



# dictionary of runnables
# these are functions that take arguments from the
# command line and do something with them.
Expand All @@ -73,6 +75,7 @@ def do_dialogue(arguments):
'dialogue' : do_dialogue
}


if __name__ == "__main__":
arguments = docopt(__doc__, version='SPECtate v0.1')

Expand Down
100 changes: 50 additions & 50 deletions runtype_options.json
Original file line number Diff line number Diff line change
@@ -1,54 +1,54 @@
{
"HBIR" : [
"Kit Version",
"Tag",
"JDK",
"RTSTART",
"JVM Options",
"NUMA Nodes",
"Data Collection",
"T1",
"T2",
"T3"
],
"HBIR_RT" : [
"Kit Version",
"Tag",
"JDK",
"RTSTART",
"JVM Options",
"NUMA Nodes",
"Data Collection",
"T1",
"T2",
"T3"
],
"PRESET" : [
"kitVersion",
"tag",
"JDK",
"TXrate",
"Duration",
"JVMoptions",
"NUMA_Node",
"Data Collection",
"T1",
"T2",
"T3"
],
"LOADLEVEL" : [
"kitVersion",
"Tag",
"JDK",
"TXrate",
"Duration",
"JVMoptions",
"NUMA_Node",
"Data Collection",
"T1",
"T2",
"T3"
]
"HBIR": [
"Kit Version",
"Tag",
"JDK",
"RTSTART",
"JVM Options",
"NUMA Nodes",
"Data Collection",
"T1",
"T2",
"T3"
],
"HBIR_RT": [
"Kit Version",
"Tag",
"JDK",
"RTSTART",
"JVM Options",
"NUMA Nodes",
"Data Collection",
"T1",
"T2",
"T3"
],
"PRESET": [
"kitVersion",
"tag",
"JDK",
"TXrate",
"Duration",
"JVMoptions",
"NUMA_Node",
"Data Collection",
"T1",
"T2",
"T3"
],
"LOADLEVEL": [
"kitVersion",
"Tag",
"JDK",
"TXrate",
"Duration",
"JVMoptions",
"NUMA_Node",
"Data Collection",
"T1",
"T2",
"T3"
]
}


0 comments on commit 635cef9

Please sign in to comment.