Skip to content

Commit

Permalink
Plugin for collecting and reporting indexing statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
odisseus committed Nov 22, 2024
1 parent 946c326 commit 76e5acd
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 7 deletions.
34 changes: 27 additions & 7 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,31 @@ version := "0.0.1"

resolvers += "JetBrains" at "https://packages.jetbrains.team/maven/p/ij/intellij-shared-indexes"

libraryDependencies ++= Seq(
"com.lihaoyi" %% "os-lib" % "0.10.5",
"com.lihaoyi" %% "mainargs" % "0.7.5",
"com.jetbrains.intellij.indexing.shared" % "ij-shared-indexes-tool" % "0.9.9",
"org.slf4j" % "slf4j-simple" % "2.0.13",
"org.scalatest" %% "scalatest" % "3.2.19" % Test,
"org.scalamock" %% "scalamock" % "6.0.0" % Test
lazy val indexingTools = project.in(file(".")).settings(
libraryDependencies ++= Seq(
"com.lihaoyi" %% "os-lib" % "0.10.5",
"com.lihaoyi" %% "mainargs" % "0.7.5",
"com.jetbrains.intellij.indexing.shared" % "ij-shared-indexes-tool" % "0.9.9",
"org.slf4j" % "slf4j-simple" % "2.0.13",
"org.scalatest" %% "scalatest" % "3.2.19" % Test,
"org.scalamock" %% "scalamock" % "6.0.0" % Test
)
)

lazy val reporterPlugin =
project.in(file("reporter-plugin"))
.enablePlugins(SbtIdeaPlugin)
.settings(
version := "0.0.1-SNAPSHOT",
scalaVersion := "2.13.14",
ThisBuild / intellijPluginName := "Indexing Statistics Reporter",
ThisBuild / intellijBuild := "233.15619.7",
ThisBuild / intellijPlatform := IntelliJPlatform.IdeaUltimate,
Global / intellijAttachSources := true,
Compile / javacOptions ++= "--release" :: "17" :: Nil,
intellijPlugins += "com.intellij.properties".toPlugin,
libraryDependencies += "com.eclipsesource.minimal-json" % "minimal-json" % "0.9.5" withSources(),
Compile / unmanagedResourceDirectories += baseDirectory.value / "resources",
Test / unmanagedResourceDirectories += baseDirectory.value / "testResources",
packageMethod := PackagingMethod.Standalone()
)
1 change: 1 addition & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
addSbtPlugin("org.jetbrains" % "sbt-idea-plugin" % "3.20.1")
19 changes: 19 additions & 0 deletions reporter-plugin/resources/META-INF/plugin.xml
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>
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
)
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)
}

}
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)
}
}

0 comments on commit 76e5acd

Please sign in to comment.