[llvm] llvm-cov: Introduce `-show-created-time` to suppress timestamps (PR #120417)

NAKAMURA Takumi via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 18 04:48:48 PST 2024


https://github.com/chapuni created https://github.com/llvm/llvm-project/pull/120417

NFC since `-show-created-time=true` by default.

>From 3a956cb99672886da477abde0b2995da2a29cb48 Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi <geek4civic at gmail.com>
Date: Wed, 18 Dec 2024 21:26:33 +0900
Subject: [PATCH] llvm-cov: Introduce `-show-created-time` to suppress
 timestamps

NFC since `-show-created-time=true` by default.
---
 .../llvm-cov/Inputs/showProjectSummary.test   | 13 +++++++++++++
 .../tools/llvm-cov/showProjectSummary.cpp     | 11 +++++++++++
 llvm/tools/llvm-cov/CodeCoverage.cpp          | 19 +++++++++++++------
 3 files changed, 37 insertions(+), 6 deletions(-)

diff --git a/llvm/test/tools/llvm-cov/Inputs/showProjectSummary.test b/llvm/test/tools/llvm-cov/Inputs/showProjectSummary.test
index 5eb6b4e24d5365..91d22e0e213b8f 100644
--- a/llvm/test/tools/llvm-cov/Inputs/showProjectSummary.test
+++ b/llvm/test/tools/llvm-cov/Inputs/showProjectSummary.test
@@ -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>
diff --git a/llvm/test/tools/llvm-cov/showProjectSummary.cpp b/llvm/test/tools/llvm-cov/showProjectSummary.cpp
index aa5e30e30d900e..c53e272cfdea27 100644
--- a/llvm/test/tools/llvm-cov/showProjectSummary.cpp
+++ b/llvm/test/tools/llvm-cov/showProjectSummary.cpp
@@ -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
@@ -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
diff --git a/llvm/tools/llvm-cov/CodeCoverage.cpp b/llvm/tools/llvm-cov/CodeCoverage.cpp
index d06fd86fe52afb..5db5c2e0235419 100644
--- a/llvm/tools/llvm-cov/CodeCoverage.cpp
+++ b/llvm/tools/llvm-cov/CodeCoverage.cpp
@@ -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"));
@@ -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)



More information about the llvm-commits mailing list