public static void initializeForTests(ProcessRecorder.ExecutionRecordWriter recordWriter) { sINSTANCE = new ProcessRecorderFactory(); ProcessRecorder.resetForTests(); setEnabled(true); sINSTANCE.setRecordWriter(recordWriter); publishInitialRecords(); }
public static void shutdown() throws InterruptedException { synchronized (LOCK) { if (sINSTANCE.isInitialized()) { sINSTANCE.processProfileWriter.finish(); } sINSTANCE.processProfileWriter = null; } }
public static void recordMemorySample() { get().createAndRecordMemorySample(); }
public static void initialize(ILogger logger, File out) throws IOException { synchronized (LOCK) { if (sINSTANCE.isInitialized() || !isEnabled()) { return; } sINSTANCE.setLogger(logger); sINSTANCE.setOutputFile(out); sINSTANCE.setRecordWriter(new ProcessRecorder.JsonRecordWriter(new FileWriter(out))); publishInitialRecords(); } }
public static void publishInitialRecords() { ThreadRecorder.get().record(ExecutionType.INITIAL_METADATA, Recorder.EmptyBlock, new Recorder.Property("build_id", UUID.randomUUID().toString()), new Recorder.Property("os_name", System.getProperty("os.name")), new Recorder.Property("os_version", System.getProperty("os.version")), new Recorder.Property("java_version", System.getProperty("java.version")), new Recorder.Property("java_vm_version", System.getProperty("java.vm.version")), new Recorder.Property("max_memory", Long.toString(Runtime.getRuntime().maxMemory()))); }
@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); } }
@VisibleForTesting public static void initializeForTests(@NonNull Path profileOutputFile) { sINSTANCE = new ProcessProfileWriterFactory(); sINSTANCE.setProfileOutputFile(profileOutputFile); ProcessProfileWriter recorder = sINSTANCE.get(); // Initialize the ProcessProfileWriter instance recorder.resetForTests(); setGlobalProperties(recorder, new File("fake/path/to/test_project/"), "2.10", new StdLogger(StdLogger.Level.VERBOSE)); }
/** Properties and statistics global to this build invocation. */ @NonNull public static GradleBuildProfile.Builder getGlobalProperties() { return get().getProperties(); }
ProcessProfileWriter(@NonNull Path benchmarkProfileOutputFile) { mBenchmarkProfileOutputFile = benchmarkProfileOutputFile; mNameAnonymizer = new NameAnonymizer(); mBuild = GradleBuildProfile.newBuilder(); mStartMemoryStats = createAndRecordMemorySample(); mProjects = CacheBuilder.newBuilder().build(new ProjectCacheLoader(mNameAnonymizer)); spans = new ConcurrentLinkedQueue<>(); }
public static Recorder get() { return ProcessProfileWriterFactory.getFactory().isInitialized() ? RECORDER : NO_OP_RECORDER; }
@Override public Project load(@NonNull String name) throws Exception { return new Project(mNameAnonymizer.anonymizeProjectPath(name)); } }
synchronized ProcessProfileWriter get() { if (processProfileWriter == null) { Preconditions.checkState( profileOutputFile != null, "call setProfileOutputFile() first"); if (mLogger == null) { mLogger = new StdLogger(StdLogger.Level.INFO); } initializeAnalytics(mLogger, mScheduledExecutorService); processProfileWriter = new ProcessProfileWriter(profileOutputFile); } return processProfileWriter; } }
/** * Sets the {@link ProcessRecorder.JsonRecordWriter } * @param recordWriter */ public synchronized void setRecordWriter( @NonNull ProcessRecorder.ExecutionRecordWriter recordWriter) { assertRecorderNotCreated(); this.recordWriter = recordWriter; }
public static Recorder get() { return ProcessRecorderFactory.isEnabled() ? recorder : dummyRecorder; }
@SuppressWarnings("VariableNotUsedInsideIf") private void assertRecorderNotCreated() { if (isInitialized()) { throw new RuntimeException("ProcessProfileWriter already created."); } }
@SuppressWarnings("VariableNotUsedInsideIf") private void assertRecorderNotCreated() { if (isInitialized()) { throw new RuntimeException("ProcessRecorder already created."); } }
public synchronized void setLogger(@NonNull ILogger iLogger) { assertRecorderNotCreated(); this.mLogger = iLogger; }
@NonNull static ProcessRecorder get() { return ProcessRecorderFactory.sINSTANCE.get(); }
@NonNull public static ProcessProfileWriter get() { return ProcessProfileWriterFactory.sINSTANCE.get(); }
public synchronized void setLogger(@NonNull ILogger iLogger) { assertRecorderNotCreated(); this.iLogger = iLogger; }