From 40b90dccc8fb26a013f555c155d18ba32a438a34 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Sat, 6 Apr 2019 11:58:10 +0200 Subject: [PATCH] FileTypeManagerImpl: do not use constructor injection - just call directly connect to message using this as disposer --- .../ide/StartUpPerformanceReporter.kt | 53 +++++++++++++++++-- .../fileTypes/impl/FileTypeManagerImpl.java | 10 ++-- 2 files changed, 55 insertions(+), 8 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/ide/StartUpPerformanceReporter.kt b/platform/platform-impl/src/com/intellij/ide/StartUpPerformanceReporter.kt index 3c39c9fa6162..4c2d7f15fbaf 100644 --- a/platform/platform-impl/src/com/intellij/ide/StartUpPerformanceReporter.kt +++ b/platform/platform-impl/src/com/intellij/ide/StartUpPerformanceReporter.kt @@ -12,6 +12,7 @@ import com.intellij.openapi.project.DumbAware import com.intellij.openapi.project.Project import com.intellij.openapi.startup.StartupActivity import com.intellij.util.SystemProperties +import com.intellij.util.containers.ObjectLongHashMap import gnu.trove.THashMap import java.io.StringWriter import java.util.concurrent.TimeUnit @@ -167,11 +168,56 @@ private fun writeParallelActivities(activities: Map() + if (name.endsWith("Component")) { + val respectedItems = mutableListOf() + var computedDurationForAll = 0L + for ((index, item) in list.withIndex()) { + val totalDuration = item.end - item.start + var ownDuration = totalDuration + + if (index > 0 && list.get(index - 1).end > item.end) { + LOG.warn("prev ${list.get(index - 1).name} end > ${item.name}") + } + if (index > 0 && list.get(index - 1).start > item.start) { + LOG.warn("prev ${list.get(index - 1).name} start > ${item.name}") + } + + for (j in (index + 1) until list.size) { + val otherItem = list.get(j) + if (otherItem.start > item.start) { + if (otherItem.end < item.end) { + LOG.warn("${otherItem.name} start > ${item.name} but end is lesser") + } + break + } + + if (isInclusive(otherItem, item) && respectedItems.all { !isInclusive(otherItem, it) }) { + ownDuration -= otherItem.end - otherItem.start + respectedItems.add(otherItem) + } + } + + computedDurationForAll += ownDuration + if (totalDuration != ownDuration) { + ownDurations.put(item, ownDuration) + } + } + + val actualTotalDurationForAll = list.last().end - list.first().start + LOG.assertTrue(computedDurationForAll == actualTotalDurationForAll, "computed: $computedDurationForAll, actual: ${actualTotalDurationForAll}") + } + StartUpPerformanceReporter.sortItems(list) - writeActivities(list, startTime, writer, activityNameToJsonFieldName(name)) + writeActivities(list, startTime, writer, activityNameToJsonFieldName(name), ownDurations) } } +private fun isInclusive(otherItem: ActivityImpl, item: ActivityImpl): Boolean { + return otherItem.start >= item.start && otherItem.end <= item.end +} + private fun writeServiceStats(writer: JsonWriter) { class StatItem(val name: String) { var app = 0 @@ -218,7 +264,7 @@ private fun activityNameToJsonFieldName(name: String): String { } } -private fun writeActivities(activities: List, offset: Long, writer: JsonWriter, fieldName: String) { +private fun writeActivities(activities: List, offset: Long, writer: JsonWriter, fieldName: String, ownDurations: ObjectLongHashMap) { if (activities.isEmpty()) { return } @@ -230,7 +276,8 @@ private fun writeActivities(activities: List, offset: Long, writer for (item in activities) { writer.beginObject() writer.name("name").value(item.name) - writeItemTimeInfo(item, item.end - item.start, offset, writer) + val computedOwnDuration = ownDurations.get(item) + writeItemTimeInfo(item, if (computedOwnDuration == -1L) item.end - item.start else computedOwnDuration, offset, writer) writer.endObject() } diff --git a/platform/platform-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeManagerImpl.java index e8391cabef36..0c6b78396ede 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeManagerImpl.java @@ -148,13 +148,13 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements Persistent private final AtomicInteger counterAutoDetect = new AtomicInteger(); private final AtomicLong elapsedAutoDetect = new AtomicLong(); - public FileTypeManagerImpl(MessageBus bus, SchemeManagerFactory schemeManagerFactory, PropertiesComponent propertiesComponent) { - int fileTypeChangedCounter = StringUtilRt.parseInt(propertiesComponent.getValue("fileTypeChangedCounter"), 0); + public FileTypeManagerImpl() { + int fileTypeChangedCounter = PropertiesComponent.getInstance().getInt("fileTypeChangedCounter", 0); fileTypeChangedCount = new AtomicInteger(fileTypeChangedCounter); autoDetectedAttribute = new FileAttribute("AUTO_DETECTION_CACHE_ATTRIBUTE", fileTypeChangedCounter, true); - myMessageBus = bus; - mySchemeManager = schemeManagerFactory.create(FILE_SPEC, new NonLazySchemeProcessor() { + myMessageBus = ApplicationManager.getApplication().getMessageBus(); + mySchemeManager = SchemeManagerFactory.getInstance().create(FILE_SPEC, new NonLazySchemeProcessor() { @NotNull @Override public AbstractFileType readScheme(@NotNull Element element, boolean duringLoad) { @@ -212,7 +212,7 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements Persistent }, ModalityState.NON_MODAL); } }); - bus.connect().subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener() { + myMessageBus.connect(this).subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener() { @Override public void after(@NotNull List events) { Collection files = ContainerUtil.map2Set(events, (Function)event -> {