“时间”的换行问题;和“制作”
我正在用 C 开发一些软件。我的 makefile 中的目标之一运行测试,我使用 time 来记录运行时,并使用 valgrind 来检查内存泄漏。当我直接从命令行调用较小的测试之一时,我得到了这一点。
$ time valgrind bin/test data/gff3/example1.gff3 data/gff3/example2.gff3
==27268== Memcheck, a memory error detector
==27268== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
==27268== Using Valgrind-3.6.0.SVN-Debian and LibVEX; rerun with -h for copyright info
==27268== Command: bin/test data/gff3/example1.gff3 data/gff3/example2.gff3
==27268==
==27268==
==27268== HEAP SUMMARY:
==27268== in use at exit: 0 bytes in 0 blocks
==27268== total heap usage: 4,001 allocs, 4,001 frees, 152,648 bytes allocated
==27268==
==27268== All heap blocks were freed -- no leaks are possible
==27268==
==27268== For counts of detected and suppressed errors, rerun with: -v
==27268== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 4 from 4)
real 0m1.460s
user 0m1.330s
sys 0m0.110s
但是,当我从 makefile 调用测试(使用相同的命令)时,我得到了这个。
$ make mem
time valgrind bin/test data/gff3/example1.gff3 data/gff3/example2.gff3
==27265== Memcheck, a memory error detector
==27265== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
==27265== Using Valgrind-3.6.0.SVN-Debian and LibVEX; rerun with -h for copyright info
==27265== Command: bin/test data/gff3/example1.gff3 data/gff3/example2.gff3
==27265==
==27265==
==27265== HEAP SUMMARY:
==27265== in use at exit: 0 bytes in 0 blocks
==27265== total heap usage: 4,001 allocs, 4,001 frees, 152,648 bytes allocated
==27265==
==27265== All heap blocks were freed -- no leaks are possible
==27265==
==27265== For counts of detected and suppressed errors, rerun with: -v
==27265== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 4 from 4)
1.32user 0.10system 0:01.55elapsed 91%CPU (0avgtext+0avgdata 214752maxresident)k
24inputs+8outputs (1major+18568minor)pagefaults 0swaps
底部的 time 程序的输出似乎存在换行问题,以及直接从命令行调用时我没有看到的一些附加输出。当我尝试为使用 nohup
运行的作业计时时,我曾经见过这种情况。
为什么会发生这种情况?我该怎么做才能获得一致的结果?
I am developing some software in C. One of the targets in my makefile runs a test, and I use time
to record the runtime and valgrind
to check for memory leaks. When I invoke one of the smaller tests directly from the command line, I get this.
$ time valgrind bin/test data/gff3/example1.gff3 data/gff3/example2.gff3
==27268== Memcheck, a memory error detector
==27268== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
==27268== Using Valgrind-3.6.0.SVN-Debian and LibVEX; rerun with -h for copyright info
==27268== Command: bin/test data/gff3/example1.gff3 data/gff3/example2.gff3
==27268==
==27268==
==27268== HEAP SUMMARY:
==27268== in use at exit: 0 bytes in 0 blocks
==27268== total heap usage: 4,001 allocs, 4,001 frees, 152,648 bytes allocated
==27268==
==27268== All heap blocks were freed -- no leaks are possible
==27268==
==27268== For counts of detected and suppressed errors, rerun with: -v
==27268== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 4 from 4)
real 0m1.460s
user 0m1.330s
sys 0m0.110s
However, when I invoke the test from my makefile (using the same exact command), I get this.
$ make mem
time valgrind bin/test data/gff3/example1.gff3 data/gff3/example2.gff3
==27265== Memcheck, a memory error detector
==27265== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
==27265== Using Valgrind-3.6.0.SVN-Debian and LibVEX; rerun with -h for copyright info
==27265== Command: bin/test data/gff3/example1.gff3 data/gff3/example2.gff3
==27265==
==27265==
==27265== HEAP SUMMARY:
==27265== in use at exit: 0 bytes in 0 blocks
==27265== total heap usage: 4,001 allocs, 4,001 frees, 152,648 bytes allocated
==27265==
==27265== All heap blocks were freed -- no leaks are possible
==27265==
==27265== For counts of detected and suppressed errors, rerun with: -v
==27265== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 4 from 4)
1.32user 0.10system 0:01.55elapsed 91%CPU (0avgtext+0avgdata 214752maxresident)k
24inputs+8outputs (1major+18568minor)pagefaults 0swaps
There seem to be line break issues with the output of the time
program at the bottom, as well as some additional output I didn't see when invoking directly from the command line. I've seen this before when I'm trying to time a job I've run with nohup
.
Why is this happening and what can I do to get consistent results?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
time 是 bash 的内置函数。 Makefile 的输出看起来像 /usr/bin/time 的输出。获得一致结果的最简单方法是在命令行上运行“/usr/bin/time”而不是 time。
time is a bash builtin. The output from your Makefile looks like the output of /usr/bin/time. The easiest way to get consistent results is to run '/usr/bin/time' instead of time on the command line.