-
Notifications
You must be signed in to change notification settings - Fork 272
Add file extension type metrics #4859
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
Changes from 1 commit
58cc77b
20a098a
47214c4
2bdf982
af2374e
483b14f
61026b4
aacbab5
be64a94
c686f1d
5b404c9
a589a04
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package software.aws.toolkits.jetbrains.services.telemetry | ||
|
||
import com.intellij.openapi.Disposable | ||
import com.intellij.openapi.fileEditor.FileEditorManager | ||
import com.intellij.openapi.fileEditor.FileEditorManagerListener | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.startup.ProjectActivity | ||
import com.intellij.openapi.vfs.VirtualFile | ||
import com.intellij.util.Alarm | ||
import software.aws.toolkits.telemetry.IdeTelemetry | ||
|
||
class OpenedFileTypesMetrics : ProjectActivity, Disposable { | ||
Check warning on line 15 in plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/services/telemetry/OpenedFileTypesMetrics.kt
|
||
private val currentOpenedFileTypes = mutableSetOf<String>() | ||
private val alarm = Alarm(Alarm.ThreadToUse.POOLED_THREAD, this) | ||
override suspend fun execute(project: Project) { | ||
// add already open file extensions | ||
FileEditorManager.getInstance(project).openFiles.forEach { | ||
it.extension?.let { openFileExtension -> currentOpenedFileTypes.add(openFileExtension) } | ||
} | ||
|
||
|
||
// add newly opened file extensions | ||
project.messageBus.connect().subscribe( | ||
manodnyab marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
FileEditorManagerListener.FILE_EDITOR_MANAGER, | ||
object : FileEditorManagerListener { | ||
override fun fileOpened(source: FileEditorManager, file: VirtualFile) { | ||
|
||
file.extension?.let { currentOpenedFileTypes.add(it) } | ||
|
||
} | ||
} | ||
) | ||
scheduleNextMetricEvent() | ||
} | ||
|
||
private fun scheduleNextMetricEvent() { | ||
alarm.addRequest(this::emitFileTypeMetric, INTERVAL_BETWEEN_METRICS) | ||
} | ||
|
||
override fun dispose() {} | ||
|
||
private fun emitFileTypeMetric() { | ||
currentOpenedFileTypes.forEach { | ||
rli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
IdeTelemetry.editCodeFile(project = null, filenameExt = it) | ||
manodnyab marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
flush() | ||
scheduleNextMetricEvent() | ||
} | ||
|
||
private fun flush() { | ||
currentOpenedFileTypes.clear() | ||
} | ||
manodnyab marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
companion object { | ||
const val INTERVAL_BETWEEN_METRICS = 30 * 60 * 1000 | ||
manodnyab marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.