فهرست منبع

instrumentation: Unique snippet file names

Updates the hash in snippet file naming to take the ProcessId into account
so that snippets with identical commands don't risk a collision in filename.

Additionally, this adds a `workingDir` to snippet files so that snippets with
identical commands can be more easily differentiated, such as with install
snippets.
Martin Duffy 7 ماه پیش
والد
کامیت
39f365ec3c
3فایلهای تغییر یافته به همراه29 افزوده شده و 19 حذف شده
  1. 16 13
      Help/manual/cmake-instrumentation.7.rst
  2. 12 6
      Source/cmInstrumentation.cxx
  3. 1 0
      Tests/RunCMake/Instrumentation/verify-snippet.cmake

+ 16 - 13
Help/manual/cmake-instrumentation.7.rst

@@ -236,11 +236,11 @@ Example:
   }
 
 In this example, after every ``cmake --build`` or ``cmake --install``
-invocation, an index file ``index-<hash>.json`` will be generated in
+invocation, an index file ``index-<timestamp>.json`` will be generated in
 ``<build>/.cmake/instrumentation/v1/data`` containing a list of data snippet
 files created since the previous indexing. The commands
-``/usr/bin/python callback.py index-<hash>.json`` and
-``/usr/bin/cmake -P callback.cmake arg index-<hash>.json`` will be executed in
+``/usr/bin/python callback.py index-<timestamp>.json`` and
+``/usr/bin/cmake -P callback.cmake arg index-<timestamp>.json`` will be executed in
 that order. The index file will contain the ``staticSystemInformation`` data and
 each snippet file listed in the index will contain the
 ``dynamicSystemInformation`` data. Once both callbacks have completed, the index
@@ -275,7 +275,7 @@ the command executed. Additionally, snippet files are created for the following:
 These files remain in the build tree until after `Indexing`_ occurs and any
 user-specified `Callbacks`_ are executed.
 
-Snippet files have a filename with the syntax ``<role>-<timestamp>-<hash>.json``
+Snippet files have a filename with the syntax ``<role>-<hash>-<timestamp>.json``
 and contain the following data:
 
   ``version``
@@ -285,6 +285,9 @@ and contain the following data:
   ``command``
     The full command executed. Excluded when ``role`` is ``build``.
 
+  ``workingDir``
+    The working directory in which the ``command`` was executed.
+
   ``result``
     The exit-value of the command, an integer.
 
@@ -450,14 +453,14 @@ Example:
     "buildDir": "<build>",
     "dataDir": "<build>/.cmake/instrumentation/v1/data",
     "snippets": [
-      "configure-<timestamp>-<hash>.json",
-      "generate-<timestamp>-<hash>.json",
-      "compile-<timestamp>-<hash>.json",
-      "compile-<timestamp>-<hash>.json",
-      "link-<timestamp>-<hash>.json",
-      "install-<timestamp>-<hash>.json",
-      "ctest-<timestamp>-<hash>.json",
-      "test-<timestamp>-<hash>.json",
-      "test-<timestamp>-<hash>.json",
+      "configure-<hash>-<timestamp>.json",
+      "generate-<hash>-<timestamp>.json",
+      "compile-<hash>-<timestamp>.json",
+      "compile-<hash>-<timestamp>.json",
+      "link-<hash>-<timestamp>.json",
+      "install-<hash>-<timestamp>.json",
+      "ctest-<hash>-<timestamp>.json",
+      "test-<hash>-<timestamp>.json",
+      "test-<hash>-<timestamp>.json",
     ]
   }

+ 12 - 6
Source/cmInstrumentation.cxx

@@ -399,6 +399,7 @@ std::string cmInstrumentation::InstrumentTest(
   root["testName"] = name;
   root["result"] = static_cast<Json::Value::Int64>(result);
   root["config"] = config;
+  root["workingDir"] = cmSystemTools::GetLogicalWorkingDirectory();
 
   // Post-Command
   this->InsertTimingData(root, steadyStart, systemStart);
@@ -407,9 +408,11 @@ std::string cmInstrumentation::InstrumentTest(
     this->InsertDynamicSystemInformation(root, "after");
   }
 
-  std::string file_name =
-    cmStrCat("test-", this->ComputeSuffixHash(command_str),
-             this->ComputeSuffixTime(), ".json");
+  cmsys::SystemInformation info;
+  std::string file_name = cmStrCat(
+    "test-",
+    this->ComputeSuffixHash(cmStrCat(command_str, info.GetProcessId())),
+    this->ComputeSuffixTime(), ".json");
   this->WriteInstrumentationJson(root, "data", file_name);
   return file_name;
 }
@@ -524,11 +527,14 @@ int cmInstrumentation::InstrumentCommand(
     }
   }
   root["role"] = command_type;
+  root["workingDir"] = cmSystemTools::GetLogicalWorkingDirectory();
 
   // Write Json
-  std::string const& file_name =
-    cmStrCat(command_type, "-", this->ComputeSuffixHash(command_str),
-             this->ComputeSuffixTime(), ".json");
+  cmsys::SystemInformation info;
+  std::string const& file_name = cmStrCat(
+    command_type, "-",
+    this->ComputeSuffixHash(cmStrCat(command_str, info.GetProcessId())),
+    this->ComputeSuffixTime(), ".json");
   this->WriteInstrumentationJson(root, "data", file_name);
   return ret;
 }

+ 1 - 0
Tests/RunCMake/Instrumentation/verify-snippet.cmake

@@ -31,6 +31,7 @@ function(snippet_has_fields snippet contents)
   get_filename_component(filename "${snippet}" NAME)
   has_key("${snippet}" "${contents}" role)
   has_key("${snippet}" "${contents}" result)
+  has_key("${snippet}" "${contents}" workingDir)
   if (NOT filename MATCHES "^build-*")
     has_key("${snippet}" "${contents}" command)
   endif()