简体   繁体   English

如何防止gnuplot吞噬我的记忆?

[英]How can I prevent gnuplot from eating my memory?

I have a set of about 500 files with 33 datapoints. 我有一组包含33个数据点的大约500个文件。

I am plotting these files using the following gnuplot script 我正在使用以下gnuplot脚本绘制这些文件

do for [i=1:477] {
   reset
   set label sprintf('Time=%03d s',i) at 0, 0.4
   @png
   infile = sprintf('%d/lineX2_U.xy',i)
   outfile = sprintf('plot%03d.png',i)
   print i," ",infile," ",outfile
   set output outfile
   set xlabel "y [m]"
   set ylabel "u [m/s]"
   set xrange [-1:1]
   set yrange [0:1.2]
   plot infile  with line ls 1
}

where I use this macro 我在哪里使用这个宏

png="set terminal pngcairo size 1800,1800 crop enhanced font \"/usr/share/fonts/truetype/times.ttf,30\" dashlength 2; set termoption linewidth 3"

The problem is, that the memory usage of the system is increasing with time, until gnuplot finishes. 问题是,直到gnuplot完成,系统的内存使用量才会随着时间增加。 Proof: 证明:

> while true; do \grep MemFree /proc/meminfo ; sleep 10s; done;
MemFree:         9720956 kB
MemFree:         9121936 kB
MemFree:         8401072 kB
MemFree:         7682248 kB
MemFree:         6963356 kB
MemFree:         6219948 kB
MemFree:         5501612 kB
MemFree:         4758256 kB
MemFree:         4064564 kB
MemFree:         3346416 kB
MemFree:         2651620 kB
MemFree:         1933656 kB
MemFree:         1241644 kB
MemFree:          547836 kB
MemFree:          152200 kB
MemFree:          126396 kB
MemFree:          118232 kB
MemFree:          131612 kB
MemFree:          117760 kB
MemFree:          117936 kB
MemFree:          118368 kB
MemFree:        10934164 kB
MemFree:        10898460 kB
MemFree:        10863592 kB
MemFree:        10822712 kB

Which is monitoring the freely available memory during the execution of the gnuplot script. gnuplot脚本执行期间,它正在监视可用内存。 Of course, running out of memory is very undesired. 当然,耗尽内存是非常不希望的。 With and without reset seems to make no difference. 有和没有reset似乎没有什么区别。

After some tests, I found out that the issue is resolved by omitting the crop option for the pngcairo terminal. 经过一些测试,我发现通过省略pngcairo终端的crop选项可以解决该问题。

A minimal reproductive script then would be: 最小的生殖脚本将是:

set terminal png crop
do for [i=1:500] {
 set output sprintf('plot%03d.png', i)
 plot '+' using 1:(rand(0)) w l
}

How can this memory issue caused by the crop option for the pngcairo terminal be resolved? 如何解决由pngcairo终端的crop选项引起的内存问题?

Note: I am using gnuplot 4.6 注意:我正在使用gnuplot 4.6

This is a bug in the pngcairo terminal when using the crop option. 使用crop选项时,这是pngcairo终端中的错误。 The minimal example to reproduce this is 重现此问题的最小示例是

set terminal pngcairo size 1000,1000 crop
do for [i=1:500] {
  set output 'plot.png'
  plot x w l
  set output
}

Internally, the structure holding the cropped image was not freed, which led to the memory leak. 在内部,保存裁切图像的结构未释放,这导致内存泄漏。 This becomes apparent when generating many images. 当生成许多图像时,这变得明显。

The bug persists in 4.6 patchlevel 3, but was fixed in the development version on 2013-09-09, see #1278 Memory leak with 'pngcairo crop' . 该错误在4.6 patchlevel 3中仍然存在,但已在2013-09-09的开发版本中修复,请参阅#1278'pngcairo crop'的内存泄漏

EDIT: It is fixed in patchlevel 4. 编辑:在补丁程序级别4中已修复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM