我有一个bash脚本,可以在运行命令时跟踪内存使用情况。它会启动所需的命令,然后记录一个日志,其中第一列是“程序使用的内存(以GB为单位)”,第二列是已经过的时间(以秒为单位)。例如:
31.282 1470
31.565 1480
31.848 1490
31.989 1500
32.273 1510
32.414 1520
32.697 1530
32.980 1540
33.122 1550
33.405 1560
6.511 1570
6.935 1580
7.502 1590
7.926 1600
8.351 1610
8.775 1620
9.059 1630
9.483 1640
9.908 1650
10.333 1660
我想做的是等待过程完成,然后使用R绘制随时间变化的内存使用情况图,并将其保存在当前目录中。我正在尝试使用R,并且知道需要使用哪些命令:
> heisenberg <- read.csv(file="4644.log",head=FALSE,sep=" ")
> plot(heisenberg$V2,heisenberg$V1,type="o",col="red",main="Memory Usage Over Time",xlab="Time (seconds)",ylab="Memory (gigabytes)")
> text(max(heisenberg$V2),max(heisenberg$V1),max(heisenberg$V1)) #Displays max value
但我卡住的部分是将图表保存为jpg或png格式。或者我如何在我的bash脚本中执行此命令。我是否绝对需要编写另一个R语言脚本并运行它?是否可能一次完成所有操作?
编辑
这是我的script.r代码:png("mem_usage_2965.png",height=800,width=800)
heisenberg <- read.csv(file="2965.log",head=FALSE,sep=" ")
plot(heisenberg$V2,heisenberg$V1,type="o",col="red",main="oases_k85",xlab="Time (seconds)",ylab="Memory (gigabytes)")
text(max(heisenberg),max(heisenberg),max(heisenberg))
dev.off()
请问有人能帮忙解决一下为什么输出的PNG图片中没有显示出最大值?我是在Bash脚本中这样调用的:R CMD BATCH script.r script.out
heisenberg$V1
和heisenberg$V2
的max()
呢?目前你正在计算heisenberg
数据框中 两个 坐标(x 和 y)的最大值,所以不奇怪它不会出现在图表上;它在图表之外。我认为你想要:with(heisenberg, text(max(V2), max(V1), max(V1)))
,至少这是你展示的原始代码片段所建议的。你知道新代码和原始代码不匹配吗? - Gavin Simpson