@@ -78,20 +78,14 @@ abstract class ForkJoinParallelCpgPass[T <: AnyRef](cpg: Cpg, @nowarn outName: S
7878 nDiffT = flatgraph.DiffGraphApplier .applyDiff(cpg.graph, diffGraph)
7979 } catch {
8080 case exc : Exception =>
81- baseLogger.error(s " Pass ${ name} failed " , exc)
81+ baseLogger.error(s " Pass $name failed " , exc)
8282 throw exc
8383 } finally {
84- try {
85- finish()
86- } finally {
87- // the nested finally is somewhat ugly -- but we promised to clean up with finish(), we want to include finish()
88- // in the reported timings, and we must have our final log message if finish() throws
89- val nanosStop = System .nanoTime()
90- val fracRun = if (nanosBuilt == - 1 ) 0.0 else (nanosStop - nanosBuilt) * 100.0 / (nanosStop - nanosStart + 1 )
91- baseLogger.info(
92- f " Pass $name completed in ${(nanosStop - nanosStart) * 1e-6 }%.0f ms ( ${fracRun}%.0f%% on mutations). ${nDiff}%d + ${nDiffT - nDiff}%d changes committed from ${nParts}%d parts. "
93- )
94- }
84+ val nanosStop = System .nanoTime()
85+ val fracRun = if (nanosBuilt == - 1 ) 0.0 else (nanosStop - nanosBuilt) * 100.0 / (nanosStop - nanosStart + 1 )
86+ baseLogger.info(
87+ f " Pass $name completed in ${(nanosStop - nanosStart) * 1e-6 }%.0f ms ( $fracRun%.0f%% on mutations). $nDiff%d + ${nDiffT - nDiff}%d changes committed from $nParts%d parts. "
88+ )
9589 }
9690 }
9791
@@ -106,27 +100,12 @@ abstract class ForkJoinParallelCpgPass[T <: AnyRef](cpg: Cpg, @nowarn outName: S
106100 runOnPart(externalBuilder, parts(0 ).asInstanceOf [T ])
107101 case _ =>
108102 val stream =
109- if (! isParallel)
110- java.util.Arrays
111- .stream(parts)
112- .sequential()
113- else
114- java.util.Arrays
115- .stream(parts)
116- .parallel()
103+ if (! isParallel) java.util.Arrays .stream(parts).sequential()
104+ else java.util.Arrays .stream(parts).parallel()
117105 val diff = stream.collect(
118- new Supplier [DiffGraphBuilder ] {
119- override def get (): DiffGraphBuilder =
120- Cpg .newDiffGraphBuilder
121- },
122- new BiConsumer [DiffGraphBuilder , AnyRef ] {
123- override def accept (builder : DiffGraphBuilder , part : AnyRef ): Unit =
124- runOnPart(builder, part.asInstanceOf [T ])
125- },
126- new BiConsumer [DiffGraphBuilder , DiffGraphBuilder ] {
127- override def accept (leftBuilder : DiffGraphBuilder , rightBuilder : DiffGraphBuilder ): Unit =
128- leftBuilder.absorb(rightBuilder)
129- }
106+ () => Cpg .newDiffGraphBuilder,
107+ (builder : DiffGraphBuilder , part : AnyRef ) => runOnPart(builder, part.asInstanceOf [T ]),
108+ (leftBuilder : DiffGraphBuilder , rightBuilder : DiffGraphBuilder ) => leftBuilder.absorb(rightBuilder)
130109 )
131110 externalBuilder.absorb(diff)
132111 }
@@ -152,12 +131,12 @@ trait CpgPassBase {
152131 @ deprecated(" Please use createAndApply" )
153132 def createApplySerializeAndStore (serializedCpg : SerializedCpg , prefix : String = " " ): Unit
154133
155- /** Name of the pass. By default it is inferred from the name of the class, override if needed.
134+ /** Name of the pass. By default, it is inferred from the name of the class, override if needed.
156135 */
157136 def name : String = getClass.getName
158137
159138 /** Runs the cpg pass, adding changes to the passed builder. Use with caution -- API is unstable. Returns max(nParts,
160- * 1), where nParts is either the number of parallel parts, or the number of iterarator elements in case of legacy
139+ * 1), where nParts is either the number of parallel parts, or the number of iterator elements in case of legacy
161140 * passes. Includes init() and finish() logic.
162141 */
163142 def runWithBuilder (builder : DiffGraphBuilder ): Int
@@ -172,11 +151,11 @@ trait CpgPassBase {
172151 Try (runWithBuilder(builder)) match {
173152 case Success (nParts) =>
174153 baseLogger.info(
175- f " Pass ${ name} completed in ${(System .nanoTime() - nanoStart) * 1e-6 }%.0f ms. ${builder.size - size0}%d changes generated from ${ nParts} %d parts. "
154+ f " Pass $name completed in ${(System .nanoTime() - nanoStart) * 1e-6 }%.0f ms. ${builder.size - size0}%d changes generated from $nParts%d parts. "
176155 )
177156 nParts
178157 case Failure (exception) =>
179- baseLogger.warn(f " Pass ${ name} failed in ${(System .nanoTime() - nanoStart) * 1e-6 }%.0f ms " , exception)
158+ baseLogger.warn(f " Pass $name failed in ${(System .nanoTime() - nanoStart) * 1e-6 }%.0f ms " , exception)
180159 - 1
181160 }
182161 }
0 commit comments