Skip to content

Commit 3223ea8

Browse files
authored
Engine tweaks for performance. Removed logging from more places. (#114)
* Engine tweaks for performance. Removed logging from more places. Fixes #113. Signed-off-by: Prabhu Subramanian <[email protected]> * Remove logging Signed-off-by: Prabhu Subramanian <[email protected]> --------- Signed-off-by: Prabhu Subramanian <[email protected]>
1 parent 0010773 commit 3223ea8

File tree

15 files changed

+338
-347
lines changed

15 files changed

+338
-347
lines changed

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name := "chen"
22
ThisBuild / organization := "io.appthreat"
3-
ThisBuild / version := "2.3.11"
3+
ThisBuild / version := "2.4.0"
44
ThisBuild / scalaVersion := "3.6.2"
55

66
val cpgVersion = "1.0.1"

ci/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ LABEL maintainer="appthreat" \
44
org.opencontainers.image.authors="Team AppThreat <[email protected]>" \
55
org.opencontainers.image.source="https://github.com/appthreat/chen" \
66
org.opencontainers.image.url="https://github.com/appthreat/chen" \
7-
org.opencontainers.image.version="2.3.x" \
7+
org.opencontainers.image.version="2.4.x" \
88
org.opencontainers.image.vendor="appthreat" \
99
org.opencontainers.image.licenses="Apache-2.0" \
1010
org.opencontainers.image.title="chen" \

codemeta.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"downloadUrl": "https://github.com/AppThreat/chen",
88
"issueTracker": "https://github.com/AppThreat/chen/issues",
99
"name": "chen",
10-
"version": "2.3.11",
10+
"version": "2.4.0",
1111
"description": "Code Hierarchy Exploration Net (chen) is an advanced exploration toolkit for your application source code and its dependency hierarchy.",
1212
"applicationCategory": "code-analysis",
1313
"keywords": [

dataflowengineoss/src/main/scala/io/appthreat/dataflowengineoss/passes/reachingdef/ReachingDefPass.scala

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import io.shiftleft.codepropertygraph.Cpg
66
import io.shiftleft.codepropertygraph.generated.nodes.*
77
import io.shiftleft.passes.ForkJoinParallelCpgPass
88
import io.shiftleft.semanticcpg.language.*
9-
import org.slf4j.{Logger, LoggerFactory}
109

1110
import scala.collection.mutable
1211

@@ -15,21 +14,14 @@ import scala.collection.mutable
1514
class ReachingDefPass(cpg: Cpg, maxNumberOfDefinitions: Int = 4000)(implicit s: Semantics)
1615
extends ForkJoinParallelCpgPass[Method](cpg):
1716

18-
private val logger: Logger = LoggerFactory.getLogger(this.getClass)
1917
// If there are any regex method full names, load them early
2018
s.loadRegexSemantics(cpg)
2119

2220
override def generateParts(): Array[Method] = cpg.method.toArray
2321

2422
override def runOnPart(dstGraph: DiffGraphBuilder, method: Method): Unit =
25-
logger.debug(
26-
"Calculating reaching definitions for: {} in {}",
27-
method.fullName,
28-
method.filename
29-
)
3023
val problem = ReachingDefProblem.create(method)
3124
if shouldBailOut(method, problem) then
32-
logger.warn("Skipping.")
3325
return
3426

3527
val solution = new DataFlowSolver().calculateMopSolutionForwards(problem)
@@ -49,9 +41,7 @@ class ReachingDefPass(cpg: Cpg, maxNumberOfDefinitions: Int = 4000)(implicit s:
4941
// For each node, the `gen` map contains the list of definitions it generates
5042
// We add up the sizes of these lists to obtain the total number of definitions
5143
val numberOfDefinitions = transferFunction.gen.foldLeft(0)(_ + _._2.size)
52-
logger.debug("Number of definitions for {}: {}", method.fullName, numberOfDefinitions)
5344
if numberOfDefinitions > maxNumberOfDefinitions then
54-
logger.warn("{} has more than {} definitions", method.fullName, maxNumberOfDefinitions)
5545
true
5646
else
5747
false

dataflowengineoss/src/main/scala/io/appthreat/dataflowengineoss/passes/reachingdef/ReachingDefProblem.scala

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ object ReachingDefProblem:
3939
*/
4040
class ReachingDefFlowGraph(val method: Method) extends FlowGraph[StoredNode]:
4141

42-
private val logger: Logger = LoggerFactory.getLogger(this.getClass)
43-
4442
val entryNode: StoredNode = method
4543
val exitNode: StoredNode = method.methodReturn
4644

@@ -89,7 +87,6 @@ class ReachingDefFlowGraph(val method: Method) extends FlowGraph[StoredNode]:
8987
case paramOut: MethodParameterOut => paramOut -> nextParamOutOrExit(paramOut)
9088
case cfgNode: CfgNode => cfgNode -> cfgNextOrFirstOutParam(cfgNode)
9189
case n =>
92-
logger.warn(s"Node type ${n.getClass.getSimpleName} should not be part of the CFG")
9390
n -> List()
9491
}.toMap
9592

@@ -105,7 +102,6 @@ class ReachingDefFlowGraph(val method: Method) extends FlowGraph[StoredNode]:
105102
case n if n == exitNode => n -> lastOutputParamOrLastNodeOfBody()
106103
case n @ (cfgNode: CfgNode) => n -> cfgNode.cfgPrev.l
107104
case n =>
108-
logger.warn(s"Node type ${n.getClass.getSimpleName} should not be part of the CFG")
109105
n -> List()
110106
}.toMap
111107

dataflowengineoss/src/main/scala/io/appthreat/dataflowengineoss/queryengine/AccessPathUsage.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,11 @@ object AccessPathUsage:
4343
// assume: MemberAccess.isGenericMemberAccessName(call.name)
4444
val argOne = memberAccess.argumentOption(1)
4545
if argOne.isEmpty then
46-
logger.debug(s"Missing first argument on call ${memberAccess.code}.")
4746
return (TrackedUnknown, Nil)
4847
val (base, tail) = toTrackedBaseAndAccessPathInternal(argOne.get)
4948
val path = AccessPathHandling.memberAccessToPath(memberAccess, tail)
5049
(base, path)
5150
case _ =>
52-
logger.debug(s"Missing handling for node type ${node.getClass}.")
5351
(TrackedUnknown, Nil)
5452
end if
5553
end toTrackedBaseAndAccessPathInternal

dataflowengineoss/src/main/scala/io/appthreat/dataflowengineoss/queryengine/Engine.scala

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import io.shiftleft.codepropertygraph.generated.nodes.*
88
import io.shiftleft.codepropertygraph.generated.{EdgeTypes, Properties}
99
import io.shiftleft.semanticcpg.language.*
1010
import io.shiftleft.semanticcpg.language.NoResolve
11-
import org.slf4j.{Logger, LoggerFactory}
1211
import overflowdb.Edge
1312

1413
import java.util.concurrent.*
@@ -26,7 +25,6 @@ class Engine(context: EngineContext):
2625

2726
import Engine.*
2827

29-
private val logger: Logger = LoggerFactory.getLogger(this.getClass)
3028
private val executorService: ExecutorService =
3129
Executors.newVirtualThreadPerTaskExecutor()
3230
private val completionService =
@@ -45,10 +43,6 @@ class Engine(context: EngineContext):
4543
* the analysis.
4644
*/
4745
def backwards(sinks: List[CfgNode], sources: List[CfgNode]): List[TableEntry] =
48-
if sources.isEmpty then
49-
logger.debug("Attempting to determine flows from empty list of sources.")
50-
if sinks.isEmpty then
51-
logger.debug("Attempting to determine flows to empty list of sinks.")
5246
reset()
5347
val sourcesSet = sources.toSet
5448
val tasks = createOneTaskPerSink(sinks)
@@ -103,24 +97,10 @@ class Engine(context: EngineContext):
10397
numberOfTasksRunning -= 1
10498

10599
submitTasks(tasks.toVector, sources)
106-
val startTimeSec: Long = System.currentTimeMillis / 1000
107100
runUntilAllTasksAreSolved()
108-
val taskFinishTimeSec: Long = System.currentTimeMillis / 1000
109-
logger.debug(
110-
"Time measurement -----> Task processing done in " +
111-
(taskFinishTimeSec - startTimeSec) + " seconds"
112-
)
113101
new HeldTaskCompletion(held.toList, mainResultTable).completeHeldTasks()
114-
val dedupResult = deduplicateFinal(extractResultsFromTable(sinks))
115-
val allDoneTimeSec: Long = System.currentTimeMillis / 1000
116-
117-
logger.debug(
118-
"Time measurement -----> Task processing: " +
119-
(taskFinishTimeSec - startTimeSec) + " seconds" +
120-
", Deduplication: " + (allDoneTimeSec - taskFinishTimeSec) +
121-
", Deduped results size: " + dedupResult.length
122-
)
123-
dedupResult
102+
// Deal with duplicates in downstream tools
103+
extractResultsFromTable(sinks)
124104
end solveTasks
125105

126106
private def submitTasks(tasks: Vector[ReachableByTask], sources: Set[CfgNode]): Unit =
@@ -314,11 +294,11 @@ case class EngineContext(
314294
* max limit on number arguments for which tasks will be created for unresolved arguments
315295
*/
316296
case class EngineConfig(
317-
var maxCallDepth: Int = 4,
297+
var maxCallDepth: Int = 3,
318298
initialTable: Option[mutable.Map[TaskFingerprint, Vector[ReachableByResult]]] = None,
319299
shareCacheBetweenTasks: Boolean = true,
320-
maxArgsToAllow: Int = 1000,
321-
maxOutputArgsExpansion: Int = 1000
300+
maxArgsToAllow: Int = 100,
301+
maxOutputArgsExpansion: Int = 100
322302
)
323303

324304
/** Tracks various performance characteristics of the query engine.

dataflowengineoss/src/main/scala/io/appthreat/dataflowengineoss/queryengine/TaskCreator.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ class TaskCreator(context: EngineContext):
8585
private def paramToArgs(param: MethodParameterIn): List[Expression] =
8686
val args = paramToArgsOfCallers(param) ++ paramToMethodRefCallReceivers(param)
8787
if args.size > context.config.maxArgsToAllow then
88-
logger.warn(s"Too many arguments for parameter: ${args.size}. Not expanding")
89-
logger.warn("Method name: " + param.method.fullName)
9088
List()
9189
else
9290
args
@@ -211,6 +209,5 @@ class TaskCreator(context: EngineContext):
211209
if l.size <= context.config.maxOutputArgsExpansion then
212210
l
213211
else
214-
logger.warn("Too many new tasks in expansion of unresolved output arguments")
215212
Vector()
216213
end TaskCreator

meta.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% set version = "2.3.11" %}
1+
{% set version = "2.4.0" %}
22

33
package:
44
name: chen

platform/frontends/ruby2atom/src/main/scala/io/appthreat/ruby2atom/astcreation/AstForExpressionsCreator.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,8 @@ trait AstForExpressionsCreator(implicit withSchemaValidation: ValidationMode):
591591
matchSplatExpression,
592592
reassign(lhs, op, thenClause, transform)
593593
)(x.span)
594+
case InClause(pattern, body) =>
595+
InClause(pattern, reassign(lhs, op, body, transform))(x.span)
594596

595597
rhs match
596598
case StatementList(statements) =>

0 commit comments

Comments
 (0)