From a8536294eaee05da95c8c9ea953f6021f31dcbf8 Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Thu, 30 May 2019 16:17:23 +0300 Subject: [PATCH] ui: add link to "Record State Collectors" action output GitOrigin-RevId: 75d09dc642484ad8867eea042a69362d3f585e69 --- .../RecordStateStatisticsEventLogAction.java | 24 ++++++++++++++----- .../eventLog/StatisticsEventLogWriter.kt | 7 ++++++ .../eventLog/StatisticsEventLogger.kt | 6 +++++ .../eventLog/StatisticsFileEventLogger.kt | 4 ++++ .../statistics/FeatureUsageEventLoggerTest.kt | 1 + 5 files changed, 36 insertions(+), 6 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/internal/statistic/actions/RecordStateStatisticsEventLogAction.java b/platform/platform-impl/src/com/intellij/internal/statistic/actions/RecordStateStatisticsEventLogAction.java index a33f2d603689..9fcff559994e 100644 --- a/platform/platform-impl/src/com/intellij/internal/statistic/actions/RecordStateStatisticsEventLogAction.java +++ b/platform/platform-impl/src/com/intellij/internal/statistic/actions/RecordStateStatisticsEventLogAction.java @@ -4,17 +4,22 @@ package com.intellij.internal.statistic.actions; import com.intellij.internal.statistic.eventLog.fus.FeatureUsageLogger; import com.intellij.internal.statistic.service.fus.collectors.FUStateUsagesLogger; import com.intellij.notification.Notification; +import com.intellij.notification.NotificationAction; import com.intellij.notification.NotificationType; -import com.intellij.notification.Notifications; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.fileEditor.FileEditorManager; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.progress.Task; import com.intellij.openapi.project.Project; +import com.intellij.openapi.vfs.LocalFileSystem; +import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; +import java.io.File; + public class RecordStateStatisticsEventLogAction extends AnAction { private static final FUStateUsagesLogger myStatesLogger = new FUStateUsagesLogger(); @@ -29,17 +34,24 @@ public class RecordStateStatisticsEventLogAction extends AnAction { @Override public void run(@NotNull ProgressIndicator indicator) { FeatureUsageLogger.INSTANCE.rollOver(); + File logFile = FeatureUsageLogger.INSTANCE.getConfig().getActiveLogFile(); + VirtualFile logVFile = logFile != null ? LocalFileSystem.getInstance().findFileByIoFile(logFile) : null; myStatesLogger.logApplicationStates(); myStatesLogger.logProjectStates(project); ApplicationManager.getApplication().invokeLater( - () -> showNotification(project, "Finished collecting and recording events") + () -> { + Notification notification = new Notification("FeatureUsageStatistics", "Feature Usage Statistics", + "Finished collecting and recording events", NotificationType.INFORMATION); + if (logVFile != null) { + notification.addAction(NotificationAction.createSimple("Show Log File", () -> { + FileEditorManager.getInstance(project).openFile(logVFile, true); + })); + } + notification.notify(project); + } ); } }); } - - protected void showNotification(@NotNull Project project, @NotNull String message) { - Notifications.Bus.notify(new Notification("FeatureUsageStatistics", "Feature Usage Statistics", message, NotificationType.INFORMATION), project); - } } diff --git a/platform/platform-impl/src/com/intellij/internal/statistic/eventLog/StatisticsEventLogWriter.kt b/platform/platform-impl/src/com/intellij/internal/statistic/eventLog/StatisticsEventLogWriter.kt index 310fe1eb215d..e9bba9690fae 100644 --- a/platform/platform-impl/src/com/intellij/internal/statistic/eventLog/StatisticsEventLogWriter.kt +++ b/platform/platform-impl/src/com/intellij/internal/statistic/eventLog/StatisticsEventLogWriter.kt @@ -14,6 +14,8 @@ import java.nio.file.Paths interface StatisticsEventLogWriter { fun log(message: String) + fun getActiveFile(): File? + fun getFiles(): List fun cleanup() @@ -58,6 +60,11 @@ class StatisticsEventLogFileWriter(private val recorderId: String, private val m eventLogger.info(message) } + override fun getActiveFile(): File? { + val activeLog = fileAppender?.activeLogName ?: return null + return File(File(getEventLogDir().toUri()), activeLog) + } + override fun getFiles(): List { val activeLog = fileAppender?.activeLogName val files = File(getEventLogDir().toUri()).listFiles { f: File -> !StringUtil.equals(f.name, activeLog) } diff --git a/platform/platform-impl/src/com/intellij/internal/statistic/eventLog/StatisticsEventLogger.kt b/platform/platform-impl/src/com/intellij/internal/statistic/eventLog/StatisticsEventLogger.kt index 58de207d8cb7..248b9b401036 100644 --- a/platform/platform-impl/src/com/intellij/internal/statistic/eventLog/StatisticsEventLogger.kt +++ b/platform/platform-impl/src/com/intellij/internal/statistic/eventLog/StatisticsEventLogger.kt @@ -16,6 +16,7 @@ private val EP_NAME = ExtensionPointName.create(" interface StatisticsEventLogger { fun log(group: EventLogGroup, eventId: String, isState: Boolean) fun log(group: EventLogGroup, eventId: String, data: Map, isState: Boolean) + fun getActiveLogFile(): File? fun getLogFiles(): List fun cleanup() fun rollOver() @@ -30,6 +31,10 @@ abstract class StatisticsEventLoggerProvider(val recorderId: String, abstract fun isRecordEnabled() : Boolean abstract fun isSendEnabled() : Boolean + fun getActiveLogFile(): File? { + return logger.getActiveLogFile() + } + fun getLogFiles(): List { return logger.getLogFiles() } @@ -61,6 +66,7 @@ class EmptyStatisticsEventLoggerProvider(recorderId: String): StatisticsEventLog class EmptyStatisticsEventLogger : StatisticsEventLogger { override fun log(group: EventLogGroup, eventId: String, isState: Boolean) = Unit override fun log(group: EventLogGroup, eventId: String, data: Map, isState: Boolean) = Unit + override fun getActiveLogFile(): File? = null override fun getLogFiles(): List = emptyList() override fun cleanup() = Unit override fun rollOver() = Unit diff --git a/platform/platform-impl/src/com/intellij/internal/statistic/eventLog/StatisticsFileEventLogger.kt b/platform/platform-impl/src/com/intellij/internal/statistic/eventLog/StatisticsFileEventLogger.kt index 901f29cacf80..3d746ac1c8e3 100644 --- a/platform/platform-impl/src/com/intellij/internal/statistic/eventLog/StatisticsFileEventLogger.kt +++ b/platform/platform-impl/src/com/intellij/internal/statistic/eventLog/StatisticsFileEventLogger.kt @@ -68,6 +68,10 @@ open class StatisticsFileEventLogger(private val recorderId: String, lastEvent = null } + override fun getActiveLogFile(): File? { + return writer.getActiveFile() + } + override fun getLogFiles(): List { return writer.getFiles() } diff --git a/platform/platform-tests/testSrc/com/intellij/internal/statistics/FeatureUsageEventLoggerTest.kt b/platform/platform-tests/testSrc/com/intellij/internal/statistics/FeatureUsageEventLoggerTest.kt index a36a328e54b7..d9d48479a1c5 100644 --- a/platform/platform-tests/testSrc/com/intellij/internal/statistics/FeatureUsageEventLoggerTest.kt +++ b/platform/platform-tests/testSrc/com/intellij/internal/statistics/FeatureUsageEventLoggerTest.kt @@ -321,6 +321,7 @@ class TestFeatureUsageEventWriter : StatisticsEventLogWriter { logged.add(message) } + override fun getActiveFile(): File? = null override fun getFiles(): List = emptyList() override fun cleanup() = Unit override fun rollOver() = Unit