gpt4 book ai didi

linux - 'time' 和 'make' 的换行问题

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:01:55 24 4
gpt4 key购买 nike

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

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

最佳答案

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

关于linux - 'time' 和 'make' 的换行问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5406024/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com