aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-cov/CodeCoverage.cpp
diff options
context:
space:
mode:
authorYing Yi <maggieyi666@gmail.com>2016-08-24 14:27:23 +0000
committerYing Yi <maggieyi666@gmail.com>2016-08-24 14:27:23 +0000
commit84dc971ee2bc444a41d01051dba5b83d103ad952 (patch)
treeed2637dc11ef83639d3aa81a281d6463dc8882fd /llvm/tools/llvm-cov/CodeCoverage.cpp
parentc22e32deac405e042ffe4f05bf01bd5b6e3aa536 (diff)
downloadllvm-84dc971ee2bc444a41d01051dba5b83d103ad952.zip
llvm-84dc971ee2bc444a41d01051dba5b83d103ad952.tar.gz
llvm-84dc971ee2bc444a41d01051dba5b83d103ad952.tar.bz2
[llvm-cov] Add the project summary to each source file coverage report.
This patch includes the following changes: - Included header "Code coverage report" and include the date that the report was created. - Included title (as specified in a command line option, (i.e llvm-cov -project-title="Simple Test") - In the summary, list the elf files that the source code file has contributed to. - Used column heading for "Line No.", "Count No.", Source". Differential Revision: https://reviews.llvm.org/D23345 llvm-svn: 279628
Diffstat (limited to 'llvm/tools/llvm-cov/CodeCoverage.cpp')
-rw-r--r--llvm/tools/llvm-cov/CodeCoverage.cpp36
1 files changed, 31 insertions, 5 deletions
diff --git a/llvm/tools/llvm-cov/CodeCoverage.cpp b/llvm/tools/llvm-cov/CodeCoverage.cpp
index 6d7c7ae..019f18a 100644
--- a/llvm/tools/llvm-cov/CodeCoverage.cpp
+++ b/llvm/tools/llvm-cov/CodeCoverage.cpp
@@ -210,9 +210,9 @@ CodeCoverageTool::createFunctionView(const FunctionRecord &Function,
return nullptr;
auto Expansions = FunctionCoverage.getExpansions();
- auto View = SourceCoverageView::create(getSymbolForHumans(Function.Name),
- SourceBuffer.get(), ViewOpts,
- std::move(FunctionCoverage));
+ auto View = SourceCoverageView::create(
+ getSymbolForHumans(Function.Name), SourceBuffer.get(), ViewOpts,
+ std::move(FunctionCoverage), /*FunctionView=*/true);
attachExpansionSubViews(*View, Expansions, Coverage);
return View;
@@ -238,7 +238,7 @@ CodeCoverageTool::createSourceFileView(StringRef SourceFile,
auto SubViewExpansions = SubViewCoverage.getExpansions();
auto SubView = SourceCoverageView::create(
getSymbolForHumans(Function->Name), SourceBuffer.get(), ViewOpts,
- std::move(SubViewCoverage));
+ std::move(SubViewCoverage), /*FunctionView=*/true);
attachExpansionSubViews(*SubView, SubViewExpansions, Coverage);
if (SubView) {
@@ -463,6 +463,12 @@ int CodeCoverageTool::run(Command Cmd, int argc, const char **argv) {
CompareFilenamesOnly = FilenameEquivalence;
ViewOpts.Format = Format;
+ SmallString<128> ObjectFilePath(this->ObjectFilename);
+ if (std::error_code EC = sys::fs::make_absolute(ObjectFilePath)) {
+ error(EC.message(), this->ObjectFilename);
+ return 1;
+ }
+ ViewOpts.ObjectFilename = ObjectFilePath.c_str();
switch (ViewOpts.Format) {
case CoverageViewOptions::OutputFormat::Text:
ViewOpts.Colors = UseColor == cl::BOU_UNSET
@@ -589,6 +595,10 @@ int CodeCoverageTool::show(int argc, const char **argv,
cl::desc(
"Set tab expansion size for html coverage reports (default = 2)"));
+ cl::opt<std::string> ProjectTitle(
+ "project-title", cl::Optional,
+ cl::desc("Set project title for the coverage report"));
+
auto Err = commandLineParser(argc, argv);
if (Err)
return Err;
@@ -602,6 +612,7 @@ int CodeCoverageTool::show(int argc, const char **argv,
ViewOpts.ShowFunctionInstantiations = ShowInstantiations;
ViewOpts.ShowOutputDirectory = ShowOutputDirectory;
ViewOpts.TabSize = TabSize;
+ ViewOpts.ProjectTitle = ProjectTitle;
if (ViewOpts.hasOutputDirectory()) {
if (auto E = sys::fs::create_directories(ViewOpts.ShowOutputDirectory)) {
@@ -610,6 +621,19 @@ int CodeCoverageTool::show(int argc, const char **argv,
}
}
+ sys::fs::file_status Status;
+ if (sys::fs::status(PGOFilename, Status)) {
+ error("profdata file error: can not get the file status. \n");
+ return 1;
+ }
+
+ auto ModifiedTime = Status.getLastModificationTime();
+ std::string ModifiedTimeStr = ModifiedTime.str();
+ size_t found = ModifiedTimeStr.rfind(":");
+ ViewOpts.CreatedTimeStr = (found != std::string::npos)
+ ? "Created: " + ModifiedTimeStr.substr(0, found)
+ : "Created: " + ModifiedTimeStr;
+
auto Coverage = load();
if (!Coverage)
return 1;
@@ -643,7 +667,9 @@ int CodeCoverageTool::show(int argc, const char **argv,
}
// Show files
- bool ShowFilenames = SourceFiles.size() != 1;
+ bool ShowFilenames =
+ (SourceFiles.size() != 1) ||
+ (ViewOpts.Format == CoverageViewOptions::OutputFormat::HTML);
if (SourceFiles.empty())
// Get the source files from the function coverage mapping.