Skip to content

Commit

Permalink
[jps cache] Add downloads statistic
Browse files Browse the repository at this point in the history
GitOrigin-RevId: d59d9ddd7099cd3431c9d8186b3669a5a202f249
  • Loading branch information
mmazurkevich authored and intellij-monorepo-bot committed Jul 21, 2021
1 parent 23b2d8e commit e2262f4
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions plugins/jps-cache/intellij.jps.cache.iml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<orderEntry type="library" name="Guava" level="project" />
<orderEntry type="module" module-name="intellij.platform.testFramework" scope="TEST" />
<orderEntry type="module" module-name="intellij.platform.ide.util.io" />
<orderEntry type="module" module-name="intellij.platform.statistics" />
<orderEntry type="module-library">
<library name="com.github.luben:zstd" type="repository">
<properties maven-id="com.github.luben:zstd-jni:1.4.0-1" />
Expand Down
1 change: 1 addition & 0 deletions plugins/jps-cache/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<extensions defaultExtensionNs="com.intellij">
<projectService serviceImplementation="com.intellij.jps.cache.loader.JpsOutputLoaderManager"/>
<postStartupActivity implementation="com.intellij.jps.cache.JpsCacheStartupActivity"/>
<statistics.counterUsagesCollector implementationClass="com.intellij.jps.cache.statistics.JpsCacheUsagesCollector"/>
<notificationGroup id="Compile Output Loader: Event Log" displayType="NONE"/>
<notificationGroup id="Compile Output Loader: Attention" displayType="STICKY_BALLOON"/>
<notificationGroup id="Compile Output Loader: Standard" displayType="BALLOON"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.concurrent.atomic.AtomicLong;

import static com.intellij.jps.cache.JpsCachesPluginUtil.EXECUTOR_SERVICE;
import static com.intellij.jps.cache.statistics.JpsCacheUsagesCollector.DOWNLOAD_SIZE_EVENT_ID;

class JpsCachesDownloader {
private static final Logger LOG = Logger.getInstance("com.intellij.jps.cache.client.JpsOutputsDownloader");
Expand Down Expand Up @@ -107,6 +108,7 @@ List<Pair<File, DownloadableFileDescription>> download(@NotNull File targetDir,
}
}
long duration = System.currentTimeMillis() - start;
DOWNLOAD_SIZE_EVENT_ID.log(totalSize.get());
LOG.info("Downloaded " + StringUtil.formatFileSize(totalSize.get()) + " in " + StringUtil.formatDuration(duration) +
"(" + duration + "ms). Percentage of CDN cache hits: " + (hitsCount * 100/myFilesDescriptions.size()) + "%");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import java.util.concurrent.atomic.AtomicBoolean;

import static com.intellij.execution.process.ProcessIOExecutorService.INSTANCE;
import static com.intellij.jps.cache.statistics.JpsCacheUsagesCollector.DOWNLOAD_DURATION_EVENT_ID;
import static com.intellij.jps.cache.ui.JpsLoaderNotifications.*;
import static org.jetbrains.jps.model.serialization.java.JpsJavaModelSerializerExtension.OUTPUT_TAG;
import static org.jetbrains.jps.model.serialization.java.JpsJavaModelSerializerExtension.URL_ATTRIBUTE;
Expand Down Expand Up @@ -303,12 +304,13 @@ private void saveStateAndNotify(LoaderStatus loaderStatus, String commitId, long

PropertiesComponent.getInstance().setValue(LATEST_COMMIT_ID, commitId);
BuildManager.getInstance().clearState(myProject);
long endTime = (System.currentTimeMillis() - startTime) / 1000;
long endTime = System.currentTimeMillis() - startTime;
ApplicationManager.getApplication().invokeLater(() -> {
STANDARD
.createNotification(JpsCacheBundle.message("notification.title.compiler.caches.loader"), JpsCacheBundle.message("notification.content.update.compiler.caches.completed.successfully.in.s", endTime), NotificationType.INFORMATION)
.createNotification(JpsCacheBundle.message("notification.title.compiler.caches.loader"), JpsCacheBundle.message("notification.content.update.compiler.caches.completed.successfully.in.s", endTime / 1000), NotificationType.INFORMATION)
.notify(myProject);
});
DOWNLOAD_DURATION_EVENT_ID.log(endTime);
myProject.getMessageBus().syncPublisher(PortableCachesLoadListener.TOPIC).loadingFinished(true);
LOG.info("Loading finished");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.jps.cache.statistics;

import com.intellij.internal.statistic.eventLog.EventLogGroup;
import com.intellij.internal.statistic.eventLog.events.EventFields;
import com.intellij.internal.statistic.eventLog.events.EventId1;
import com.intellij.internal.statistic.service.fus.collectors.CounterUsagesCollector;

public class JpsCacheUsagesCollector extends CounterUsagesCollector {
private static final EventLogGroup GROUP = new EventLogGroup("jps.cache", 1);
public static final EventId1<Long> DOWNLOAD_DURATION_EVENT_ID = GROUP.registerEvent("CachesDownloadDuration", EventFields.Long("download_time"));
public static final EventId1<Long> DOWNLOAD_SIZE_EVENT_ID = GROUP.registerEvent("CachesDownloadSize", EventFields.Long("download_size"));

@Override
public EventLogGroup getGroup() {
return GROUP;
}
}

0 comments on commit e2262f4

Please sign in to comment.