mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[fileTypes & FUS] IJPL-178816 Start counting file type's schemas in FUS
GitOrigin-RevId: fe1951faa6aa39924ae79fd46309bb659c0040c2
This commit is contained in:
committed by
intellij-monorepo-bot
parent
73398d93a7
commit
8d61d23a40
+32
@@ -0,0 +1,32 @@
|
||||
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.internal.statistic.collectors.fus.fileTypes
|
||||
|
||||
import com.intellij.internal.statistic.eventLog.events.ObjectEventData
|
||||
import com.intellij.openapi.fileTypes.FileType
|
||||
import org.jetbrains.annotations.NotNull
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
internal class FileTypeSchemaCounter {
|
||||
private val NO_SCHEMA = ""
|
||||
private val fileTypeSchemaData: MutableMap<@NotNull FileType, MutableMap<String, Int>> = mutableMapOf()
|
||||
|
||||
fun recordFileTypeWithSchema(effectiveType: FileType, schemaType: String?) {
|
||||
val effectiveSchema = schemaType ?: NO_SCHEMA
|
||||
|
||||
val schemasForType = fileTypeSchemaData.getOrPut(effectiveType) { mutableMapOf() }
|
||||
val currentSchemaCount = schemasForType.getOrPut(effectiveSchema) { 0 }
|
||||
fileTypeSchemaData[effectiveType]!![effectiveSchema] = currentSchemaCount + 1
|
||||
}
|
||||
|
||||
fun getFileTypeSchemaUsagePercentage(effectiveType: FileType): List<ObjectEventData> {
|
||||
val schemaCounts = fileTypeSchemaData[effectiveType].orEmpty()
|
||||
val allSchemasCount = schemaCounts.values.sum()
|
||||
return schemaCounts.map { (schema, count) ->
|
||||
val schemaPercentage = ((count.toDouble() / allSchemasCount) * 100).roundToInt()
|
||||
ObjectEventData(
|
||||
FileTypeUsagesCollector.SCHEMA with schema,
|
||||
FileTypeUsagesCollector.PERCENT with schemaPercentage
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
+9
-8
@@ -22,24 +22,22 @@ import com.intellij.util.containers.ObjectIntMap;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
import static com.intellij.internal.statistic.collectors.fus.fileTypes.FileTypeUsageCounterCollector.findSchema;
|
||||
import static java.util.Collections.emptySet;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public final class FileTypeUsagesCollector extends ProjectUsagesCollector {
|
||||
private static final String DEFAULT_ID = "third.party";
|
||||
|
||||
private final EventLogGroup GROUP = new EventLogGroup("file.types", 7);
|
||||
private final EventLogGroup GROUP = new EventLogGroup("file.types", 8);
|
||||
|
||||
private final RoundedIntEventField COUNT = EventFields.RoundedInt("count");
|
||||
|
||||
// temporary is not collected
|
||||
private final EventField<String> SCHEMA = EventFields.StringValidatedByCustomRule("schema", FileTypeSchemaValidator.class);
|
||||
private final IntEventField PERCENT = EventFields.Int("percent");
|
||||
public static final EventField<String> SCHEMA = EventFields.StringValidatedByCustomRule("schema", FileTypeSchemaValidator.class);
|
||||
public static final IntEventField PERCENT = EventFields.Int("percent");
|
||||
private final ObjectListEventField FILE_SCHEME_PERCENT = new ObjectListEventField("file_schema", SCHEMA, PERCENT);
|
||||
|
||||
private final VarargEventId FILE_IN_PROJECT = GROUP.registerVarargEvent(
|
||||
@@ -62,10 +60,12 @@ public final class FileTypeUsagesCollector extends ProjectUsagesCollector {
|
||||
ProjectFileIndex projectFileIndex = ProjectFileIndex.getInstance(project);
|
||||
IProjectStore stateStore = ProjectKt.getStateStore(project);
|
||||
final ObjectIntMap<FileType> filesByTypeCount = new ObjectIntHashMap<>();
|
||||
var schemaCounter = new FileTypeSchemaCounter();
|
||||
projectFileIndex.iterateContent(
|
||||
file -> {
|
||||
FileType type = file.getFileType();
|
||||
filesByTypeCount.put(type, filesByTypeCount.getOrDefault(type, 0) + 1);
|
||||
schemaCounter.recordFileTypeWithSchema(type, findSchema(project, file));
|
||||
return true;
|
||||
},
|
||||
//skip files from .idea directory otherwise 99% of projects would have XML and PLAIN_TEXT file types
|
||||
@@ -74,10 +74,11 @@ public final class FileTypeUsagesCollector extends ProjectUsagesCollector {
|
||||
|
||||
final Set<MetricEvent> events = new HashSet<>();
|
||||
for (final FileType fileType : filesByTypeCount.keySet()) {
|
||||
List<EventPair<?>> eventPairs = new ArrayList<>(3);
|
||||
List<EventPair<?>> eventPairs = new ArrayList<>(4);
|
||||
eventPairs.add(EventFields.PluginInfoFromInstance.with(fileType));
|
||||
eventPairs.add(EventFields.FileType.with(fileType));
|
||||
eventPairs.add(COUNT.with(filesByTypeCount.get(fileType)));
|
||||
eventPairs.add(FILE_SCHEME_PERCENT.with(schemaCounter.getFileTypeSchemaUsagePercentage(fileType)));
|
||||
events.add(FILE_IN_PROJECT.metric(eventPairs));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user