log_start {autometric} | R Documentation |
Start the log thread.
Description
Start a background thread that periodically writes
system usage metrics of the current R process to a log file.
See log_read()
for explanations of the specific metrics.
Usage
log_start(
path,
seconds = 1,
pids = c(local = Sys.getpid()),
error = getOption("autometric_error", TRUE)
)
Arguments
path |
Character string, path to a file to log resource usage.
On Windows, the path must point to a physical file on disk.
On Unix-like systems, Standard output is the most convenient option for high-performance computing scenarios where worker processes already write to log files. Such workers usually already redirect standard output to a physical file, as with a cluster like SLURM, or capture messages with Amazon CloudWatch. Normally, standard output and standard error are discouraged because
of how they interact with the R API and R console. However, the
exported user interface of |
seconds |
Positive number, number of seconds between writes to the
log file. This number should be noticeably large, anywhere between
half a second to several seconds or minutes.
A low number of seconds could burden the operating system
and generate large log files. Because of the way CPU usage measurements
work, the first log entry starts only after after the first interval of
|
pids |
Nonempty vector of non-negative integers
of process IDs to monitor. NOTE: On Mac OS, only the currently running
process can be monitored.
This is due to security restrictions around certain system calls, c.f.
https://os-tres.net/blog/2010/02/17/mac-os-x-and-task-for-pid-mach-call/. # nolint
If the |
error |
|
Details
Only one thread can run at a time. If the thread is already
running, then log_start()
does not start an additional one.
Before creating a new thread, call log_stop()
to terminate
the first one.
Value
NULL
(invisibly). Called for its side effects.
Examples
path <- tempfile()
log_start(seconds = 0.5, path = path)
Sys.sleep(2)
log_stop()
Sys.sleep(2)
log_read(path)
unlink(path)