diff --git a/platform/platform-impl/src/com/intellij/internal/statistic/eventLog/FeatureUsageFileEventLoggerProvider.kt b/platform/platform-impl/src/com/intellij/internal/statistic/eventLog/FeatureUsageFileEventLoggerProvider.kt index 127c0ade0d5c..c59306842e03 100644 --- a/platform/platform-impl/src/com/intellij/internal/statistic/eventLog/FeatureUsageFileEventLoggerProvider.kt +++ b/platform/platform-impl/src/com/intellij/internal/statistic/eventLog/FeatureUsageFileEventLoggerProvider.kt @@ -13,7 +13,7 @@ class FeatureUsageFileEventLoggerProvider : FeatureUsageEventLoggerProvider { override fun createLogger(): FeatureUsageEventLogger { val sessionId = UUID.randomUUID().toString().shortedUUID() val build = ApplicationInfo.getInstance().build.asBuildNumber() - val logger = FeatureUsageFileEventLogger(sessionId, build, "-1", "4", FeatureUsageLogEventWriter()) + val logger = FeatureUsageFileEventLogger(sessionId, build, "-1", "5", FeatureUsageLogEventWriter()) ApplicationManager.getApplication().addApplicationListener(object : ApplicationAdapter() { override fun applicationExiting() { diff --git a/platform/platform-impl/src/com/intellij/internal/statistic/service/fus/collectors/AbstractUsageTrigger.java b/platform/platform-impl/src/com/intellij/internal/statistic/service/fus/collectors/AbstractUsageTrigger.java index 4d0273b9f5ed..31bf5937c3f2 100644 --- a/platform/platform-impl/src/com/intellij/internal/statistic/service/fus/collectors/AbstractUsageTrigger.java +++ b/platform/platform-impl/src/com/intellij/internal/statistic/service/fus/collectors/AbstractUsageTrigger.java @@ -41,10 +41,12 @@ public abstract class AbstractUsageTrigger imp protected abstract FeatureUsagesCollector findCollector(@NotNull Class fusClass); + protected abstract Map createEventLogData(@Nullable FUSUsageContext context); + protected void doTrigger(@NotNull String usageCollectorId, @NotNull String feature, @Nullable FUSUsageContext context) { - FeatureUsageLogger.INSTANCE.log(usageCollectorId, feature, context != null ? context.getData() : Collections.emptyMap()); + FeatureUsageLogger.INSTANCE.log(usageCollectorId, feature, createEventLogData(context)); SessionInfo sessionInfo = getOrCreateSessionInfo(); UsagesCollectorInfo collectorInfo = sessionInfo.getUsageCollectorInfo(usageCollectorId); diff --git a/platform/platform-impl/src/com/intellij/internal/statistic/service/fus/collectors/FUSApplicationUsageTrigger.java b/platform/platform-impl/src/com/intellij/internal/statistic/service/fus/collectors/FUSApplicationUsageTrigger.java index 2fa63d7f3b9b..54616f248c4f 100644 --- a/platform/platform-impl/src/com/intellij/internal/statistic/service/fus/collectors/FUSApplicationUsageTrigger.java +++ b/platform/platform-impl/src/com/intellij/internal/statistic/service/fus/collectors/FUSApplicationUsageTrigger.java @@ -2,8 +2,12 @@ package com.intellij.internal.statistic.service.fus.collectors; import com.intellij.internal.statistic.persistence.UsageStatisticsPersistenceComponent; +import com.intellij.internal.statistic.utils.StatisticsUtilKt; import com.intellij.openapi.components.*; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Map; @State(name = "FUSApplicationUsageTrigger", storages = @Storage(value = UsageStatisticsPersistenceComponent.USAGE_STATISTICS_XML, roamingType = RoamingType.DISABLED)) @@ -20,6 +24,11 @@ final public class FUSApplicationUsageTrigger extends AbstractUsageTrigger createEventLogData(@Nullable FUSUsageContext context) { + return StatisticsUtilKt.createData(null, context); + } + @Override protected FUSession getFUSession() { return FUSession.APPLICATION_SESSION; diff --git a/platform/platform-impl/src/com/intellij/internal/statistic/service/fus/collectors/FUSProjectUsageTrigger.java b/platform/platform-impl/src/com/intellij/internal/statistic/service/fus/collectors/FUSProjectUsageTrigger.java index 440ab381dec6..6222a630fda7 100644 --- a/platform/platform-impl/src/com/intellij/internal/statistic/service/fus/collectors/FUSProjectUsageTrigger.java +++ b/platform/platform-impl/src/com/intellij/internal/statistic/service/fus/collectors/FUSProjectUsageTrigger.java @@ -1,9 +1,13 @@ // Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.internal.statistic.service.fus.collectors; +import com.intellij.internal.statistic.utils.StatisticsUtilKt; import com.intellij.openapi.components.*; import com.intellij.openapi.project.Project; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Map; @State(name = "FUSProjectUsageTrigger", storages = { @Storage(value = StoragePathMacros.CACHE_FILE), @@ -30,6 +34,11 @@ final public class FUSProjectUsageTrigger extends AbstractUsageTrigger createEventLogData(@Nullable FUSUsageContext context) { + return StatisticsUtilKt.createData(myProject, context); + } + @Override protected FUSession getFUSession() { return FUSession.create(getProject()); diff --git a/platform/platform-impl/src/com/intellij/internal/statistic/service/fus/collectors/FUStatisticsAggregator.java b/platform/platform-impl/src/com/intellij/internal/statistic/service/fus/collectors/FUStatisticsAggregator.java index ff19b626eeac..faca5f2d1cae 100644 --- a/platform/platform-impl/src/com/intellij/internal/statistic/service/fus/collectors/FUStatisticsAggregator.java +++ b/platform/platform-impl/src/com/intellij/internal/statistic/service/fus/collectors/FUStatisticsAggregator.java @@ -7,6 +7,7 @@ import com.intellij.internal.statistic.service.fus.beans.CollectorGroupDescripto import com.intellij.internal.statistic.service.fus.beans.FSContent; import com.intellij.internal.statistic.service.fus.beans.FSGroup; import com.intellij.internal.statistic.service.fus.beans.FSSession; +import com.intellij.internal.statistic.utils.StatisticsUtilKt; import com.intellij.openapi.application.ex.ApplicationManagerEx; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectManager; @@ -15,7 +16,6 @@ import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map; import java.util.Set; @@ -70,26 +70,27 @@ public class FUStatisticsAggregator implements UsagesCollectorConsumer { synchronized (LOCK) { Map> usageDescriptors = new LinkedHashMap<>(); for (ApplicationUsagesCollector usagesCollector : ApplicationUsagesCollector.getExtensions(this)) { - - collectUsages(usageDescriptors, usagesCollector, usagesCollector.getContext(), usagesCollector::getUsages, approvedGroups, - isStateCollector(usagesCollector)); + collectUsages(null, usageDescriptors, usagesCollector, usagesCollector.getContext(), usagesCollector::getUsages, + approvedGroups, isStateCollector(usagesCollector)); } return usageDescriptors; } } - private static void collectUsages(@NotNull Map> usageDescriptors, + private static void collectUsages(@Nullable Project project, + @NotNull Map> usageDescriptors, @NotNull FeatureUsagesCollector usagesCollector, @Nullable FUSUsageContext context, @NotNull Factory> usagesProducer, - @NotNull Set approvedGroups, boolean isStateCollector) { + @NotNull Set approvedGroups, + boolean isStateCollector) { if (!usagesCollector.isValid()) return; if (approvedGroups.contains(usagesCollector.getGroupId())) { - addUsageDescriptors(usagesCollector.getGroupId(), context, usageDescriptors, usagesProducer, isStateCollector); + addUsageDescriptors(project, usagesCollector.getGroupId(), context, usageDescriptors, usagesProducer, isStateCollector); } else if (ApplicationManagerEx.getApplicationEx().isInternal()) { - addUsageDescriptors(createDebugModeId(usagesCollector.getGroupId()), context, usageDescriptors, usagesProducer, isStateCollector); + addUsageDescriptors(project, createDebugModeId(usagesCollector.getGroupId()), context, usageDescriptors, usagesProducer, isStateCollector); } } @@ -98,7 +99,7 @@ public class FUStatisticsAggregator implements UsagesCollectorConsumer { return "internal." + groupId; } - private static void addUsageDescriptors(@NotNull String groupDescriptor, + private static void addUsageDescriptors(@Nullable Project project, @NotNull String groupDescriptor, @Nullable FUSUsageContext context, @NotNull Map> allUsageDescriptors, @NotNull Factory> usagesProducer, boolean isStateCollector) { @@ -106,7 +107,7 @@ public class FUStatisticsAggregator implements UsagesCollectorConsumer { usages = usages.stream().filter(descriptor -> descriptor.getValue() > 0).collect(Collectors.toSet()); if (!usages.isEmpty()) { if (isStateCollector) { - logUsagesAsStateEvents(groupDescriptor, context, usages); + logUsagesAsStateEvents(project, groupDescriptor, context, usages); } CollectorGroupDescriptor collectorGroupDescriptor = CollectorGroupDescriptor.create(groupDescriptor, context); allUsageDescriptors.merge(collectorGroupDescriptor, usages, ContainerUtil::union); @@ -117,11 +118,11 @@ public class FUStatisticsAggregator implements UsagesCollectorConsumer { return !(usagesCollector instanceof FUStatisticsDifferenceSender); } - private static void logUsagesAsStateEvents(@NotNull String groupDescriptor, + private static void logUsagesAsStateEvents(@Nullable Project project, @NotNull String groupDescriptor, @Nullable FUSUsageContext context, @NotNull Set usages) { final FeatureUsageLogger logger = FeatureUsageLogger.INSTANCE; - final Map data = context != null ? context.getData() : Collections.emptyMap(); + final Map data = StatisticsUtilKt.createData(project, context); for (UsageDescriptor usage : usages) { logger.logState(groupDescriptor, usage.getKey(), data); } @@ -132,8 +133,8 @@ public class FUStatisticsAggregator implements UsagesCollectorConsumer { synchronized (LOCK) { Map> usageDescriptors = new LinkedHashMap<>(); for (ProjectUsagesCollector usagesCollector : ProjectUsagesCollector.getExtensions(this)) { - collectUsages(usageDescriptors, usagesCollector, usagesCollector.getContext(project), () -> usagesCollector.getUsages(project), - approvedGroups, isStateCollector(usagesCollector)); + collectUsages(project, usageDescriptors, usagesCollector, usagesCollector.getContext(project), + () -> usagesCollector.getUsages(project), approvedGroups, isStateCollector(usagesCollector)); } return usageDescriptors; } diff --git a/platform/platform-impl/src/com/intellij/internal/statistic/utils/StatisticsUtil.kt b/platform/platform-impl/src/com/intellij/internal/statistic/utils/StatisticsUtil.kt index 81005696d7d3..4f988d06475d 100644 --- a/platform/platform-impl/src/com/intellij/internal/statistic/utils/StatisticsUtil.kt +++ b/platform/platform-impl/src/com/intellij/internal/statistic/utils/StatisticsUtil.kt @@ -18,9 +18,11 @@ package com.intellij.internal.statistic.utils import com.intellij.ide.plugins.PluginManager import com.intellij.ide.plugins.PluginManagerMain import com.intellij.internal.statistic.beans.UsageDescriptor +import com.intellij.internal.statistic.service.fus.collectors.FUSUsageContext import com.intellij.openapi.extensions.PluginId import com.intellij.openapi.project.Project import com.intellij.openapi.project.getProjectCacheFileName +import com.intellij.util.containers.ContainerUtil import com.intellij.util.containers.ObjectIntHashMap import gnu.trove.THashSet import java.util.* @@ -29,6 +31,20 @@ fun getProjectId(project: Project): String { return project.getProjectCacheFileName(false, ".").hashCode().toString() } +fun createData(project: Project?, context: FUSUsageContext?): Map { + if (project == null && context == null) return Collections.emptyMap() + + val data = ContainerUtil.newHashMap() + if (context != null) { + data.putAll(context.data) + } + + if (project != null) { + data["project"] = getProjectId(project) + } + return data +} + fun isDevelopedByJetBrains(pluginId: PluginId?): Boolean { val plugin = PluginManager.getPlugin(pluginId) return plugin == null || plugin.isBundled || PluginManagerMain.isDevelopedByJetBrains(plugin.vendor)