Skip to content

Commit

Permalink
DEV2-4344 add workspace tracing (#693)
Browse files Browse the repository at this point in the history
  • Loading branch information
amircodota authored Nov 27, 2023
1 parent b276ca2 commit 90e9f75
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ public enum Capability {
FORCE_REGISTRATION,
@SerializedName("plugin.feature.tabnine_chat")
TABNINE_CHAT,
@SerializedName("plugin.feature.workspace_trace")
WORKSPACE_TRACE,
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import com.intellij.openapi.project.Project
import com.intellij.openapi.project.ProjectManager
import com.intellij.openapi.roots.ProjectRootManager
import com.intellij.util.concurrency.AppExecutorUtil
import com.tabnineCommon.binary.requests.analytics.EventRequest
import com.tabnineCommon.binary.requests.fileLifecycle.Workspace
import com.tabnineCommon.capabilities.CapabilitiesService
import com.tabnineCommon.capabilities.Capability
import com.tabnineCommon.general.DependencyContainer
import java.io.File
import java.net.URL
Expand Down Expand Up @@ -42,11 +45,21 @@ class WorkspaceListenerService {
if (rootPaths.isNullOrEmpty()) return
Logger.getInstance(javaClass).info("All root paths collected: $rootPaths")

sendEvent("workspace_sending_request", mapOf("root_paths_len" to rootPaths.size.toString()))
binaryRequestFacade.executeRequest(Workspace(rootPaths))
}

private fun sendEvent(name: String, properties: Map<String, String>?) {
if (CapabilitiesService.getInstance().isCapabilityEnabled(Capability.WORKSPACE_TRACE)) {
binaryRequestFacade.executeRequest(EventRequest(name, properties))
}
}

fun getWorkspaceRootPaths(project: Project): List<String>? {
sendEvent("workspace_starting", mapOf())

if (project.isDisposed) {
sendEvent("workspace_project_disposed", mapOf())
Logger.getInstance(javaClass).warn("Project ${project.name} is disposed, skipping root paths resolution")
return null
}
Expand All @@ -55,17 +68,21 @@ class WorkspaceListenerService {
for (contentRootUrl in ProjectRootManager.getInstance(project).contentRootUrls) {
val url = URL(contentRootUrl)
if (url.protocol != "file") {
sendEvent("workspace_protocol_not_file", mapOf("path" to url.toString()))

Logger.getInstance(javaClass).debug("$url in project ${project.name} has unsupported protocol (${url.protocol})")
continue
}
if (File(url.path).list()?.isEmpty() != false) {
sendEvent("workspace_empty_path", mapOf("path" to url.path))
Logger.getInstance(javaClass).debug("${url.path} in project ${project.name} is empty, skipping")
continue
}
rootPaths.add(url.path)
}

val dedupedRootPaths = dedupRootPaths(rootPaths)
sendEvent("workspace_after_dedup", mapOf("before_len" to rootPaths.size.toString(), "after_len" to dedupedRootPaths.size.toString()))

Logger.getInstance(javaClass).debug("Root paths for project ${project.name} found: $dedupedRootPaths")
return dedupedRootPaths
Expand Down

0 comments on commit 90e9f75

Please sign in to comment.