Skip to content

Commit

Permalink
Log the amount of time it takes for post-sync manifest parsing.
Browse files Browse the repository at this point in the history
Currently a batch of manifest parsing operations occur at the end of
each sync. Processing these manifests could take a long time but there's
no stats at the moment for how long it takes.

This CL adds logging for how long this post-sync manifest parsing takes
as well as the number of files processed.

PiperOrigin-RevId: 310615404
  • Loading branch information
Googler authored and copybara-github committed May 8, 2020
1 parent d22d157 commit e19da71
Showing 1 changed file with 44 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.android.ide.common.util.PathStringUtil;
import com.android.projectmodel.AndroidPathType;
import com.android.projectmodel.SourceSet;
import com.google.common.base.Stopwatch;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
Expand All @@ -46,6 +47,7 @@
import com.google.idea.blaze.base.ideinfo.ArtifactLocation;
import com.google.idea.blaze.base.ideinfo.TargetIdeInfo;
import com.google.idea.blaze.base.ideinfo.TargetKey;
import com.google.idea.blaze.base.logging.EventLoggingService;
import com.google.idea.blaze.base.model.BlazeProjectData;
import com.google.idea.blaze.base.model.primitives.Label;
import com.google.idea.blaze.base.model.primitives.TargetExpression;
Expand Down Expand Up @@ -75,6 +77,7 @@
import com.intellij.openapi.roots.libraries.LibraryTable;
import java.io.File;
import java.io.IOException;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand All @@ -88,6 +91,27 @@
public class BlazeAndroidProjectStructureSyncer {
private static final Logger log = Logger.getInstance(BlazeAndroidProjectStructureSyncer.class);

private static class ManifestParsingStatCollector {
private Duration totalDuration = Duration.ZERO;
private int fileCount = 0;

/** Adds duration to total duration counter. Also increments file count. */
void addDuration(Duration duration) {
totalDuration = totalDuration.plus(duration);
fileCount++;
}

/** Logs the total number of files processed and the amount of time it took. */
void submitLogEvent() {
EventLoggingService.getInstance()
.logEvent(
BlazeAndroidProjectStructureSyncer.class,
"PostSyncManifestParsing",
ImmutableMap.of(
"fileCount", "" + fileCount, "totalDurationMs", "" + totalDuration.toMillis()));
}
}

public static void updateProjectStructure(
Project project,
BlazeContext context,
Expand Down Expand Up @@ -310,7 +334,8 @@ public static Module ensureRunConfigurationModule(Project project, Label label)
moduleDirectory),
target.getAndroidIdeInfo().getResourceJavaPackage(),
ImmutableList.of(),
false);
false,
null);
return newModule;
}

Expand Down Expand Up @@ -365,7 +390,7 @@ private static void updateInMemoryState(
if (androidSdkPlatform == null) {
return;
}

ManifestParsingStatCollector manifestParsingStatCollector = new ManifestParsingStatCollector();
boolean configAndroidJava8Libs = hasConfigAndroidJava8Libs(projectViewSet);

updateWorkspaceModuleFacetInMemoryState(
Expand All @@ -374,7 +399,8 @@ private static void updateInMemoryState(
workspaceRoot,
workspaceModule,
androidSdkPlatform,
configAndroidJava8Libs);
configAndroidJava8Libs,
manifestParsingStatCollector);

ArtifactLocationDecoder artifactLocationDecoder = blazeProjectData.getArtifactLocationDecoder();
ModuleFinder moduleFinder = ModuleFinder.getInstance(project);
Expand Down Expand Up @@ -419,7 +445,8 @@ private static void updateInMemoryState(
moduleDirectoryForAndroidTarget(workspaceRoot, target)),
androidIdeInfo.getResourceJavaPackage(),
resources,
configAndroidJava8Libs);
configAndroidJava8Libs,
manifestParsingStatCollector);
String modulePackage = androidIdeInfo.getResourceJavaPackage();
rClassBuilder.addRClass(modulePackage, module);
sourcePackages.remove(modulePackage);
Expand Down Expand Up @@ -456,8 +483,10 @@ private static void updateInMemoryState(
moduleDirectoryForAndroidTarget(workspaceRoot, target)),
androidIdeInfo.getResourceJavaPackage(),
ImmutableList.of(),
configAndroidJava8Libs);
configAndroidJava8Libs,
manifestParsingStatCollector);
}
manifestParsingStatCollector.submitLogEvent();
}

@VisibleForTesting
Expand Down Expand Up @@ -490,7 +519,8 @@ private static void updateWorkspaceModuleFacetInMemoryState(
WorkspaceRoot workspaceRoot,
Module workspaceModule,
AndroidSdkPlatform androidSdkPlatform,
boolean configAndroidJava8Libs) {
boolean configAndroidJava8Libs,
@Nullable ManifestParsingStatCollector manifestParsingStatCollector) {
File moduleDirectory = workspaceRoot.directory();
File manifest = new File(workspaceRoot.directory(), "AndroidManifest.xml");
String resourceJavaPackage = ":workspace";
Expand All @@ -503,7 +533,8 @@ private static void updateWorkspaceModuleFacetInMemoryState(
manifest,
resourceJavaPackage,
ImmutableList.of(),
configAndroidJava8Libs);
configAndroidJava8Libs,
manifestParsingStatCollector);
}

private static void updateModuleFacetInMemoryState(
Expand All @@ -515,7 +546,8 @@ private static void updateModuleFacetInMemoryState(
File manifestFile,
String resourceJavaPackage,
Collection<File> resources,
boolean configAndroidJava8Libs) {
boolean configAndroidJava8Libs,
@Nullable ManifestParsingStatCollector manifestParsingStatCollector) {
SourceSet sourceSet =
new SourceSet(
ImmutableMap.of(
Expand All @@ -528,8 +560,12 @@ private static void updateModuleFacetInMemoryState(

String applicationId = resourceJavaPackage;
try {
Stopwatch timer = Stopwatch.createStarted();
ManifestParser.ParsedManifest parsedManifest =
ParsedManifestService.getInstance(project).getParsedManifest(manifestFile);
if (manifestParsingStatCollector != null) {
manifestParsingStatCollector.addDuration(timer.elapsed());
}
if (parsedManifest != null && parsedManifest.packageName != null) {
applicationId = parsedManifest.packageName;
}
Expand Down

0 comments on commit e19da71

Please sign in to comment.