Read a log file into R.

log_read(
  path,
  units_cpu = c("percentage", "fraction"),
  units_memory = c("megabytes", "bytes", "kilobytes", "gigabytes"),
  units_time = c("seconds", "minutes", "hours", "days"),
  hidden = FALSE
)

Arguments

path

Character vector of paths to files and/or directories of logs to read.

units_cpu

Character string with the units of the cpu field. Defaults to "percentage" and must be in c("percentage", "fraction").

units_memory

Character string with the units of the memory field. Defaults to "megabytes" and must be in c("megabytes", "bytes", "kilobytes", "gigabytes").

units_time

Character string, units of the time field. Defaults to "seconds" and must be in c("seconds", "minutes", "hours", "days").

hidden

TRUE to include hidden files in the files and directories listed in path, FALSE to omit.

Value

A data frame of metrics from the log with one row per log entry and columns with metadata and resource usage metrics. log_read() automatically converts the data into the units chosen with arguments units_time, units_cpu, and units_memory. The returned data frame has the following columns:

  • version: Version of the package used to write the log entry.

  • pid: Process ID monitored.

  • status: A status code for the log entry. Status 0 means logging succeeded. A status code not equal to 0 indicates something went wrong and the metrics should not be trusted.

  • time: numeric time stamp at which the entry was logged. log_read() automatically recenters this column so that time 0 indicates the first logged entry. Use the units_time argument to customize the units of this field.

  • core: CPU load of the process scaled relative to a single CPU core. Measures the amount of time the process spends running during a given interval of elapsed time.

    On Mac OS, the package uses native system calls to get CPU core usage. On Linux and Windows, the package calculates it manually using. user + kernel clock cycles that ran during a sampling interval. It measures the clock cycles that the process executed during the interval, converts the clock cycles into seconds, then divides the result by the elapsed time of the interval. The length of the sampling interval is the seconds argument supplied to log_start(), or length of time between calls to log_print(). The first core measurement is 0 to reflect that a full sampling interval has not elapsed yet.

    core can be read in as a percentage or fraction, depending on the units_cpu argument.

  • cpu: core divided by the number of logical CPU cores. This metric measures the load on the machine as a whole, not just the CPU core it runs on. Use the units_cpu argument to customize the units of this field.

  • rss: resident set size, the total amount of memory used by the process at the time of logging. This include the memory unique to the process (unique set size USS) and shared memory. Use the units_memory argument to customize the units of this field.

  • virtual: total virtual memory available to the process. The process does not necessarily use all this memory, but it can request more virtual memory throughout its life cycle. Use the units_memory argument to customize the units of this field.

Details

log_read() is capable of reading a log file where both autometric and other processes have printed. Whenever autometric writes to a log, it bounds the beginning and end of the text with the keyword "__AUTOMETRIC__". that way, log_read() knows to only read and process the correct lines of the file.

In addition, it automatically converts the log data into the units units_time, units_cpu, and units_memory arguments.

Examples

  path <- tempfile()
  log_start(seconds = 0.5, path = path)
  Sys.sleep(2)
  log_stop()
  Sys.sleep(2)
  log_read(path)
#>      version       phase  pid  name status      time core cpu resident virtual
#> 1 0.1.2.9000 __DEFAULT__ 5832 local      0 0.0000000    0   0 154.4397 876.843
#> 2 0.1.2.9000 __DEFAULT__ 5832 local      0 0.5009999    0   0 154.4397 876.843
#> 3 0.1.2.9000 __DEFAULT__ 5832 local      0 1.0009999    0   0 154.4397 876.843
#> 4 0.1.2.9000 __DEFAULT__ 5832 local      0 1.5009999    0   0 154.4397 876.843
  unlink(path)