r - R 中的内存分析 - 总结工具

标签 r memory-profiling r-faq

R 有一些用于内存分析的工具,例如带有选项“memory.profiling=TRUE”的 Rprofmem()Rprof()tracemem()。最后一个只能用于对象,因此对于跟踪对象被复制的次数很有用,但没有给出函数基础上的概述。 Rprofmem 应该能够做到这一点,但即使是像 lm() 这样最简单的函数调用的输出也会给出超过 500 行日志。我试图弄清楚 Rprof("somefile.log",memory.profile=T) 实际上做了什么,但我认为我并没有真正理解它。

我能找到的最后一个是 this message of Thomas Lumley ,这么说,我引用:

I do not yet have tools to summarize the output.

那是在 2006 年。现在有机会可以根据 Rprofmem()(Rprof() 的神秘输出)进行一些不错的摘要选择>memory.profile 设置 TRUE 或任何其他工具?

最佳答案

profvis看起来像是这个问题的解决方案。

它会生成一个交互式 .html 文件(使用 htmlwidgets),显示代码分析结果。

introduction vignette是对其功能的良好指南。

直接从介绍中获取,您可以像这样使用它:

devtools::install_github("rstudio/profvis")
library(profvis)

# Generate data
times <- 4e5
cols <- 150
data <- as.data.frame(x = matrix(rnorm(times * cols, mean = 5), ncol = cols))
data <- cbind(id = paste0("g", seq_len(times)), data)
profvis({
    data1 <- data   # Store in another variable for this run

    # Get column means
    means <- apply(data1[, names(data1) != "id"], 2, mean)

    # Subtract mean from each column
    for (i in seq_along(means)) {
        data1[, names(data1) != "id"][, i] <- data1[, names(data1) != "id"][, i] - means[i]
    }
}, height = "400px")

这给出

enter image description here

关于r - R 中的内存分析 - 总结工具,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5184953/

相关文章:

r - 使具有许多观察结果的多组线图更具可读性

r - 条形图中的自定义线(多个条形图)

r - R中的plot_ly旋转动画

python - 读取 Python 的 memory_profiler 的输出

r - 在 dplyr 的函数中使用变量名

r - 在 Rprofile.site 中使用 .libPaths 更改 R 默认库路径失败

r - 如何使绘图上的点大小与 p 值成比例?

python - 如何使用 pympler 跟踪/修复 tornado-redis 中的内存泄漏?

python - 解释 python memory_profiler 的输出

r - 将年和月 ("yyyy-mm"格式)转换为日期?