Skip to content

Commit

Permalink
Adding dependencies to pmpmeas, not yet imported. See next commit
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanKierans committed Jul 5, 2024
1 parent 4069a7b commit f7e617e
Show file tree
Hide file tree
Showing 6 changed files with 265 additions and 35 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
URL: https://github.com/DylanKierans/rTrace
BugReports: https://github.com/DylanKierans/rTrace/issues
SystemRequirements: otf-trace, libotf-trace-dev, zeromq
SystemRequirements: otf-trace, libotf-trace-dev, zeromq, papi, perf
36 changes: 27 additions & 9 deletions R/rTrace.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,45 +45,63 @@ library("Rcpp")
#' \item{PRINT_INSTRUMENTS}{}
#' \item{PRINT_SKIPS}{}
#' \item{PRINT_FUNC_INDEXES}{}
#' \item{COLLECT_METRICS}{}
#' \item{RTRACE_VARS}{}
#' }
#'
pkg.env <- new.env(parent = emptyenv())

### SECTION - Init section for instrumentation ###
# @name INSTRUMENTATION_INIT
# @description Checked when instrumenting functions to ensure init() has been called
# @description Boolean - Checked when instrumenting functions to ensure init() has been called
pkg.env$INSTRUMENTATION_INIT <- FALSE

# @name INSTRUMENTATION_ENABLED
# @description Current status of instrumentation
# @description Boolean - Current status of instrumentation
pkg.env$INSTRUMENTATION_ENABLED <- FALSE

# @name INSTRUMENTATION_STATUS_SAVED
# @description Saved status of instrumentation
# @description Boolean - Saved status of instrumentation
pkg.env$INSTRUMENTATION_STATUS_SAVED <- FALSE

### SECTION - Instrument Flags ###
# @name MAX_FUNCTION_DEPTH
# @description Max depth of functions to creat instrumententation events for
# @description int - Max depth of functions to creat instrumententation events for
pkg.env$MAX_FUNCTION_DEPTH <- 10

# @name FUNCTION_DEPTH
# @description Current instrumentation depth
# @description int - Current instrumentation depth
pkg.env$FUNCTION_DEPTH <- 0

# @name UNLOCK_ENVS
# @description Keep package envs unlocked when instrumenting functions
# @description Boolean - Keep package envs unlocked when instrumenting functions
pkg.env$UNLOCK_ENVS <- TRUE # Not sure if this is safe to set TRUE, but should be quicker!

### SECTION - Output Flags ###
# @name PRINT_INSTRUMENTS
# @description Print which functions are being instrumented
# @description Boolean - Print which functions are being instrumented
pkg.env$PRINT_INSTRUMENTS <- FALSE

# @name PRINT_SKIPS
# @description Print which functions are being skipped due to exception
# @description Boolean - Print which functions are being skipped due to exception
pkg.env$PRINT_SKIPS <- FALSE

# @name PRINT_FUNC_INDEXES
# @description Print function indexes when called (only intended for verbose debugging)
# @description Boolean - Print function indexes when called (only intended for verbose debugging)
pkg.env$PRINT_FUNC_INDEXES <- FALSE


# @name COLLECT_METRICS
# @description Boolean - Enable collection of Hardware Performance Metrics (HWPC)
pkg.env$COLLECT_METRICS <- FALSE


# @name RTRACE_VARS
# @description List of all global rTrace variables
pkg.env$RTRACE_VARS <- c( "INSTRUMENTATION_INIT", "INSTRUMENTATION_ENABLED",
"INSTRUMENTATION_STATUS_SAVED", "MAX_FUNCTION_DEPTH",
"FUNCTION_DEPTH", "UNLOCK_ENVS", "PRINT_INSTRUMENTS",
"PRINT_SKIPS", "PRINT_FUNC_INDEXES",
"COLLECT_METRICS"
)

11 changes: 3 additions & 8 deletions R/r_fork_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -397,17 +397,12 @@ master_init_slave <- function(cl) {
parallel::clusterEvalQ(cl, eval(parse(text = pkg_cmd)))

# Export rTrace variables
vars <- c( "INSTRUMENTATION_INIT", "INSTRUMENTATION_ENABLED",
"INSTRUMENTATION_STATUS_SAVED", "MAX_FUNCTION_DEPTH",
"FUNCTION_DEPTH", "UNLOCK_ENVS", "PRINT_INSTRUMENTS",
"PRINT_SKIPS", "PRINT_FUNC_INDEXES"
)
parallel::clusterExport(cl, c("vars"), envir=environment())
parallel::clusterExport(cl, vars, envir=pkg.env)
parallel::clusterExport(cl, c("RTRACE_VARS"), envir=environment())
parallel::clusterExport(cl, RTRACE_VARS, envir=pkg.env)
parallel::clusterEvalQ(cl, {
FUNCTION_DEPTH <- 0 # Reset function depth
unlock_envs("rTrace")
for(n in vars) { assign(n, get(n, .GlobalEnv), pkg.env) }
for(n in RTRACE_VARS) { assign(n, get(n, .GlobalEnv), pkg.env) }
lock_envs("rTrace")
})

Expand Down
15 changes: 12 additions & 3 deletions R/r_instrument_hl.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,27 @@ is_instrumentation_enabled <- function() {
}


## YOU ARE HERE
#' instrumentation_init
#' @description Create otf2 objs for instrumentation, and initiate global vars
#' @param flag_user_functions Boolean - TRUE to include user functions in dataframe
#' @param verbose_wrapping Boolean - Print info about skipping or instrumenting each function. Produces large amount of info to stdout
#' @param collect_metrics Boolean - Enable papi/perf metric collection with instrumentation
#' @param verbose_wrapping Boolean - Print info about skipping or instrumenting each function. Produces large amount of info to stdout. Intended for developers
#' @export
instrumentation_init <- function(flag_user_functions=T, verbose_wrapping=F)
instrumentation_init <- function(flag_user_functions=T, collect_metrics=F, verbose_wrapping=F)
{
## Update package vars
pkg.env$PRINT_INSTRUMENTS <- verbose_wrapping
pkg.env$PRINT_SKIPS <- verbose_wrapping
pkg.env$INSTRUMENTATION_INIT <- TRUE

### YOU ARE HERE
## Interface to pmpmeas
if (collect_metrics){
pkg.env$COLLECT_METRICS <- TRUE
pmpmeas_init()
}

## Initiate new proc - close R if not Master
ret <- init_otf2_logger(parallelly::availableCores()) # Master R proc returns 0
if (ret != 0){ quit(save="no"); } # Unintended fork R proc for otf2 logger
Expand Down Expand Up @@ -147,4 +156,4 @@ instrumentation_wrapper <- function(func, ...)

instrumentation_finalize()
ret
}
}
8 changes: 6 additions & 2 deletions src/Makevars
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@ OTF2_PKG_LIBS=-L${OTF2_ROOT}/lib -lotf2
ZEROMQ_PKG_CPPFLAGS=-I${ZEROMQ_ROOT}/include
ZEROMQ_PKG_LIBS=-L${ZEROMQ_ROOT}/lib -lzmq

PKG_CPPFLAGS=-I. ${OTF2_PKG_CPPFLAGS} ${ZEROMQ_PKG_CPPFLAGS}
PKG_LIBS=-L. ${OTF2_PKG_LIBS} ${ZEROMQ_PKG_LIBS}
# pmpmeas - papi
PMPMEAS_PKG_CPPFLAGS=`pkg-config --cflags papi`
PMPMEAS_PKG_LIBS=`pkg-config --libs papi`

PKG_CPPFLAGS=-I. ${OTF2_PKG_CPPFLAGS} ${ZEROMQ_PKG_CPPFLAGS} ${PMPMEAS_PKG_CPPFLAGS}
PKG_LIBS=-L. ${OTF2_PKG_LIBS} ${ZEROMQ_PKG_LIBS} ${PMPMMEAS_PKG_LIBS}
Loading

0 comments on commit f7e617e

Please sign in to comment.