-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Plugin for collecting and reporting indexing statistics
- Loading branch information
Showing
6 changed files
with
121 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
addSbtPlugin("org.jetbrains" % "sbt-idea-plugin" % "3.20.1") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<idea-plugin> | ||
<id>com.virtuslab.indexing.stats.reporter</id> | ||
<name>Indexing Statistics Reporter</name> | ||
<version>0.0.1-SNAPSHOT</version> | ||
|
||
<description>A tool for collecting and reporting indexing statistics</description> | ||
<vendor>Virtus Lab sp. z o.o.</vendor> | ||
|
||
<idea-version since-build="233.0"/> | ||
|
||
<depends>com.intellij.modules.platform</depends> | ||
<depends>com.intellij.properties</depends> | ||
|
||
<extensions defaultExtensionNs="com.intellij"> | ||
<projectIndexingActivityHistoryListener | ||
implementation="com.virtuslab.indexing.listeners.IndexingStatsReporter"/> | ||
</extensions> | ||
|
||
</idea-plugin> |
11 changes: 11 additions & 0 deletions
11
reporter-plugin/src/main/scala/com/virtuslab/indexing/data/IndexingStats.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.virtuslab.indexing.data | ||
|
||
case class IndexingStats ( | ||
startedAt: Long, | ||
finishedAt: Long, | ||
isSharedIndexesEnabled: Boolean, | ||
isIncremental: Boolean, | ||
sharedIndexKindsUsed: Seq[String], | ||
numberOfIndexedFiles: Int, | ||
numberOfFilesCoveredBySharedIndexes: Int | ||
) |
46 changes: 46 additions & 0 deletions
46
reporter-plugin/src/main/scala/com/virtuslab/indexing/listeners/IndexingStatsReporter.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.virtuslab.indexing.listeners | ||
|
||
import com.intellij.openapi.util.registry.Registry | ||
import com.intellij.util.indexing.diagnostic.{ProjectDumbIndexingHistory, ProjectIndexingActivityHistoryListener, ProjectScanningHistory, SharedIndexDiagnostic} | ||
import com.virtuslab.indexing.data.IndexingStats | ||
import com.virtuslab.indexing.publish.IndexingStatsLogPublisher | ||
import it.unimi.dsi.fastutil.longs.LongCollection | ||
|
||
import scala.collection.concurrent.TrieMap | ||
import scala.jdk.CollectionConverters._ | ||
|
||
class IndexingStatsReporter extends ProjectIndexingActivityHistoryListener{ | ||
private val scanningRecord = new TrieMap[Long, ProjectScanningHistory]() | ||
|
||
override def onFinishedScanning(history: ProjectScanningHistory): Unit = { | ||
scanningRecord += history.getTimes.getScanningId -> history | ||
} | ||
|
||
override def onFinishedDumbIndexing(history: ProjectDumbIndexingHistory): Unit = { | ||
val histories = scanningRecord.view.filterKeys{ | ||
id => history.getTimes.getScanningIds.asInstanceOf[LongCollection].contains(id) | ||
} | ||
val numberOfFilesCoveredBySharedIndexes = history.getProviderStatistics.asScala | ||
.map(_.getTotalNumberOfFilesFullyIndexedByExtensions).sum | ||
val numberOfIndexedFiles = history.getProviderStatistics.asScala | ||
.map(_.getTotalNumberOfIndexedFiles).sum | ||
//FIXME read info about shared index kinds | ||
//val sharedIndexEvents = SharedIndexDiagnostic.readEvents(project) | ||
|
||
val isIncremental = histories.values.exists { s => | ||
s.getTimes.getScanningType.name().toLowerCase == "partial" | ||
} | ||
val report: IndexingStats = IndexingStats( | ||
startedAt = history.getTimes.getUpdatingStart.toEpochSecond, | ||
finishedAt = history.getTimes.getUpdatingEnd.toEpochSecond, | ||
isSharedIndexesEnabled = Registry.is("shared.indexes.download"), | ||
isIncremental = isIncremental, | ||
sharedIndexKindsUsed = Seq.empty, | ||
numberOfIndexedFiles = numberOfIndexedFiles, | ||
numberOfFilesCoveredBySharedIndexes = numberOfFilesCoveredBySharedIndexes | ||
) | ||
// TODO add an extension point | ||
IndexingStatsLogPublisher.publish(report) | ||
} | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
reporter-plugin/src/main/scala/com/virtuslab/indexing/publish/IndexingStatsPublisher.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.virtuslab.indexing.publish | ||
|
||
import com.intellij.openapi.diagnostic.Logger | ||
import com.virtuslab.indexing.data.IndexingStats | ||
|
||
trait IndexingStatsPublisher { | ||
def publish(stats: IndexingStats): Unit | ||
} | ||
|
||
object IndexingStatsLogPublisher extends IndexingStatsPublisher { | ||
|
||
private val logger = Logger.getInstance(classOf[IndexingStatsPublisher]) | ||
override def publish(stats: IndexingStats): Unit = { | ||
// TODO make sure the log format is reasonable | ||
logger.info(stats.toString) | ||
} | ||
} |