简体   繁体   English

代码覆盖率和分析之间的差异

[英]difference between code coverage and profiling

What is difference between code code coverage and profiling. 代码覆盖率和分析之间有什么区别。

Which is the best open source tool for code coverage. 哪个是代码覆盖率最好的开源工具。

Code coverage is an assessment of how much of your code has been run. 代码覆盖率是对您的代码运行量的评估。 This is used to see how well your tests have exercised your code. 这用于查看测试执行代码的情况。

Profiling is used to see how various parts of your code perform. 分析用于查看代码的各个部分的执行情况。

The tools depend on the language and platform you are using. 这些工具取决于您使用的语言和平台。 I'm guessing that you are using Java, so recommend CodeCover . 我猜你正在使用Java,所以推荐使用CodeCover Though you may find NoUnit easier to use. 虽然您可能会发现NoUnit更容易使用。

Coverage is important to see which parts of the code have not been run. 覆盖范围是很重要的,看看哪部分代码没有被运行。 In my experience it has to be accumulated over multiple use cases, because any single run of the software will only use some of the code. 根据我的经验,它必须在多个用例中累积,因为任何一次运行的软件都只会使用一些代码。

Profiling means different things at different times. 分析在不同时间意味着不同的东西。 Sometimes it means measuring performance. 有时它意味着衡量绩效。 Sometimes it means diagnosing memory leaks. 有时它意味着诊断内存泄漏。 Sometimes it means getting visibility into multi-threading or other low-level activities. 有时它意味着可以了解多线程或其他低级别活动。

When the goal is to improve software performance, by finding so-called "bottlenecks" and fixing them, don't just settle for any profiler, not even necessarily a highly-recommended or venerable one. 当我们的目标是提高软件性能时,通过找到所谓的“瓶颈”并修复它们,不仅要满足于任何分析器,甚至不一定是高度推荐或古老的分析器。 It is essential to use the kind that gets the right kind of information and presents it to you the right way, because there is a lot of confusion about this. 必须使用能够获得正确信息并以正确方式呈现给您的那种信息,因为对此存在很多困惑。 More on that subject. 更多关于这个主题。

Added: For a coverage tool, I've always done it myself. 补充:对于覆盖工具,我总是自己做。 In nearly every routine and basic block, I insert a call like this: Utils.CovTest("file name, routine name, comment that tells what's being done here") . 在几乎每个例程和基本块中,我都插入一个这样的调用: Utils.CovTest("file name, routine name, comment that tells what's being done here") The routine records the fact that it was called, and when the program finishes, all those comments are appended to a text file. 例程记录了它被调用的事实,当程序完成时,所有这些注释都附加到文本文件中。 Then there's a post-processing step where that file is "subtracted" from a complete list (gotten by a grep-like program). 然后是一个后处理步骤,从完整列表中“减去”该文件(由类似grep的程序获取)。 The result is a list of what hasn't been tested, requiring additional test cases. 结果是什么也没有经过测试的列表,需要额外的测试用例。

When not doing coverage testing, Utils.CovTest does nothing. 当不进行覆盖测试时, Utils.CovTest什么都不做。 I leave it out of the innermost loops anyway, so it doesn't affect performance much. 无论如何,我把它留在最里面的循环中,所以它不会影响性能。 In C and C++, I do it with a macro that, during normal use, expands to nothing. 在C和C ++中,我使用一个宏,在正常使用期间,它会扩展为空。

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

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