Skip to content

Commit

Permalink
Fix the PidCollector to work with the configuration cache
Browse files Browse the repository at this point in the history
by not relying on gradle.buildFinished
simply writing the file instead

Before it was using a separate i/o thread, joined when the build is
finished to write the pid to a file, only to prevent i/o to interfere
with the performance.

Now it writes it as soon as it can in a simpler way.

Even though the AsyncWriter usage make sense for e.g.
GradleTracingPlugin which is writing quite a lot of stuff,
it shouldn't change much for writing the pid number.

This could be done with a BuildService listener but there isn't any way
to get ProcessEnvironment in one yet so the pid would have to be
captured at configuration time anyway.

Signed-off-by: Paul Merlin <[email protected]>
  • Loading branch information
eskatos committed May 27, 2020
1 parent 9fa749f commit 7382390
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class BuildOperationInstrumentationIntegrationTest extends AbstractProfilerInteg
]
if (configurationCache) {
file("gradle.properties") << """
org.gradle.unsafe.configuration-cache=warn
org.gradle.unsafe.configuration-cache=on
"""
}

Expand Down Expand Up @@ -83,7 +83,7 @@ class BuildOperationInstrumentationIntegrationTest extends AbstractProfilerInteg
args += commandLine
if (configurationCache) {
file("gradle.properties") << """
org.gradle.unsafe.configuration-cache=warn
org.gradle.unsafe.configuration-cache=on
"""
}
args += scenarioConfiguration ? "default" : "assemble"
Expand Down Expand Up @@ -158,7 +158,7 @@ class BuildOperationInstrumentationIntegrationTest extends AbstractProfilerInteg
]
if (configurationCache) {
file("gradle.properties") << """
org.gradle.unsafe.configuration-cache=warn
org.gradle.unsafe.configuration-cache=on
"""
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
package org.gradle.trace.pid;

import org.gradle.BuildAdapter;
import org.gradle.BuildResult;
import org.gradle.api.internal.GradleInternal;
import org.gradle.internal.nativeintegration.ProcessEnvironment;
import org.gradle.trace.stream.AsyncWriter;
import org.gradle.util.GFileUtils;

import java.io.File;

@SuppressWarnings("unused")
public class PidCollector {
public static void collect(GradleInternal gradle, File outFile) {
ProcessEnvironment processEnvironment = gradle.getServices().get(ProcessEnvironment.class);
AsyncWriter<Long> writer = new AsyncWriter<>(outFile, (l, w) -> w.print(l));
writer.append(processEnvironment.getPid());
writer.finished();
gradle.addBuildListener(new BuildAdapter(){
@Override
public void buildFinished(BuildResult result) {
writer.stop();
}
});
GFileUtils.writeFile(processEnvironment.getPid().toString(), outFile);
}
}

0 comments on commit 7382390

Please sign in to comment.