From bbc17066146cc832cdfdb6d22adf78c71fc5be8c Mon Sep 17 00:00:00 2001 From: Landon Owen Date: Thu, 19 Sep 2024 16:29:47 -0700 Subject: [PATCH] Added ability to specify a caliper configuration json file, remove highwatermark spot configuration as it causes issues with LLNLSpheral tests --- docs/developer/dev/diagnostic_tools.rst | 7 ++++--- src/PYB11/Utilities/TimerMgr.py | 5 +++++ src/SimulationControl/SpheralOptionParser.py | 15 +++++++++++---- src/Utilities/Timer.hh | 8 +++++++- 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/docs/developer/dev/diagnostic_tools.rst b/docs/developer/dev/diagnostic_tools.rst index 921fbee09..d16a2e94c 100644 --- a/docs/developer/dev/diagnostic_tools.rst +++ b/docs/developer/dev/diagnostic_tools.rst @@ -13,7 +13,7 @@ Querying using Caliper Caliper is configured and started through the :kbd:`cali::ConfigManager`. The :kbd:`cali::ConfigManager` is wrapped in a :kbd:`TimerMgr` singleton class, which has a python interface. :kbd:`TimerMgr` is initialized and started in the :kbd:`InitTimers` routine which is called in :kbd:`commandLine()` in ``src/SimulationControl/SpheralOptionParser.py``. -By default, the Caliper configuration is set to ``spot,mem.highwatermark`` and outputs Caliper files (``.cali``). +By default, the Caliper configuration is set to ``spot`` and outputs Caliper files (``.cali``). For the default configuration, the Caliper files are named based on what file is being run, for example: :: @@ -38,9 +38,10 @@ Non-default Caliper configurations can be set at the command line using ``--cali .. note:: The above configuration produces timing results similar to the previous :kbd:`Spheral::Timer` method. This results in a file named ``time.txt`` with cumulative times for the nested regions as well as a count of how many times each region ran. -Additionally, Caliper timers can be turned off using ``--caliperConfig none``. +Similarly, a non-default Caliper configuration can be read in from a JSON file using ``--caliperConfigJSON`` and providing the file name. +Lastly, Caliper timers can be turned off using ``--caliperConfig none``. -There are many different Caliper configurations to view various information. Here are some extra links for those who want to read or experiment with other features in Caliper that can be incorperated into Spheral: +There are many different Caliper configurations to view various information. Here are some extra links for those who want to read or experiment with other features in Caliper that can be incorporated into Spheral: * `Configuration basics `_ * `Builtin Configuration `_ diff --git a/src/PYB11/Utilities/TimerMgr.py b/src/PYB11/Utilities/TimerMgr.py index 4f61a83aa..6b47214cd 100644 --- a/src/PYB11/Utilities/TimerMgr.py +++ b/src/PYB11/Utilities/TimerMgr.py @@ -34,6 +34,11 @@ def add(self, config_str = "std::string"): "Add a Caliper configuration" return "void" + @PYB11static + def load(self, config_json = "std::string"): + "Load a json file containing Caliper configurations" + return "void" + @PYB11static def default_start(self, testname = "std::string"): "Set the spot Caliper configuration and start the manager" diff --git a/src/SimulationControl/SpheralOptionParser.py b/src/SimulationControl/SpheralOptionParser.py index d846a2cbc..7f45e26c0 100644 --- a/src/SimulationControl/SpheralOptionParser.py +++ b/src/SimulationControl/SpheralOptionParser.py @@ -26,12 +26,13 @@ def commandLine(**options): help = "Verbose output -- print all options that were set.") parser.add_argument("--caliperConfig", default="", type=str) parser.add_argument("--caliperFilename", default="", type=str) + parser.add_argument("--caliperConfigJSON", default="", type=str) # Evaluate the command line. args = parser.parse_args() arg_dict = vars(args) if (not TimerMgr.timers_usable()): - if (args.caliperConfig or args.caliperFilename): + if (args.caliperConfig or args.caliperFilename or args.caliperConfigJSON): print("WARNING: Caliper command line inputs provided for "+\ "non-timer install. Reconfigure the install with "+\ "-DENABLE_TIMER=ON to be able to use Caliper timers.") @@ -49,6 +50,8 @@ def commandLine(**options): print(" * caliperConfig = ", args.caliperConfig) if (args.caliperFilename): print(" * caliperFilename = ", args.caliperFilename) + if (args.caliperConfigJSON): + print(" * caliperConfigJSON = ", args.caliperConfigJSON) # Set all the variables. gd = globalFrame().f_globals for key, val in arg_dict.items(): @@ -57,10 +60,14 @@ def commandLine(**options): val = eval(val, gd) gd[key] = val # Initialize timers - InitTimers(args.caliperConfig, args.caliperFilename) + InitTimers(args.caliperConfig, args.caliperFilename, args.caliperConfigJSON) return -def InitTimers(caliper_config, filename): +def InitTimers(caliper_config, filename, caliper_json): + if(caliper_json): + TimerMgr.load(caliper_json) + if(not caliper_config): + raise RuntimeError("SpheralOptionParser: specifying a configuration file without using one of the configurations means no timers are started") off_tests = ["none", "off", "disable", "disabled", "0"] if (caliper_config.lower() in off_tests): return @@ -74,7 +81,7 @@ def InitTimers(caliper_config, filename): else: from datetime import datetime # Append the current day and time to the filename - unique_digits = datetime.now().strftime("_%Y_%m_%d_%H%M%S") + unique_digits = datetime.now().strftime("_%Y_%m_%d_%H%M%S_%f") # Name file based on name of python file being run testname = os.path.splitext(os.path.basename(sys.argv[0]))[0] testname += unique_digits + ".cali" diff --git a/src/Utilities/Timer.hh b/src/Utilities/Timer.hh index 1188ce79b..4ba514b59 100644 --- a/src/Utilities/Timer.hh +++ b/src/Utilities/Timer.hh @@ -65,9 +65,13 @@ public: VERIFY2(test, instance().cali_mgr.error_msg()); instance().caliperConfig += config_str; } + static void load(std::string config_json) { + instance().cali_mgr.load(config_json.c_str()); + VERIFY2(!instance().cali_mgr.error(), instance().cali_mgr.error_msg()); + } static void default_start(std::string testname) { if (!testname.empty()) { - std::string default_config = "spot,mem.highwatermark,output=" + testname; + std::string default_config = "spot,output=" + testname; instance().caliperFilename = testname; add(default_config); start(); @@ -91,6 +95,8 @@ public: static bool timers_usable() { return false; } + static void load(std::string) { + } static void default_start(std::string) { } static void add(std::string) {