llvm-cov: Warn if object file is newer than profile
authorJustin Bogner <mail@justinbogner.com>
Mon, 4 May 2015 04:09:38 +0000 (04:09 +0000)
committerJustin Bogner <mail@justinbogner.com>
Mon, 4 May 2015 04:09:38 +0000 (04:09 +0000)
Looking at coverage with an out of date profile can be confusing.
Provide a little hint that something might be wrong.

llvm-svn: 236408

llvm/tools/llvm-cov/CodeCoverage.cpp

index 0331a02..f85f3b1 100644 (file)
@@ -195,7 +195,20 @@ CodeCoverageTool::createSourceFileView(StringRef SourceFile,
   return View;
 }
 
+static bool modifiedTimeGT(StringRef LHS, StringRef RHS) {
+  sys::fs::file_status Status;
+  if (sys::fs::status(LHS, Status))
+    return false;
+  auto LHSTime = Status.getLastModificationTime();
+  if (sys::fs::status(RHS, Status))
+    return false;
+  auto RHSTime = Status.getLastModificationTime();
+  return LHSTime > RHSTime;
+}
+
 std::unique_ptr<CoverageMapping> CodeCoverageTool::load() {
+  if (modifiedTimeGT(ObjectFilename, PGOFilename))
+    errs() << "warning: profile data may be out of date - object is newer\n";
   auto CoverageOrErr = CoverageMapping::load(ObjectFilename, PGOFilename,
                                              CoverageArch);
   if (std::error_code EC = CoverageOrErr.getError()) {