[platform] improves project FS stats collection (IDEA-CR-42488)

This commit is contained in:
Roman Shevchenko
2019-01-28 13:33:45 +01:00
parent c455a114d4
commit 0d149f7345
3 changed files with 42 additions and 24 deletions
@@ -4,7 +4,7 @@ package com.intellij.ide.startup.impl;
import com.intellij.diagnostic.PerformanceWatcher;
import com.intellij.ide.startup.ServiceNotReadyException;
import com.intellij.ide.startup.StartupManagerEx;
import com.intellij.internal.statistic.collectors.fus.project.FsCaseSensitivityTriggerCollector;
import com.intellij.internal.statistic.collectors.fus.project.ProjectFsStatsCollector;
import com.intellij.notification.Notification;
import com.intellij.notification.NotificationListener;
import com.intellij.notification.NotificationType;
@@ -271,7 +271,7 @@ public class StartupManagerImpl extends StartupManagerEx {
myProject);
}
FsCaseSensitivityTriggerCollector.trigger(myProject, actual);
ProjectFsStatsCollector.caseSensitivity(myProject, actual);
}
catch (FileNotFoundException e) {
LOG.warn(e);
@@ -284,7 +284,10 @@ public class StartupManagerImpl extends StartupManagerEx {
LocalFileSystem fs = LocalFileSystem.getInstance();
if (!(fs instanceof LocalFileSystemImpl)) return;
FileWatcher watcher = ((LocalFileSystemImpl)fs).getFileWatcher();
if (!watcher.isOperational()) return;
if (!watcher.isOperational()) {
ProjectFsStatsCollector.watchedRoots(myProject, -1);
return;
}
PooledThreadExecutor.INSTANCE.submit(() -> {
LOG.debug("FW/roots waiting started");
@@ -296,6 +299,7 @@ public class StartupManagerImpl extends StartupManagerEx {
LOG.debug("FW/roots waiting finished");
Collection<String> manualWatchRoots = watcher.getManualWatchRoots();
int pctNonWatched = 0;
if (!manualWatchRoots.isEmpty()) {
List<String> nonWatched = new SmartList<>();
for (VirtualFile root : roots) {
@@ -312,8 +316,11 @@ public class StartupManagerImpl extends StartupManagerEx {
watcher.notifyOnFailure(message, null);
LOG.info("unwatched roots: " + nonWatched);
LOG.info("manual watches: " + manualWatchRoots);
pctNonWatched = (int)(100.0 * nonWatched.size() / roots.length);
}
}
ProjectFsStatsCollector.watchedRoots(myProject, pctNonWatched);
});
}
@@ -1,21 +0,0 @@
// Copyright 2000-2019 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.collectors.fus.project
import com.intellij.internal.statistic.eventLog.FeatureUsageGroup
import com.intellij.internal.statistic.eventLog.FeatureUsageLogger
import com.intellij.internal.statistic.service.fus.collectors.FUSUsageContext
import com.intellij.internal.statistic.utils.createData
import com.intellij.openapi.project.Project
object FsCaseSensitivityTriggerCollector {
private val groupId = FeatureUsageGroup("statistics.project.root.fs.case", 1)
private val context = FUSUsageContext.create(FUSUsageContext.getOSNameContextData(), systemFsContextData())
@JvmStatic
fun trigger(project: Project, sensitivity: Boolean) {
FeatureUsageLogger.log(groupId, sensitivity.encode(), createData(project, context))
}
private fun systemFsContextData() = "system:" + (System.getProperty("idea.case.sensitive.fs")?.toBoolean()?.encode() ?: "default")
private fun Boolean.encode() = if (this) "case-sensitive" else "case-insensitive"
}
@@ -0,0 +1,32 @@
// Copyright 2000-2019 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.collectors.fus.project
import com.intellij.internal.statistic.eventLog.FeatureUsageData
import com.intellij.internal.statistic.eventLog.FeatureUsageGroup
import com.intellij.internal.statistic.eventLog.FeatureUsageLogger
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.SystemInfo
object ProjectFsStatsCollector {
private val groupId = FeatureUsageGroup("project.fs", 1)
@JvmStatic
fun caseSensitivity(project: Project, value: Boolean) {
FeatureUsageLogger.logState(groupId, "case-sensitivity", FeatureUsageData()
.addProject(project)
.addData("cs-project", value)
.addData("cs-system", SystemInfo.isFileSystemCaseSensitive)
.addData("cs-implicit", System.getProperty("idea.case.sensitive.fs") == null)
.addOS()
.build())
}
@JvmStatic
fun watchedRoots(project: Project, pctNonWatched: Int) {
FeatureUsageLogger.logState(groupId, "roots-watched", FeatureUsageData()
.addProject(project)
.addData("pct-non-watched", pctNonWatched)
.addData("os-name", SystemInfo.OS_NAME) // `addOS` groups uncommon OSes under 'Other' moniker
.build())
}
}