Indexing diagnostics: allow 2 indexing diagnostics to be dumped in one second.
authorSergey Patrikeev <Sergey.Patrikeev@jetbrains.com>
Tue, 11 Aug 2020 08:44:06 +0000 (11:44 +0300)
committerintellij-monorepo-bot <intellij-monorepo-bot-no-reply@jetbrains.com>
Tue, 11 Aug 2020 08:44:36 +0000 (08:44 +0000)
GitOrigin-RevId: 9e039559b4c1275af311ce53910d56a79d629fb9

platform/lang-impl/src/com/intellij/util/indexing/diagnostic/IndexDiagnosticDumper.kt

index a72f13734e50aed5bea98c1730318a65db6f9a2f..846ccc23b57c5c86e9f5f904498514cd4d464206 100644 (file)
@@ -16,6 +16,7 @@ import java.time.LocalDateTime
 import java.time.ZoneOffset
 import java.time.format.DateTimeFormatter
 import java.time.format.DateTimeParseException
+import java.util.concurrent.TimeUnit
 import kotlin.streams.asSequence
 
 object IndexDiagnosticDumper {
@@ -39,7 +40,11 @@ object IndexDiagnosticDumper {
     jacksonObjectMapper().registerKotlinModule().writerWithDefaultPrettyPrinter()
   }
 
-  private val diagnosticDateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm-ss")
+  private val diagnosticDateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm-ss.SSS")
+
+  private const val fileNamePrefix = "diagnostic-"
+
+  private var lastTime: LocalDateTime = LocalDateTime.MIN
 
   @Synchronized
   fun dumpProjectIndexingHistoryToLogSubdirectory(projectIndexingHistory: ProjectIndexingHistory) {
@@ -47,9 +52,14 @@ object IndexDiagnosticDumper {
       val indexDiagnosticDirectory = indexingDiagnosticDir
       indexDiagnosticDirectory.createDirectories()
 
-      val fileNamePrefix = "diagnostic-"
+      var nowTime = LocalDateTime.now()
+      if (lastTime == nowTime) {
+        // Ensure that the generated diagnostic file does not overwrite an existing file.
+        nowTime = nowTime.plusNanos(TimeUnit.MILLISECONDS.toNanos(1))
+        lastTime = nowTime
+      }
 
-      val timestamp = LocalDateTime.now().format(diagnosticDateTimeFormatter)
+      val timestamp = nowTime.format(diagnosticDateTimeFormatter)
       val diagnosticJson = indexDiagnosticDirectory.resolve("$fileNamePrefix$timestamp.json")
 
       val jsonIndexDiagnostic = JsonIndexDiagnostic.generateForHistory(projectIndexingHistory)