Skip to content

Commit

Permalink
Cleanup legacy event logger for R
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanKierans committed Mar 4, 2024
1 parent 09970b2 commit ba053c4
Show file tree
Hide file tree
Showing 19 changed files with 30 additions and 524 deletions.
5 changes: 0 additions & 5 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Generated by roxygen2: do not edit by hand

export(create_eventlog)
export(get_function_exception_list)
export(get_function_index)
export(get_function_list)
Expand All @@ -17,8 +16,6 @@ export(instrumentation_finalize)
export(instrumentation_init)
export(is_instrumentation_enabled)
export(makeCluster_test)
export(print_dataframe)
export(print_eventlog)
export(print_function_from_index)
export(rTrace_evtWriter_Write)
export(rTrace_finalize_Archive)
Expand All @@ -31,8 +28,6 @@ export(rTrace_globalDefWriter_WriteSystemTreeNode)
export(rTrace_init_Archive)
export(rTrace_init_EvtWriter)
export(rTrace_init_GlobalDefWriter)
export(save_dataframe)
export(save_eventlog)
export(skip_function)
export(test_instrumentation)
export(total_num_functions)
Expand Down
2 changes: 0 additions & 2 deletions R/rTrace.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ library("Rcpp")
#' \item{MAX_FUNCTION_DEPTH}{}
#' \item{FUNCTION_DEPTH}{}
#' \item{UNLOCK_ENVS}{}
#' \item{PROFILE_EVENTLOG}{}
#' \item{PROFILE_EVENTLOG_NROWS}{}
#' \item{PROFILE_INSTRUMENTATION_DF}{}
#' \item{PRINT_INSTRUMENTS}{}
#' \item{PRINT_SKIPS}{}
Expand Down
178 changes: 0 additions & 178 deletions R/r_event_instrumentation_loggers.R

This file was deleted.

8 changes: 1 addition & 7 deletions R/r_instrument_hl.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,11 @@ is_instrumentation_enabled <- function() {

#' instrumentation_init
#' @description Create otf2 objs for instrumentation, and initiate global vars
#' @param r_profiling Boolean - TRUE to enable R-based eventlogger and runtime info
#' @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
#' @export
instrumentation_init <- function(r_profiling=T, flag_user_functions=T, verbose_wrapping=F)
instrumentation_init <- function(flag_user_functions=T, verbose_wrapping=F)
{
if (r_profiling) {
pkg.env$PROFILE_INSTRUMENTATION_DF <- create_dataframe(flag_user_functions=flag_user_functions)
pkg.env$PROFILE_EVENTLOG <- create_eventlog()
}

# @name INSTRUMENTATION_INIT
# @description Checked when instrumenting functions to ensure init() has been called
pkg.env$INSTRUMENTATION_INIT <- TRUE
Expand Down
122 changes: 21 additions & 101 deletions R/r_instrument_ll.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@ get_wrapper_expression <- function() {
}
}
)

## Version 9 - only otf2, no max depth
#if (VERSION_9) {
#.wrapper_expression <- eval( substitute(
#expression(
#{
# if (pkg.env$INSTRUMENTATION_ENABLED) {
# ## OTF2 Event
# evtWriter_Write(X_regionRef_X,T)
# on.exit(evtWriter_Write(X_regionRef_X,F), add=TRUE)
# }
#}
#)
# , list(X_regionRef_X=regionRef)
#) )
#}

wrapper_expression
}

Expand All @@ -46,104 +63,7 @@ get_wrapper_expression <- function() {
#' @param env_is_locked Boolean - TRUE if function name-/package- space is locked
#' @export
insert_instrumentation <- function(func, func_name, func_index, regionRef, package_name, flag_user_function=FALSE, env_is_locked=TRUE) {

VERSION_7 <- FALSE
VERSION_8 <- TRUE
VERSION_9 <- FALSE

## Version 7 - R and otf2
if (VERSION_7) {
.wrapper_expression <- eval( substitute(
expression(
{
if (pkg.env$PRINT_FUNC_INDEXES){
print(paste0("func_index: ", X_func_index_X))
}

if (pkg.env$INSTRUMENTATION_ENABLED) {
NULL
## DEBUGGING
#print("Hello World!")
#on.exit(print("Finish!"),add=TRUE)

## Depth counter error check
if (pkg.env$FUNCTION_DEPTH < 0 )
{
print("Warning: Disabling instrumentation - Function_depth < 0.")
instrumentation_disable()
}

## Append to depth counter
pkg.env$FUNCTION_DEPTH <- pkg.env$FUNCTION_DEPTH + 1
on.exit( pkg.env$FUNCTION_DEPTH <- pkg.env$FUNCTION_DEPTH - 1, add=TRUE )

if (pkg.env$FUNCTION_DEPTH <= pkg.env$MAX_FUNCTION_DEPTH )
{
## Function count
on.exit( pkg.env$PROFILE_INSTRUMENTATION_DF[["function_count"]][X_func_index_X] <- pkg.env$PROFILE_INSTRUMENTATION_DF[["function_count"]][X_func_index_X] + 1, add=TRUE )

## Function timing
t0 <- rTrace_time()
on.exit( t0 <- rTrace_time() - t0, add=TRUE)
on.exit( pkg.env$PROFILE_INSTRUMENTATION_DF[["function_time"]][X_func_index_X] <- pkg.env$PROFILE_INSTRUMENTATION_DF[["function_time"]][X_func_index_X] + t0, add=TRUE )

## Eventlog
event_create(as.integer(X_func_index_X), TRUE, rTrace_time())
on.exit( event_create(as.integer(X_func_index_X), FALSE, rTrace_time()), add=TRUE )

## OTF2 Event
evtWriter_Write(X_regionRef_X,T)
on.exit(evtWriter_Write(X_regionRef_X,F), add=TRUE)
}

}
}
)
, list(X_func_index_X=func_index, X_regionRef_X=regionRef)
) )
}

if (VERSION_8) {
## Version 8 - only otf2
.wrapper_expression <- eval( substitute(
expression(
{
if (pkg.env$INSTRUMENTATION_ENABLED) {
NULL
## Append to depth counter
pkg.env$FUNCTION_DEPTH <- pkg.env$FUNCTION_DEPTH + 1
on.exit( pkg.env$FUNCTION_DEPTH <- pkg.env$FUNCTION_DEPTH - 1, add=TRUE )

if (pkg.env$FUNCTION_DEPTH <= pkg.env$MAX_FUNCTION_DEPTH )
{
## OTF2 Event
evtWriter_Write(X_regionRef_X,T)
on.exit(evtWriter_Write(X_regionRef_X,F), add=TRUE)
}

}
}
)
, list(X_regionRef_X=regionRef)
) )
}

## Version 9 - only otf2, no max depth
if (VERSION_9) {
.wrapper_expression <- eval( substitute(
expression(
{
if (pkg.env$INSTRUMENTATION_ENABLED) {
## OTF2 Event
evtWriter_Write(X_regionRef_X,T)
on.exit(evtWriter_Write(X_regionRef_X,F), add=TRUE)
}
}
)
, list(X_regionRef_X=regionRef)
) )
}

.wrapper_expression= eval(substitute(get_wrapper_expression(),
list(X_regionRef_X=regionRef)))

Expand Down Expand Up @@ -409,14 +329,15 @@ try_insert_instrumentation <- function(func_info, func_ptrs, env_is_locked,
flag_user_function=flag_user_function)
}

# @TODO : zmq this
#' create_otf2_event
#' @description Creates stringRef and regionRef for func_name
#' @param func_name String - Name of function
#' @return regionRef Int - Index of stringRef for function
create_otf2_event <- function(func_name) {
stringRef <- rTrace_globalDefWriter_WriteString(func_name)
regionRef <- rTrace_globalDefWriter_WriteRegion(stringRef)
regionRef
stringRef <- rTrace_globalDefWriter_WriteString(func_name)
regionRef <- rTrace_globalDefWriter_WriteRegion(stringRef)
regionRef
}


Expand Down Expand Up @@ -666,4 +587,3 @@ test_instrumentation <- function(func_ptr, func_name, expr, flag_debug=F) {
}
}


Loading

0 comments on commit ba053c4

Please sign in to comment.