Skip to content

Commit 2f23a6a

Browse files
authored
log node/edge/property count when loading proto CPGs (#1815)
* add log of count of graph elements during proto conversion flatgraph now logs this info internally while loading a graph. ODB graphs are converted on the fly to flatgraph, so that'll happen for those graphs as well. Add this for protos, and all formats are covered. * update flatgraph
1 parent b32da21 commit 2f23a6a

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name := "codepropertygraph"
22

33
// parsed by project/Versions.scala, updated by updateDependencies.sh
4-
val flatgraphVersion = "0.1.9"
4+
val flatgraphVersion = "0.1.12"
55

66
inThisBuild(
77
List(

codepropertygraph/src/main/scala/io/shiftleft/codepropertygraph/cpgloading/ProtoCpgLoader.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ object ProtoCpgLoader {
4141
implicit val interner: StringInterner = StringInterner.makeStrongInterner()
4242
val protoToGraphNodeMappings = new ProtoToGraphNodeMappings
4343
val cpg = openOrCreateCpg(storagePath)
44+
var edgeCount = 0
45+
var propCount = 0
4446

4547
// first pass: add the raw nodes without any properties or edges
4648
addNodesRaw(protoCpgs().flatMap(cpgProto => nodesIter(cpgProto)), cpg.graph, protoToGraphNodeMappings)
@@ -54,20 +56,23 @@ object ProtoCpgLoader {
5456
.findGNode(protoNode)
5557
.getOrElse(throw new ConversionException(s"node with proto node id=$protoNodeId not found in graph"))
5658
protoNode.getPropertyList.iterator().asScala.foreach { protoProperty =>
59+
propCount += 1
5760
diffGraph.setNodeProperty(gNode, protoProperty.getName.name(), extractPropertyValue(protoProperty.getValue()))
5861
}
5962
}
6063

6164
protoCpg.getEdgeList.iterator().asScala.foreach { protoEdge =>
6265
List(protoEdge.getSrc, protoEdge.getDst).map(protoToGraphNodeMappings.findGNode) match {
6366
case List(Some(srcNode), Some(dstNode)) =>
67+
edgeCount += 1
6468
diffGraph.addEdge(srcNode, dstNode, protoEdge.getType.name(), extractEdgePropertyValue(protoEdge))
6569
case _ => // at least one of the nodes doesn't exist in the cpg, most likely because it was filtered out - ignore
6670
}
6771
}
6872
}
6973

7074
DiffGraphApplier.applyDiff(cpg.graph, diffGraph)
75+
logger.debug(s"Loaded proto graph with ${cpg.graph.nodeCount} nodes, $edgeCount edges, $propCount properties")
7176
cpg
7277
}
7378

0 commit comments

Comments
 (0)