From 6cfcbcf3a4dc0105e588238584f83f0e1b390c22 Mon Sep 17 00:00:00 2001 From: DylanKierans Date: Tue, 23 Jul 2024 15:32:22 +0200 Subject: [PATCH] Disabling overwriting of otf2 archivePath by default by adding timestamp-related suffix --- R/RcppExports.R | 5 +++-- R/r_instrument_hl.R | 2 +- man/init_otf2_logger.Rd | 3 +++ src/RcppExports.cpp | 9 +++++---- src/pmpmeas | 2 +- src/rTrace.cpp | 17 ++++++++--------- src/rTrace.h | 2 +- 7 files changed, 22 insertions(+), 18 deletions(-) diff --git a/R/RcppExports.R b/R/RcppExports.R index ea7c788..a9f1724 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -5,11 +5,12 @@ #' @param max_nprocs Maximum number of R processes (ie evtWriters required) #' @param archivePath Path to otf2 archive #' @param archiveName Name of otf2 archive +#' @param overwrite_archivePath If true then use archivePath as prefix for directory to avoid overwriting, the suffix is generated using mkdtemp #' @param collect_metrics Collect HWPC metrics via pmpmeas #' @param flag_print_pids True to print pids of parent and child procs #' @return <0 if error, 0 if R master, else >0 if child -init_otf2_logger <- function(max_nprocs, archivePath, archiveName, collect_metrics, flag_print_pids) { - .Call(`_rTrace_init_otf2_logger`, max_nprocs, archivePath, archiveName, collect_metrics, flag_print_pids) +init_otf2_logger <- function(max_nprocs, archivePath, archiveName, overwrite_archivePath, collect_metrics, flag_print_pids) { + .Call(`_rTrace_init_otf2_logger`, max_nprocs, archivePath, archiveName, overwrite_archivePath, collect_metrics, flag_print_pids) } #' r_pmpmeas_init diff --git a/R/r_instrument_hl.R b/R/r_instrument_hl.R index dfc0fab..bec5de4 100644 --- a/R/r_instrument_hl.R +++ b/R/r_instrument_hl.R @@ -75,7 +75,7 @@ instrumentation_init <- function(flag_user_functions=T, collect_metrics=F, verbo ## Initiate new proc - close R if not Master ret <- init_otf2_logger(parallelly::availableCores(), "rTrace", "rTrace", - collect_metrics=pkg.env$COLLECT_METRICS, + overwrite_archivePath = FALSE, collect_metrics=pkg.env$COLLECT_METRICS, flag_print_pids=F) # Master R proc returns 0 if (ret != 0){ quit(save="no"); } # Unintended fork R proc for otf2 logger diff --git a/man/init_otf2_logger.Rd b/man/init_otf2_logger.Rd index 4ab105d..d7bde0e 100644 --- a/man/init_otf2_logger.Rd +++ b/man/init_otf2_logger.Rd @@ -8,6 +8,7 @@ init_otf2_logger( max_nprocs, archivePath, archiveName, + overwrite_archivePath, collect_metrics, flag_print_pids ) @@ -19,6 +20,8 @@ init_otf2_logger( \item{archiveName}{Name of otf2 archive} +\item{overwrite_archivePath}{If true then use archivePath as prefix for directory to avoid overwriting, the suffix is generated using mkdtemp} + \item{collect_metrics}{Collect HWPC metrics via pmpmeas} \item{flag_print_pids}{True to print pids of parent and child procs} diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index 28ffe53..be2fb81 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -11,17 +11,18 @@ Rcpp::Rostream& Rcpp::Rcerr = Rcpp::Rcpp_cerr_get(); #endif // init_otf2_logger -RcppExport int init_otf2_logger(int max_nprocs, Rcpp::String archivePath, Rcpp::String archiveName, bool collect_metrics, bool flag_print_pids); -RcppExport SEXP _rTrace_init_otf2_logger(SEXP max_nprocsSEXP, SEXP archivePathSEXP, SEXP archiveNameSEXP, SEXP collect_metricsSEXP, SEXP flag_print_pidsSEXP) { +RcppExport int init_otf2_logger(int max_nprocs, Rcpp::String archivePath, Rcpp::String archiveName, bool overwrite_archivePath, bool collect_metrics, bool flag_print_pids); +RcppExport SEXP _rTrace_init_otf2_logger(SEXP max_nprocsSEXP, SEXP archivePathSEXP, SEXP archiveNameSEXP, SEXP overwrite_archivePathSEXP, SEXP collect_metricsSEXP, SEXP flag_print_pidsSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< int >::type max_nprocs(max_nprocsSEXP); Rcpp::traits::input_parameter< Rcpp::String >::type archivePath(archivePathSEXP); Rcpp::traits::input_parameter< Rcpp::String >::type archiveName(archiveNameSEXP); + Rcpp::traits::input_parameter< bool >::type overwrite_archivePath(overwrite_archivePathSEXP); Rcpp::traits::input_parameter< bool >::type collect_metrics(collect_metricsSEXP); Rcpp::traits::input_parameter< bool >::type flag_print_pids(flag_print_pidsSEXP); - rcpp_result_gen = Rcpp::wrap(init_otf2_logger(max_nprocs, archivePath, archiveName, collect_metrics, flag_print_pids)); + rcpp_result_gen = Rcpp::wrap(init_otf2_logger(max_nprocs, archivePath, archiveName, overwrite_archivePath, collect_metrics, flag_print_pids)); return rcpp_result_gen; END_RCPP } @@ -300,7 +301,7 @@ END_RCPP } static const R_CallMethodDef CallEntries[] = { - {"_rTrace_init_otf2_logger", (DL_FUNC) &_rTrace_init_otf2_logger, 5}, + {"_rTrace_init_otf2_logger", (DL_FUNC) &_rTrace_init_otf2_logger, 6}, {"_rTrace_r_pmpmeas_init", (DL_FUNC) &_rTrace_r_pmpmeas_init, 0}, {"_rTrace_r_pmpmeas_finish", (DL_FUNC) &_rTrace_r_pmpmeas_finish, 0}, {"_rTrace_r_pmpmeas_start", (DL_FUNC) &_rTrace_r_pmpmeas_start, 0}, diff --git a/src/pmpmeas b/src/pmpmeas index c8fcc05..e2c9e08 160000 --- a/src/pmpmeas +++ b/src/pmpmeas @@ -1 +1 @@ -Subproject commit c8fcc05544ae9b2e3710f325a95489beb060df43 +Subproject commit e2c9e08bc3488319dd51552ecacdd233bf68c956 diff --git a/src/rTrace.cpp b/src/rTrace.cpp index 648b9c7..41e0e9c 100644 --- a/src/rTrace.cpp +++ b/src/rTrace.cpp @@ -9,14 +9,8 @@ // Server refers to otf2 logger proc {server}n{clients}=0 // @note WARNING - Was receiving consistent noise on port 5558 // @todo Look at timing offsets per proc -// @todo Signal handling for both procs -// @todo get epochs from Master proc // @todo Multipart message implimentation for repeated buffer usage -// @todo Move pmpmeas to sub-directory and update buildchain // -// @note Use pmpmeas_init to parse environment variables -// @note New object Meas for each meas_type, contains multiple metrics via _cnt -// Names and values stored in papi/perf interface (include/papiinf.hh) #include #include @@ -42,7 +36,6 @@ using namespace Rcpp; using namespace PMPMEAS; - /////////////////////////////// // Global vars /////////////////////////////// @@ -88,7 +81,6 @@ sighandler_t default_sigint_handler; // Function definitions /////////////////////////////// -// TODO: Ensure this doesn't cause overflow of wtime // get_time // @description Returns wall-clock time in units of milliseconds (1E-6s) // @return OTF2_Timestamp - Wallclock time @@ -191,12 +183,13 @@ void sigint_handler(int sig){ //' @param max_nprocs Maximum number of R processes (ie evtWriters required) //' @param archivePath Path to otf2 archive //' @param archiveName Name of otf2 archive +//' @param overwrite_archivePath If true then use archivePath as prefix for directory to avoid overwriting, the suffix is generated using current time in seconds //' @param collect_metrics Collect HWPC metrics via pmpmeas //' @param flag_print_pids True to print pids of parent and child procs //' @return <0 if error, 0 if R master, else >0 if child // [[Rcpp::export]] RcppExport int init_otf2_logger(int max_nprocs, Rcpp::String archivePath, - Rcpp::String archiveName, bool collect_metrics, + Rcpp::String archiveName, bool overwrite_archivePath, bool collect_metrics, bool flag_print_pids) { // TODO: Verify this acts as intended to save child proc @@ -212,6 +205,12 @@ RcppExport int init_otf2_logger(int max_nprocs, Rcpp::String archivePath, } COLLECT_METRICS = collect_metrics; + // Postpend start time to archivePath name to avoid overwrite + char new_archivePath[120]; + snprintf(new_archivePath, 120, "%s_%lu", archivePath.get_cstring(), get_time()); + if (!overwrite_archivePath) + archivePath = new_archivePath; + child_pid = fork(); if (child_pid == (pid_t) -1 ){ // ERROR report_and_exit("Forking logger process", NULL); diff --git a/src/rTrace.h b/src/rTrace.h index d234eca..e6a9702 100644 --- a/src/rTrace.h +++ b/src/rTrace.h @@ -62,7 +62,7 @@ char log_filename[]="log.log"; ///* Name of log file on server proc /////////////////////////////// // R client functions (master/slaves) RcppExport int init_otf2_logger(int max_nprocs, Rcpp::String archivePath = "rTrace", - Rcpp::String archiveName = "rTrace", bool collect_metrics=false, + Rcpp::String archiveName = "rTrace", bool overwrite_archivePath=false, bool collect_metrics=false, bool flag_print_pids=false); RcppExport SEXP finalize_GlobalDefWriter_client(); RcppExport int define_otf2_regionRef_client(Rcpp::String, int);