Skip to content

llvm-cov: Introduce -show-created-time to suppress timestamps #120417

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions llvm/test/tools/llvm-cov/Inputs/showProjectSummary.test
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,16 @@ HTML-HEADER: <td><pre>Line</pre></td>
HTML-HEADER: <td><pre>Count</pre></td>
HTML-HEADER: <td><pre>Source</pre></td>
HTML-FOOTER: <h5>Generated by llvm-cov{{.*}}</h5>

HTMF-TITLE: <h1>Test Suite</h1>
HTMF: <h2>Coverage Report</h2>
HTMF-NOT: <h4>Created:
HTMF-FILE: <pre>{{.*}}showProjectSummary.cpp</pre>
HTMF-NOT: <h4>Created:
HTMF-FUNCTION: <pre>main</pre>
HTMF-NOT: <h4>Created:
HTMF-HEADER: <td><pre>Line</pre></td>
HTMF-HEADER: <td><pre>Count</pre></td>
HTMF-HEADER: <td><pre>Source</pre></td>
HTMF-NOT: <h4>Created:
HTMF-FOOTER: <h5>Generated by llvm-cov{{.*}}</h5>
11 changes: 11 additions & 0 deletions llvm/test/tools/llvm-cov/showProjectSummary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ int main(int argc, char ** argv) {
return x;
}

// RUN: rm -rf %t.dir

// Test console output.
// RUN: llvm-cov show %S/Inputs/showProjectSummary.covmapping -instr-profile %t.profdata -path-equivalence=/tmp,%S %s | FileCheck -check-prefixes=TEXT %S/Inputs/showProjectSummary.test
// RUN: llvm-cov show %S/Inputs/showProjectSummary.covmapping -instr-profile %t.profdata -path-equivalence=/tmp,%S -name=main %s | FileCheck -check-prefixes=TEXT %S/Inputs/showProjectSummary.test
Expand All @@ -27,3 +29,12 @@ int main(int argc, char ** argv) {
// RUN: FileCheck -check-prefixes=HTML-TITLE,HTML,HTML-FOOTER -input-file %t.dir/index.html %S/Inputs/showProjectSummary.test
// RUN: llvm-cov show %S/Inputs/showProjectSummary.covmapping -format=html -o %t.filtered.dir -instr-profile %t.profdata -project-title "Test Suite" -path-equivalence=/tmp,%S -name=main %s
// RUN: FileCheck -check-prefixes=HTML-TITLE,HTML,HTML-FOOTER -input-file %t.filtered.dir/index.html %S/Inputs/showProjectSummary.test

// Test html output. (w/o ctime)
// RUN: llvm-cov show %S/Inputs/showProjectSummary.covmapping -show-created-time=false -format=html -o %t.dir -instr-profile %t.profdata -path-equivalence=/tmp,%S %s
// RUN: FileCheck -check-prefixes=HTMF,HTMF-FILE,HTMF-HEADER -input-file %t.dir/coverage/tmp/showProjectSummary.cpp.html %S/Inputs/showProjectSummary.test
// RUN: llvm-cov show %S/Inputs/showProjectSummary.covmapping -show-created-time=false -format=html -o %t.dir -instr-profile %t.profdata -project-title "Test Suite" -path-equivalence=/tmp,%S %s
// RUN: FileCheck -check-prefixes=HTMF-TITLE,HTMF,HTMF-FILE,HTMF-HEADER -input-file %t.dir/coverage/tmp/showProjectSummary.cpp.html %S/Inputs/showProjectSummary.test
// RUN: FileCheck -check-prefixes=HTMF-TITLE,HTMF,HTMF-FOOTER -input-file %t.dir/index.html %S/Inputs/showProjectSummary.test
// RUN: llvm-cov show %S/Inputs/showProjectSummary.covmapping -show-created-time=false -format=html -o %t.filtered.dir -instr-profile %t.profdata -project-title "Test Suite" -path-equivalence=/tmp,%S -name=main %s
// RUN: FileCheck -check-prefixes=HTMF-TITLE,HTMF,HTMF-FOOTER -input-file %t.filtered.dir/index.html %S/Inputs/showProjectSummary.test
19 changes: 13 additions & 6 deletions llvm/tools/llvm-cov/CodeCoverage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,10 @@ int CodeCoverageTool::doShow(int argc, const char **argv,
cl::desc("Show directory coverage"),
cl::cat(ViewCategory));

cl::opt<bool> ShowCreatedTime("show-created-time", cl::Optional,
cl::desc("Show created time for each page."),
cl::init(true), cl::cat(ViewCategory));

cl::opt<std::string> ShowOutputDirectory(
"output-dir", cl::init(""),
cl::desc("Directory in which coverage information is written out"));
Expand Down Expand Up @@ -1112,12 +1116,15 @@ int CodeCoverageTool::doShow(int argc, const char **argv,
return 1;
}

auto ModifiedTime = Status.getLastModificationTime();
std::string ModifiedTimeStr = to_string(ModifiedTime);
size_t found = ModifiedTimeStr.rfind(':');
ViewOpts.CreatedTimeStr = (found != std::string::npos)
? "Created: " + ModifiedTimeStr.substr(0, found)
: "Created: " + ModifiedTimeStr;
if (ShowCreatedTime) {
auto ModifiedTime = Status.getLastModificationTime();
std::string ModifiedTimeStr = to_string(ModifiedTime);
size_t found = ModifiedTimeStr.rfind(':');
ViewOpts.CreatedTimeStr =
(found != std::string::npos)
? "Created: " + ModifiedTimeStr.substr(0, found)
: "Created: " + ModifiedTimeStr;
}

auto Coverage = load();
if (!Coverage)
Expand Down
Loading