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

DEV2-4344 add workspace tracing #693

Merged
merged 1 commit into from
Nov 27, 2023
Merged
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
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
Loading