【问题标题】:Line break issues with 'time' and 'make''time' 和 'make' 的换行问题
【发布时间】:2011-03-23 13:34:35
【问题描述】:

我正在用 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 为我运行的工作计时时看到过这种情况。

为什么会发生这种情况,我该怎么做才能获得一致的结果?

【问题讨论】:

    标签: linux time makefile


    【解决方案1】:

    time 是内置的 bash。 Makefile 的输出看起来像 /usr/bin/time 的输出。获得一致结果的最简单方法是在命令行上运行 '/usr/bin/time' 而不是 time。

    【讨论】:

    • 行尾还是很奇怪。
    • 谢谢! @Tomalak 如果您查看 time 手册页,它会向您展示如何设置自己的格式。
    • @Daniel:啊,是的。忽略我的最后一次。多么奇怪的默认格式字符串!
    • @Tomalak 确实。我喜欢/usr/bin/time 提供了更多的灵活性和输出,但我发现默认格式难以阅读。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-09-11
    • 2014-09-27
    • 2015-04-07
    • 2011-03-05
    • 2016-02-08
    • 2011-12-22
    • 2016-07-21
    相关资源
    最近更新 更多