diff --git a/comparative_analyzer/ComparativeAnalyzer.py b/comparative_analyzer/ComparativeAnalyzer.py index c1cb3b7..9f176bb 100755 --- a/comparative_analyzer/ComparativeAnalyzer.py +++ b/comparative_analyzer/ComparativeAnalyzer.py @@ -4,10 +4,8 @@ # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. - +import argparse from datetime import datetime -import imp -from optparse import OptionParser import matplotlib.pyplot as plt from mpl_toolkits.axes_grid1.inset_locator import ( inset_axes, @@ -20,7 +18,6 @@ import pickle import seaborn as sns import sys -import time sys.path = ["./", "../"] + sys.path @@ -208,34 +205,10 @@ def RelativeDegradation(combined_stat_df): plt.close() -def main(argv=None): +def main(options): """ The main function. """ - parser = OptionParser() - parser.add_option( - "-s", - "--since", - dest="since", - help="compare archives since time", - action="store_true", - ) - parser.add_option( - "-p", - "--plot", - dest="plot", - help="plots default comparative test results", - action="store_true", - ) - parser.add_option( - "-c", - "--customized_plot", - dest="customized_plot", - help="specify a customized plotting string", - metavar="FILE", - ) - (options, args) = parser.parse_args() - logger.info("Comparative Analyzer started") print("Log file -> logs/CA.log") @@ -259,7 +232,7 @@ def main(argv=None): archive_files, options.plot ) - if (options.plot) or (argv is None): + if options.plot: ComparativePlotting(t_df=combined_test_df, p_df_dic=combined_perf_df_dic) elif options.customized_plot is not None: cp = options.customized_plot.replace(".py", "") @@ -274,4 +247,30 @@ def main(argv=None): if __name__ == "__main__": - main(sys.argv) + """ + The main function. + """ + parser = argparse.ArgumentParser() + parser.add_argument( + "-s", + "--since", + dest="since", + help="compare archives since time", + action="store_true", + ) + parser.add_argument( + "-p", + "--plot", + dest="plot", + help="plots default comparative test results", + action="store_true", + ) + parser.add_argument( + "-c", + "--customized_plot", + dest="customized_plot", + help="specify a customized plotting string", + metavar="FILE", + ) + options = parser.parse_args() + main(options) diff --git a/synthetic_workload_invoker/WorkloadChecker.py b/synthetic_workload_invoker/WorkloadChecker.py index 8d4368c..a23baeb 100644 --- a/synthetic_workload_invoker/WorkloadChecker.py +++ b/synthetic_workload_invoker/WorkloadChecker.py @@ -67,7 +67,7 @@ def CheckWorkloadValidity(workload): "Please enter a valid value for test_duration_in_seconds field in the config file." ) return False - elif int(test_duration_in_seconds) <= 0: + if int(test_duration_in_seconds) <= 0: logger_wlch.error("test_duration_in_seconds should be greater than zero!") return False except: diff --git a/synthetic_workload_invoker/WorkloadInvoker.py b/synthetic_workload_invoker/WorkloadInvoker.py index e121fb9..0783be7 100755 --- a/synthetic_workload_invoker/WorkloadInvoker.py +++ b/synthetic_workload_invoker/WorkloadInvoker.py @@ -6,8 +6,8 @@ # LICENSE file in the root directory of this source tree. # Standard imports +import argparse import json -from optparse import OptionParser import os from requests_futures.sessions import FuturesSession import subprocess @@ -39,9 +39,10 @@ RESULT = "true" -def PROCESSInstanceGenerator(instance, instance_script, instance_times, blocking_cli): +def PROCESSInstanceGenerator(instance_script, instance_times, blocking_cli): """ Deprecated. This function was used to invoke a function in OpenWhisk using new processes. + You can use this approach, but it is not recommended due to high overhead. """ if len(instance_times) == 0: return False @@ -73,7 +74,7 @@ def HTTPInstanceGeneratorOW(action, instance_times, blocking_cli, param_file=Non authentication = (user_pass[0], user_pass[1]) after_time, before_time = 0, 0 - if param_file == None: + if param_file is None: st = 0 for t in instance_times: st = st + t - (after_time - before_time) @@ -149,7 +150,7 @@ def HTTPInstanceGeneratorGeneric(instance_times, blocking_cli, url, data): """ if len(instance_times) == 0: return False - if (validators.url(url) != True): + if validators.url(url) is not True: logger.error("Invalid URL: " + url) return False @@ -209,7 +210,6 @@ def CreateActionInvocationThreads(workload, all_events): args=[instance_times, blocking_cli, url, data], ) ) - pass return threads @@ -220,15 +220,15 @@ def main(argv): """ logger.info("Workload Invoker started") print("Log file -> logs/SWI.log") - parser = OptionParser() - parser.add_option( + parser = argparse.ArgumentParser() + parser.add_argument( "-c", "--config_json", dest="config_json", help="The input json config file describing the synthetic workload.", metavar="FILE", ) - (options, args) = parser.parse_args() + options = parser.parse_args() if not CheckJSONConfig(options.config_json): logger.error("You should specify a JSON config file using -c option!") diff --git a/tests/unit_tests/ComparativeAnalyzer_test.py b/tests/unit_tests/ComparativeAnalyzer_test.py index e5c4725..3b14a83 100644 --- a/tests/unit_tests/ComparativeAnalyzer_test.py +++ b/tests/unit_tests/ComparativeAnalyzer_test.py @@ -4,10 +4,10 @@ # LICENSE file in the root directory of this source tree. import datetime +import os from os.path import exists import unittest from comparative_analyzer.ComparativeAnalyzer import * -import comparative_analyzer.ComparativeAnalyzer as CA class TestComparativeAnalyzer(unittest.TestCase): @@ -27,9 +27,10 @@ def test_GetTimeFromDFNameNoInput(self): self.assertEqual(str(sampleDT), "2021-01-18 04:37:00") def test_ComparativeAnalyzer_Script(self): - CA.main() + os.system("./ComparativeAnalyzer -p") self.assertTrue(exists("sample_comparative_plot.png")) if __name__ == "__main__": - unittest.main() + runner = unittest.TextTestRunner() + runner.run(unittest.TestLoader().loadTestsFromTestCase(TestComparativeAnalyzer)) diff --git a/tests/unit_tests/EventGenerator_test.py b/tests/unit_tests/EventGenerator_test.py index 39a683e..f85dca0 100644 --- a/tests/unit_tests/EventGenerator_test.py +++ b/tests/unit_tests/EventGenerator_test.py @@ -62,4 +62,5 @@ def test_GenericEventGenerator_Normal(self): if __name__ == "__main__": - unittest.main() + runner = unittest.TextTestRunner() + runner.run(unittest.TestLoader().loadTestsFromTestCase(TestEventGenerator)) diff --git a/tests/unit_tests/WorkloadAnalyzer_test.py b/tests/unit_tests/WorkloadAnalyzer_test.py index 556cbfd..1845d2b 100644 --- a/tests/unit_tests/WorkloadAnalyzer_test.py +++ b/tests/unit_tests/WorkloadAnalyzer_test.py @@ -28,4 +28,5 @@ def test_ConstructConfigDataframe(self): if __name__ == "__main__": - unittest.main() + runner = unittest.TextTestRunner() + runner.run(unittest.TestLoader().loadTestsFromTestCase(TestWorkloadAnalyzer)) diff --git a/tests/unit_tests/WorkloadChecker_test.py b/tests/unit_tests/WorkloadChecker_test.py index e80882b..fc9bfb0 100644 --- a/tests/unit_tests/WorkloadChecker_test.py +++ b/tests/unit_tests/WorkloadChecker_test.py @@ -19,4 +19,5 @@ def test_CheckWorkloadValidity(self): if __name__ == "__main__": - unittest.main() + runner = unittest.TextTestRunner() + runner.run(unittest.TestLoader().loadTestsFromTestCase(TestWorkloadChecker)) diff --git a/tests/unit_tests/WorkloadInvoker_test.py b/tests/unit_tests/WorkloadInvoker_test.py index e612433..5a6a0fe 100644 --- a/tests/unit_tests/WorkloadInvoker_test.py +++ b/tests/unit_tests/WorkloadInvoker_test.py @@ -12,7 +12,7 @@ def test_HTTPInstanceGeneratorGenerics(self): status = HTTPInstanceGeneratorGeneric( instance_times=[1.0, 1.0, 1.0, 1.0], blocking_cli=0, - url="http://localhost:8080", + url="http://127.0.0.1:8080", data="", ) self.assertTrue(status) @@ -21,7 +21,7 @@ def test_HTTPInstanceGeneratorGenerics_with_empty_instance_times(self): status = HTTPInstanceGeneratorGeneric( instance_times=[], blocking_cli=0, - url="http://localhost:8080", + url="http://127.0.0.1:8080", data="", ) self.assertFalse(status) @@ -46,4 +46,5 @@ def test_HTTPInstanceGeneratorGenerics_with_invalid_url(self): if __name__ == "__main__": - unittest.main() + runner = unittest.TextTestRunner() + runner.run(unittest.TestLoader().loadTestsFromTestCase(TestWorkloadInvoker)) diff --git a/workload_analyzer/WorkloadAnalyzer.py b/workload_analyzer/WorkloadAnalyzer.py index ccc260c..85e76ef 100755 --- a/workload_analyzer/WorkloadAnalyzer.py +++ b/workload_analyzer/WorkloadAnalyzer.py @@ -1,14 +1,14 @@ #!/usr/bin/env python3 -# Copyright (c) 2019 Princeton University +# Copyright (c) 2019 Princeton University, 2024 UBC # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. # Standard +import argparse from datetime import datetime import json -from optparse import OptionParser import os from os.path import isfile, join import pandas as pd @@ -178,9 +178,9 @@ def NormalizeMemoryValue(mem_string): """ if mem_string[-1] == "G": return float(mem_string[:-1]) - elif mem_string[-1] == "M": + if mem_string[-1] == "M": return float(mem_string[:-1]) / 1024.0 - elif mem_string[-1] == "K": + if mem_string[-1] == "K": return float(mem_string[:-1]) / (1024 * 1024.0) @@ -221,7 +221,7 @@ def GetControlGroupsRecords(since=None): "docker_tasks": [], "memory": [], } - if since == None: + if since is None: logger.error("No since parameter entered!") return None log_path = FAAS_ROOT + "/logs" @@ -274,53 +274,53 @@ def main(argv): """ The main function. """ - parser = OptionParser() - parser.add_option( + parser = argparse.ArgumentParser() + parser.add_argument( "-v", "--verbose", dest="verbose", help="prints the detailed test data", action="store_true", ) - parser.add_option( + parser.add_argument( "-p", "--plot", dest="plot", help="plots the test results", action="store_true" ) - parser.add_option( + parser.add_argument( "-s", "--save_plot", dest="save_plot", help="save test result plots", action="store_true", ) - parser.add_option( + parser.add_argument( "-a", "--archive", dest="archive", help="archive the test results in an pickle file", action="store_true", ) - parser.add_option( + parser.add_argument( "-c", "--capacity_factor", dest="capacity_factor", help="returns the capacity factor", action="store_true", ) - parser.add_option( + parser.add_argument( "-o", "--override_testname", dest="override_testname", help="override the JSON test name", metavar="FILE", ) - parser.add_option( + parser.add_argument( "-r", "--read_results", dest="read_results", help="gather also the results of function invocations", action="store_true", ) - (options, args) = parser.parse_args() + options = parser.parse_args() logger.info("Workload Analyzer started") print("Log file -> logs/WA.log")