|
133 | 133 | #' concurrently, one after the other. If `"sequential"`, they are set up |
134 | 134 | #' sequentially. |
135 | 135 | #' |
| 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 | +#' |
136 | 140 | #' @param action This is an internal argument. |
137 | 141 | #' |
138 | 142 | #' @return `makeNodePSOCK()` returns a `"SOCKnode"` or |
|
377 | 381 | #' @importFrom tools pskill |
378 | 382 | #' @importFrom utils flush.console |
379 | 383 | #' @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) { |
381 | 385 | verbose <- as.logical(verbose) |
382 | 386 | stop_if_not(length(verbose) == 1L, !is.na(verbose)) |
383 | 387 | verbose_prefix <- "[local output] " |
@@ -418,7 +422,8 @@ makeNodePSOCK <- function(worker = getOption2("parallelly.localhost.hostname", " |
418 | 422 | manual = manual, |
419 | 423 | dryrun = dryrun, |
420 | 424 | quiet = quiet, |
421 | | - setup_strategy = setup_strategy |
| 425 | + setup_strategy = setup_strategy, |
| 426 | + calls = calls |
422 | 427 | ) |
423 | 428 |
|
424 | 429 | localhostHostname <- getOption2("parallelly.localhost.hostname", "localhost") |
@@ -850,7 +855,23 @@ makeNodePSOCK <- function(worker = getOption2("parallelly.localhost.hostname", " |
850 | 855 | }) |
851 | 856 | rscript_args_internal <- c(rscript_args_internal, "-e", shQuote(code, type = rscript_sh[1])) |
852 | 857 | } |
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 | + |
854 | 875 | ## .{slave,work}RSOCK() command already specified? |
855 | 876 | if (!any(grepl("parallel:::[.](slave|work)RSOCK[(][)]", rscript_args))) { |
856 | 877 | ## In R (>= 4.1.0), parallel:::.slaveRSOCK() was renamed to .workRSOCK() |
|
0 commit comments