diff --git a/pyphare/pyphare/simulator/simulator.py b/pyphare/pyphare/simulator/simulator.py index 712c703ef..e39f33050 100644 --- a/pyphare/pyphare/simulator/simulator.py +++ b/pyphare/pyphare/simulator/simulator.py @@ -2,6 +2,7 @@ # # +import os import datetime import atexit import time as timem @@ -11,6 +12,7 @@ life_cycles = {} +PHARE_SIM_MON = os.getenv("PHARE_SIM_MON", "False").lower() in ("true", "1", "t") @atexit.register @@ -171,12 +173,15 @@ def times(self): self.timeStep(), ) - def run(self, plot_times=False, monitoring=False): + def run(self, plot_times=False, monitoring=None): """monitoring requires phlop""" from pyphare.cpp import cpp_lib self._check_init() + if monitoring is None: # check env + monitoring = PHARE_SIM_MON + if self.simulation.dry_run: return self if monitoring: diff --git a/src/phare/phare.hpp b/src/phare/phare.hpp index d6519253f..666f3de8e 100644 --- a/src/phare/phare.hpp +++ b/src/phare/phare.hpp @@ -43,7 +43,7 @@ class SamraiLifeCycle PHARE_WITH_PHLOP( // if (auto e = core::get_env("PHARE_SCOPE_TIMING", "false"); e == "1" || e == "true") phlop::ScopeTimerMan::INSTANCE() - .file_name(".phare_times." + std::to_string(core::mpi::rank()) + ".txt") + .file_name(".phare/timings/rank." + std::to_string(core::mpi::rank()) + ".txt") .init(); // ) } diff --git a/tests/functional/harris/harris_2d_lb.py b/tests/functional/harris/harris_2d_lb.py index 71ba63646..1153b6e8b 100644 --- a/tests/functional/harris/harris_2d_lb.py +++ b/tests/functional/harris/harris_2d_lb.py @@ -15,6 +15,7 @@ mpl.use("Agg") +SCOPE_TIMING = os.getenv("PHARE_SCOPE_TIMING", "True").lower() in ("true", "1", "t") LOAD_BALANCE = os.getenv("LOAD_BALANCE", "True").lower() in ("true", "1", "t") cpp = cpp_lib() @@ -200,7 +201,8 @@ def test_run(self): Simulator(config()).run().reset() if cpp.mpi_rank() == 0: plot(diag_dir) - m_plotting.plot_run_timer_data(diag_dir, cpp.mpi_rank()) + if SCOPE_TIMING: + m_plotting.plot_run_timer_data(diag_dir, cpp.mpi_rank()) cpp.mpi_barrier() return self diff --git a/tools/python3/phloping.py b/tools/python3/phloping.py index 0b616677b..b795be173 100644 --- a/tools/python3/phloping.py +++ b/tools/python3/phloping.py @@ -147,3 +147,26 @@ def normalised_times_for_L(self, ilvl): def file_parser(run, rank, times_filepath): supe = phfile_parser(times_filepath) return ScopeTimerFile(supe.id_keys, supe.roots, run, str(rank)) + + +def write_root_as_csv(scope_timer_file, outfile, headers=None, regex=None): + from contextlib import redirect_stdout + + with open(outfile, "w") as f: + with redirect_stdout(f): + print_root_as_csv(scope_timer_file, headers, regex) + + +def print_root_as_csv(scope_timer_file, headers=None, regex=None, n_parts): + stf = scope_timer_file # alias + stf = file_parser(stf) if isinstance(stf, str) else stf + + if headers: + print(",".join(headers)) + for root in stf.roots: + s = stf(root.k) + if regex and regex not in s: + continue + bits = s.split(",") + dim = int(bits[1]) + print(f"{s}{root.t},{root.t/n_parts}")