Skip to content

Commit ff25799

Browse files
Add argument 'calls' to makeNodePSOCK(), controllable via option 'parallelly.makeNodePSOCK.calls', which if TRUE, relayes the call stack in the system calls
1 parent bc76074 commit ff25799

File tree

5 files changed

+57
-7
lines changed

5 files changed

+57
-7
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: parallelly
2-
Version: 1.44.0-9022
2+
Version: 1.44.0-9023
33
Title: Enhancing the 'parallel' Package
44
Imports:
55
parallel,

R/makeNodePSOCK.R

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@
133133
#' concurrently, one after the other. If `"sequential"`, they are set up
134134
#' sequentially.
135135
#'
136+
#' @param calls If TRUE, the call stack is recorded and revealed in the
137+
#' system call launching the cluster node. This can be useful when trying
138+
#' to identify which package and function created a particular cluster node.
139+
#'
136140
#' @param action This is an internal argument.
137141
#'
138142
#' @return `makeNodePSOCK()` returns a `"SOCKnode"` or
@@ -377,7 +381,7 @@
377381
#' @importFrom tools pskill
378382
#' @importFrom utils flush.console
379383
#' @export
380-
makeNodePSOCK <- function(worker = getOption2("parallelly.localhost.hostname", "localhost"), master = NULL, port, connectTimeout = getOption2("parallelly.makeNodePSOCK.connectTimeout", 2 * 60), timeout = getOption2("parallelly.makeNodePSOCK.timeout", 30 * 24 * 60 * 60), rscript = NULL, homogeneous = NULL, rscript_args = NULL, rscript_envs = NULL, rscript_libs = NULL, rscript_startup = NULL, rscript_sh = c("auto", "cmd", "sh", "none"), default_packages = c("datasets", "utils", "grDevices", "graphics", "stats", if (methods) "methods"), methods = TRUE, socketOptions = getOption2("parallelly.makeNodePSOCK.socketOptions", "no-delay"), useXDR = getOption2("parallelly.makeNodePSOCK.useXDR", FALSE), outfile = "/dev/null", renice = NA_integer_, rshcmd = getOption2("parallelly.makeNodePSOCK.rshcmd", NULL), user = NULL, revtunnel = NA, rshlogfile = NULL, rshopts = getOption2("parallelly.makeNodePSOCK.rshopts", NULL), rank = 1L, manual = FALSE, dryrun = FALSE, quiet = FALSE, setup_strategy = getOption2("parallelly.makeNodePSOCK.setup_strategy", "parallel"), action = c("launch", "options"), verbose = FALSE) {
384+
makeNodePSOCK <- function(worker = getOption2("parallelly.localhost.hostname", "localhost"), master = NULL, port, connectTimeout = getOption2("parallelly.makeNodePSOCK.connectTimeout", 2 * 60), timeout = getOption2("parallelly.makeNodePSOCK.timeout", 30 * 24 * 60 * 60), rscript = NULL, homogeneous = NULL, rscript_args = NULL, rscript_envs = NULL, rscript_libs = NULL, rscript_startup = NULL, rscript_sh = c("auto", "cmd", "sh", "none"), default_packages = c("datasets", "utils", "grDevices", "graphics", "stats", if (methods) "methods"), methods = TRUE, socketOptions = getOption2("parallelly.makeNodePSOCK.socketOptions", "no-delay"), useXDR = getOption2("parallelly.makeNodePSOCK.useXDR", FALSE), outfile = "/dev/null", renice = NA_integer_, rshcmd = getOption2("parallelly.makeNodePSOCK.rshcmd", NULL), user = NULL, revtunnel = NA, rshlogfile = NULL, rshopts = getOption2("parallelly.makeNodePSOCK.rshopts", NULL), rank = 1L, manual = FALSE, dryrun = FALSE, quiet = FALSE, setup_strategy = getOption2("parallelly.makeNodePSOCK.setup_strategy", "parallel"), calls = getOption2("parallelly.makeNodePSOCK.calls", FALSE), action = c("launch", "options"), verbose = FALSE) {
381385
verbose <- as.logical(verbose)
382386
stop_if_not(length(verbose) == 1L, !is.na(verbose))
383387
verbose_prefix <- "[local output] "
@@ -418,7 +422,8 @@ makeNodePSOCK <- function(worker = getOption2("parallelly.localhost.hostname", "
418422
manual = manual,
419423
dryrun = dryrun,
420424
quiet = quiet,
421-
setup_strategy = setup_strategy
425+
setup_strategy = setup_strategy,
426+
calls = calls
422427
)
423428

424429
localhostHostname <- getOption2("parallelly.localhost.hostname", "localhost")
@@ -850,7 +855,23 @@ makeNodePSOCK <- function(worker = getOption2("parallelly.localhost.hostname", "
850855
})
851856
rscript_args_internal <- c(rscript_args_internal, "-e", shQuote(code, type = rscript_sh[1]))
852857
}
853-
858+
859+
## Reveal sys.calls() in system call
860+
if (calls) {
861+
calls <- sys.calls()
862+
## Drop this function
863+
calls <- calls[-length(calls)]
864+
## Drop any arguments
865+
calls <- lapply(calls, FUN = function(call) as.character(call)[1])
866+
calls <- unlist(calls, use.names = FALSE)
867+
calls <- paste(calls, collapse = "->")
868+
calls <- gsub("[[:space:]]+", "", calls)
869+
calls <- sprintf("calls:%s", calls)
870+
calls <- shQuote(calls)
871+
calls <- sprintf("invisible(%s)", calls)
872+
rscript_args_internal <- c(rscript_args_internal, "-e", shQuote(calls))
873+
}
874+
854875
## .{slave,work}RSOCK() command already specified?
855876
if (!any(grepl("parallel:::[.](slave|work)RSOCK[(][)]", rscript_args))) {
856877
## In R (>= 4.1.0), parallel:::.slaveRSOCK() was renamed to .workRSOCK()

R/options.R

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,20 @@
8484
#' \item{`parallelly.makeNodePSOCK.tries.delay`:}{(numeric) The number of seconds to wait before trying to launch a cluster node that failed to launch previously. Only used when setting up cluster nodes using the sequential strategy.}
8585
#' }
8686
#'
87-
#'
8887
#' @section Options for debugging:
8988
#'
9089
#' \describe{
91-
#' \item{`parallelly.debug`:}{(logical) If `TRUE`, extensive debug messages are generated. (Default: `FALSE`)}
90+
#' \item{`parallelly.debug`:}{(logical)
91+
#' If `TRUE`, extensive debug messages are generated.
92+
#' (Default: `FALSE`)
93+
#' }
94+
#'
95+
#' \item{`parallelly.makeNodePSOCK.calls`:}{(logical)
96+
#' If TRUE, then the call stack that launched the cluster node is revealed
97+
#' as a string part of the system call such that it can be viewed using
98+
#' tools such as `ps`.
99+
#' (Default: `FALSE`)
100+
#' }
92101
#' }
93102
#'
94103
#'
@@ -179,6 +188,7 @@
179188
#' parallelly.makeNodePSOCK.rshopts
180189
#' parallelly.makeNodePSOCK.tries
181190
#' parallelly.makeNodePSOCK.tries.delay
191+
#' parallelly.makeNodePSOCK.calls
182192
#' R_PARALLELLY_MAKENODEPSOCK_SETUP_STRATEGY
183193
#' R_PARALLELLY_MAKENODEPSOCK_VALIDATE
184194
#' R_PARALLELLY_MAKENODEPSOCK_CONNECTTIMEOUT
@@ -189,6 +199,7 @@
189199
#' R_PARALLELLY_MAKENODEPSOCK_RSHOPTS
190200
#' R_PARALLELLY_MAKENODEPSOCK_TRIES
191201
#' R_PARALLELLY_MAKENODEPSOCK_TRIES_DELAY
202+
#' R_PARALLELLY_MAKENODEPSOCK_CALLS
192203
#'
193204
## Internal options and environment variables _not_ documented here:
194205
## parallelly.localhost.hostname
@@ -350,4 +361,5 @@ update_package_options <- function(debug = FALSE) {
350361
update_package_option("makeNodePSOCK.autoKill", mode = "logical", debug = debug)
351362
update_package_option("makeNodePSOCK.master.localhost.hostname", mode = "character", debug = debug)
352363
update_package_option("makeNodePSOCK.port.increment", mode = "logical", debug = debug)
364+
update_package_option("makeNodePSOCK.calls", mode = "logical", debug = debug)
353365
}

man/makeClusterPSOCK.Rd

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/zzz-parallelly.options.Rd

Lines changed: 13 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)