Commit 64ba19e9 authored by Shaverdova Elena's avatar Shaverdova Elena
Browse files

Move listener to component, see comments in IDEA-CR-33698

FUS-87 IDE and Project Lifecycle
parent 2ef07d0f
Showing with 18 additions and 42 deletions
+18 -42
// 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.diagnostic;
import com.intellij.featureStatistics.fusCollectors.AppLifecycleUsageTriggerCollector;
import com.intellij.ide.IdeBundle;
import com.intellij.internal.statistic.eventLog.FeatureUsageLogger;
import com.intellij.internal.statistic.service.fus.collectors.FUSApplicationUsageTrigger;
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.AnActionEvent;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.ApplicationComponent;
import com.intellij.openapi.util.LowMemoryWatcher;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import java.util.concurrent.atomic.AtomicBoolean;
import static com.intellij.openapi.util.LowMemoryWatcher.LowMemoryWatcherType.ONLY_AFTER_GC;
......@@ -19,6 +24,19 @@ public class LowMemoryNotifier implements ApplicationComponent {
private final LowMemoryWatcher myWatcher = LowMemoryWatcher.register(this::onLowMemorySignalReceived, ONLY_AFTER_GC);
private final AtomicBoolean myNotificationShown = new AtomicBoolean();
@Override
public void initComponent() {
IdePerformanceListener.Adapter handler = new IdePerformanceListener.Adapter() {
@Override
public void uiFreezeFinished(int lengthInSeconds) {
FUSApplicationUsageTrigger.getInstance().trigger(AppLifecycleUsageTriggerCollector.class, "ide.freeze");
FeatureUsageLogger.INSTANCE.log("lifecycle",
"ide.freeze", Collections.singletonMap("durationSeconds", lengthInSeconds));
}
};
ApplicationManager.getApplication().getMessageBus().connect().subscribe(IdePerformanceListener.TOPIC, handler);
}
private void onLowMemorySignalReceived() {
if (myNotificationShown.compareAndSet(false, true)) {
Notification notification = new Notification(IdeBundle.message("low.memory.notification.title"),
......
// 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.featureStatistics.fusCollectors;
import com.intellij.diagnostic.IdePerformanceListener;
import com.intellij.internal.statistic.eventLog.FeatureUsageLogger;
import com.intellij.internal.statistic.service.fus.collectors.FUSApplicationUsageTrigger;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.PreloadingActivity;
import com.intellij.openapi.progress.ProgressIndicator;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
public class UsageTriggerCollectionActivity extends PreloadingActivity {
@Override
public void preload(@NotNull ProgressIndicator indicator) {
IdePerformanceListener.Adapter handler = new IdePerformanceListener.Adapter() {
@Override
public void uiFreezeFinished(int lengthInSeconds) {
FUSApplicationUsageTrigger.getInstance().trigger(AppLifecycleUsageTriggerCollector.class,
"ide.freeze." + getLength(lengthInSeconds));
FeatureUsageLogger.INSTANCE.log("lifecycle",
"ide.freeze", Collections.singletonMap("durationSeconds", lengthInSeconds));
}
private String getLength(int seconds) {
if (seconds <= 1) {
return "0_1";
}
if (seconds <= 2) {
return "1_2";
}
if (seconds <= 5) {
return "2_5";
}
return "5_more";
}
};
ApplicationManager.getApplication().getMessageBus().connect().subscribe(IdePerformanceListener.TOPIC, handler);
}
}
......@@ -467,7 +467,6 @@
<preloadingActivity implementation="com.intellij.openapi.actionSystem.impl.ActionPreloader"/>
<preloadingActivity implementation="com.intellij.ide.ui.search.SearchableOptionPreloader"/>
<preloadingActivity implementation="com.intellij.featureStatistics.fusCollectors.UsageTriggerCollectionActivity"/>
<writingAccessProvider implementation="com.intellij.openapi.fileEditor.impl.NonProjectFileWritingAccessProvider" order="first"/>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment