Skip to content

Commit 36d1ab5

Browse files
committed
Quick 'n dirty profiling.
1 parent 0a2a825 commit 36d1ab5

File tree

5 files changed

+39
-5
lines changed

5 files changed

+39
-5
lines changed

lib-extra/build.gradle

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ apply from: rootProject.file('gradle/java-setup.gradle')
33
apply from: rootProject.file('gradle/java-publish.gradle')
44

55
dependencies {
6+
// temporary, for profiling
7+
compile 'com.diffplug.durian:durian-debug:1.0.0'
8+
69
compile project(':lib')
710
// misc useful utilities
811
compile "com.diffplug.durian:durian-core:${VER_DURIAN}"

lib/build.gradle

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ apply from: rootProject.file('gradle/java-setup.gradle')
33
apply from: rootProject.file('gradle/java-publish.gradle')
44

55
dependencies {
6+
// temporary, for profiling
7+
compile 'com.diffplug.durian:durian-debug:1.0.0'
68
// zero runtime reqs is a hard requirements for spotless-lib
79
// if you need a dep, put it in lib-extra
810
testCompile "junit:junit:${VER_JUNIT}"

lib/src/main/java/com/diffplug/spotless/FormatterStepImpl.java

+29-4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import java.util.Objects;
2121
import java.util.Random;
2222

23+
import com.diffplug.common.debug.LapTimer;
24+
import com.diffplug.common.debug.StepProfiler;
2325
import com.diffplug.spotless.FormatterStep.Strict;
2426

2527
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
@@ -32,7 +34,9 @@
3234
* from the API.
3335
*/
3436
@SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED")
35-
abstract class FormatterStepImpl<Key extends Serializable> extends Strict<Key> {
37+
public abstract class FormatterStepImpl<Key extends Serializable> extends Strict<Key> {
38+
public static final StepProfiler PROFILER = new StepProfiler(LapTimer.createNanoWrap2Sec());
39+
3640
private static final long serialVersionUID = 1L;
3741

3842
/** Transient because only the key matters. */
@@ -53,7 +57,12 @@ public String getName() {
5357

5458
@Override
5559
protected Key calculateKey() throws Exception {
56-
return keySupplier.get();
60+
try {
61+
PROFILER.startStep(name + " calculateKey");
62+
return keySupplier.get();
63+
} finally {
64+
PROFILER.finish();
65+
}
5766
}
5867

5968
static final class Standard<Key extends Serializable> extends FormatterStepImpl<Key> {
@@ -70,9 +79,16 @@ static final class Standard<Key extends Serializable> extends FormatterStepImpl<
7079
@Override
7180
protected String format(Key key, String rawUnix, File file) throws Exception {
7281
if (formatter == null) {
82+
PROFILER.startStep(name + " createFormatter");
7383
formatter = keyToFormatter.apply(key());
84+
PROFILER.finish();
85+
}
86+
try {
87+
PROFILER.startStep(name + " apply");
88+
return formatter.apply(rawUnix);
89+
} finally {
90+
PROFILER.finish();
7491
}
75-
return formatter.apply(rawUnix);
7692
}
7793
}
7894

@@ -90,15 +106,24 @@ static class Closeable<Key extends Serializable> extends FormatterStepImpl<Key>
90106
@Override
91107
protected String format(Key key, String rawUnix, File file) throws Exception {
92108
if (formatter == null) {
109+
PROFILER.startStep(name + " openFormatter");
93110
formatter = keyToFormatter.apply(key());
111+
PROFILER.finish();
112+
}
113+
try {
114+
PROFILER.startStep(name + " apply");
115+
return formatter.apply(rawUnix);
116+
} finally {
117+
PROFILER.finish();
94118
}
95-
return formatter.apply(rawUnix);
96119
}
97120

98121
@Override
99122
public void finish() {
100123
if (formatter != null) {
124+
PROFILER.startStep(name + " closeFormatter");
101125
formatter.close();
126+
PROFILER.finish();
102127
formatter = null;
103128
}
104129
}

plugin-gradle/build.gradle

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ apply from: rootProject.file('gradle/java-publish.gradle')
55
apply plugin: 'com.gradle.plugin-publish'
66
apply plugin: 'java-gradle-plugin'
77

8-
dependencies {
8+
dependencies { // temporary, for profiling
9+
compile 'com.diffplug.durian:durian-debug:1.0.0'
10+
911
compile project(':lib')
1012
compile project(':lib-extra')
1113
compile "com.diffplug.durian:durian-core:${VER_DURIAN}"

plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ApplyFormatTask.java

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.gradle.api.tasks.TaskAction;
2121

2222
import com.diffplug.spotless.Formatter;
23+
import com.diffplug.spotless.FormatterStepImpl;
2324
import com.diffplug.spotless.PaddedCellBulk;
2425

2526
public class ApplyFormatTask extends BaseFormatTask {
@@ -35,5 +36,6 @@ public void apply() throws Exception {
3536
formatter.applyFormat(file);
3637
}
3738
}
39+
FormatterStepImpl.PROFILER.printResults();
3840
}
3941
}

0 commit comments

Comments
 (0)