/** Properties and statistics global to this build invocation. */ @NonNull public static GradleBuildProfile.Builder getGlobalProperties() { return get().getProperties(); }
public static void recordMemorySample() { get().createAndRecordMemorySample(); }
@NonNull public static GradleBuildProject.Builder getProject(@NonNull String projectPath) { return get().mProjects.getUnchecked(projectPath).properties; }
public static GradleBuildVariant.Builder addVariant( @NonNull String projectPath, @NonNull String variantName) { GradleBuildVariant.Builder properties = GradleBuildVariant.newBuilder(); get().addVariant(projectPath, variantName, properties); return properties; }
@Override public void record( @NonNull ExecutionType executionType, @NonNull String projectPath, @Nullable String variant, @NonNull VoidBlock block) { ProfileRecordWriter profileRecordWriter = ProcessProfileWriter.get(); GradleBuildProfileSpan.Builder currentRecord = create(profileRecordWriter, executionType, null); try { block.call(); } catch (IOException e) { throw new UncheckedIOException(e); } finally { write(profileRecordWriter, currentRecord, projectPath, variant); } }
/** * Initialize the {@link ProcessProfileWriterFactory}. Idempotent. * * @param project the current Gradle {@link Project}. */ public static void init(@NonNull Project project) { synchronized (LOCK) { //noinspection VariableNotUsedInsideIf if (recordingBuildListener != null) { return; } ProcessProfileWriterFactory.initialize( project.getRootProject().getProjectDir(), project.getGradle().getGradleVersion(), new LoggerWrapper(project.getLogger()), new File(project.getRootProject().getBuildDir(), "android-profile")); recordingBuildListener = new RecordingBuildListener(ProcessProfileWriter.get()); project.getGradle().addListener(recordingBuildListener); } project.getGradle().addListener(new ProfileShutdownListener(project)); }
@Nullable @Override public <T> T record( @NonNull ExecutionType executionType, @Nullable GradleTransformExecution transform, @NonNull String projectPath, @Nullable String variant, @NonNull Block<T> block) { ProfileRecordWriter profileRecordWriter = ProcessProfileWriter.get(); GradleBuildProfileSpan.Builder currentRecord = create(profileRecordWriter, executionType, transform); try { return block.call(); } catch (Exception e) { block.handleException(e); } finally { write(profileRecordWriter, currentRecord, projectPath, variant); } // we always return null when an exception occurred and was not rethrown. return null; }