Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin for collecting and reporting indexing statistics #14

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's put the duration and shared index utilization too, even though they can be computed. It will be easier to query.
Now that I am thinking, we might want to observe full indexing time (with sannings, as this also takes time and may change), and real indexing time (without pauses, it also shows in the report).

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,51 @@
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)
}
}