Skip to content

Commit

Permalink
Added ability to specify a caliper configuration json file, remove hi…
Browse files Browse the repository at this point in the history
…ghwatermark spot configuration as it causes issues with LLNLSpheral tests
  • Loading branch information
ldowen committed Sep 19, 2024
1 parent 3279a71 commit bbc1706
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
7 changes: 4 additions & 3 deletions docs/developer/dev/diagnostic_tools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:
::

Expand All @@ -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 <https://software.llnl.gov/Caliper/CaliperBasics.html#more-on-configurations>`_
* `Builtin Configuration <https://software.llnl.gov/Caliper/BuiltinConfigurations.html>`_
Expand Down
5 changes: 5 additions & 0 deletions src/PYB11/Utilities/TimerMgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
15 changes: 11 additions & 4 deletions src/SimulationControl/SpheralOptionParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand All @@ -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():
Expand All @@ -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
Expand All @@ -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"
Expand Down
8 changes: 7 additions & 1 deletion src/Utilities/Timer.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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) {
Expand Down

0 comments on commit bbc1706

Please sign in to comment.