20
20
import java .util .Objects ;
21
21
import java .util .Random ;
22
22
23
+ import com .diffplug .common .debug .LapTimer ;
24
+ import com .diffplug .common .debug .StepProfiler ;
23
25
import com .diffplug .spotless .FormatterStep .Strict ;
24
26
25
27
import edu .umd .cs .findbugs .annotations .SuppressFBWarnings ;
32
34
* from the API.
33
35
*/
34
36
@ 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
+
36
40
private static final long serialVersionUID = 1L ;
37
41
38
42
/** Transient because only the key matters. */
@@ -53,7 +57,12 @@ public String getName() {
53
57
54
58
@ Override
55
59
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
+ }
57
66
}
58
67
59
68
static final class Standard <Key extends Serializable > extends FormatterStepImpl <Key > {
@@ -70,9 +79,16 @@ static final class Standard<Key extends Serializable> extends FormatterStepImpl<
70
79
@ Override
71
80
protected String format (Key key , String rawUnix , File file ) throws Exception {
72
81
if (formatter == null ) {
82
+ PROFILER .startStep (name + " createFormatter" );
73
83
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 ();
74
91
}
75
- return formatter .apply (rawUnix );
76
92
}
77
93
}
78
94
@@ -90,15 +106,24 @@ static class Closeable<Key extends Serializable> extends FormatterStepImpl<Key>
90
106
@ Override
91
107
protected String format (Key key , String rawUnix , File file ) throws Exception {
92
108
if (formatter == null ) {
109
+ PROFILER .startStep (name + " openFormatter" );
93
110
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 ();
94
118
}
95
- return formatter .apply (rawUnix );
96
119
}
97
120
98
121
@ Override
99
122
public void finish () {
100
123
if (formatter != null ) {
124
+ PROFILER .startStep (name + " closeFormatter" );
101
125
formatter .close ();
126
+ PROFILER .finish ();
102
127
formatter = null ;
103
128
}
104
129
}
0 commit comments