Skip to content

Commit 072a81d

Browse files
authored
Merge pull request #2 from magoorden/1-performance-measurement
#1 Added platform-independent performance statistics + other improvements. - Added the collection of platform-independent performance statistics. - Added `bdd_used_nodes_count()` that counts the number of used nodes. - Replaced static `CACHESTATS` by non-static `cachestats.enabled`, which is adaptable by user and configurable per BDD factory instance. - Removed global JVM shutdown hook, that prints cache statistics to `stdout`, from `JFactory`. - Cache statistics are now measured using `longs` rather than `ints` to reduce integer overflow issues. - Added `opAccess` statistic to cache statistics. - Added functionality to reset statistics.
2 parents 21fd960 + bd6c873 commit 072a81d

File tree

3 files changed

+317
-73
lines changed

3 files changed

+317
-73
lines changed

CHANGES.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
44

55
## [Unreleased]
66
* Added CHANGES.md to track changes between releases.
7+
* Added the collection of platform-independent performance statistics.
8+
* Added `bdd_used_nodes_count()` that counts the number of used nodes.
9+
* Replaced static `CACHESTATS` by non-static `cachestats.enabled`, which is adaptable by user and configurable per BDD factory instance.
10+
* Removed global JVM shutdown hook, that prints cache statistics to `stdout`, from `JFactory`.
11+
* Cache statistics are now measured using `longs` rather than `ints` to reduce integer overflow issues.
12+
* Added `opAccess` statistic to cache statistics.
13+
* Added functionality to reset statistics.
714

815
## [1.0.1] - 2020-03-17
916
* Updated SCM URL for proper Maven Central metadata.

src/main/java/com/github/javabdd/BDDFactory.java

Lines changed: 136 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Licensed under the terms of the GNU LGPL; see COPYING for details.
44
package com.github.javabdd;
55

6+
import java.util.ArrayList;
67
import java.util.Arrays;
78
import java.util.BitSet;
89
import java.util.Collection;
@@ -1235,16 +1236,20 @@ public ReorderStats getReorderStats() {
12351236
* Stores statistics about the operator cache.
12361237
*
12371238
* @author jwhaley
1239+
* @author sthuijsman
1240+
* @author mgoorden
12381241
* @version $Id: BDDFactory.java 480 2010-11-16 01:29:49Z robimalik $
12391242
*/
12401243
public static class CacheStats {
1241-
public int uniqueAccess;
1242-
public int uniqueChain;
1243-
public int uniqueHit;
1244-
public int uniqueMiss;
1245-
public int opHit;
1246-
public int opMiss;
1247-
public int swapCount;
1244+
protected boolean enabled = false;
1245+
public long uniqueAccess;
1246+
public long uniqueChain;
1247+
public long uniqueHit;
1248+
public long uniqueMiss;
1249+
public long opAccess;
1250+
public long opHit;
1251+
public long opMiss;
1252+
public long swapCount;
12481253

12491254
protected CacheStats() { }
12501255

@@ -1253,11 +1258,31 @@ void copyFrom(CacheStats that) {
12531258
this.uniqueChain = that.uniqueChain;
12541259
this.uniqueHit = that.uniqueHit;
12551260
this.uniqueMiss = that.uniqueMiss;
1261+
this.opAccess = that.opAccess;
12561262
this.opHit = that.opHit;
12571263
this.opMiss = that.opMiss;
12581264
this.swapCount = that.swapCount;
12591265
}
12601266

1267+
public void enableMeasurements() {
1268+
enabled = true;
1269+
}
1270+
1271+
public void disableMeasurements() {
1272+
enabled = false;
1273+
}
1274+
1275+
public void resetMeasurements() {
1276+
uniqueAccess = 0;
1277+
uniqueChain = 0;
1278+
uniqueHit = 0;
1279+
uniqueMiss = 0;
1280+
opAccess = 0;
1281+
opHit = 0;
1282+
opMiss = 0;
1283+
swapCount = 0;
1284+
}
1285+
12611286
/* (non-Javadoc)
12621287
* @see java.lang.Object#toString()
12631288
*/
@@ -1294,6 +1319,9 @@ public String toString() {
12941319
else
12951320
sb.append((float)0);
12961321
sb.append(newLine);
1322+
sb.append("Operator Access: ");
1323+
sb.append(opAccess);
1324+
sb.append(newLine);
12971325
sb.append("Operator Hits: ");
12981326
sb.append(opHit);
12991327
sb.append(newLine);
@@ -1327,6 +1355,107 @@ public CacheStats getCacheStats() {
13271355
return cachestats;
13281356
}
13291357

1358+
/**
1359+
* Stores statistics about the maximum BDD nodes usage.
1360+
*
1361+
* @author mgoorden
1362+
*/
1363+
public static class MaxUsedBddNodesStats {
1364+
protected boolean enabled = false;
1365+
protected int maxUsedBddNodes;
1366+
1367+
protected MaxUsedBddNodesStats() { }
1368+
1369+
public void enableMeasurements() {
1370+
enabled = true;
1371+
}
1372+
1373+
public void disableMeasurements() {
1374+
enabled = false;
1375+
}
1376+
1377+
public void resetMeasurements() {
1378+
maxUsedBddNodes = 0;
1379+
}
1380+
1381+
public void newMeasurement(int newUsedBddNodes) {
1382+
maxUsedBddNodes = Math.max(newUsedBddNodes, maxUsedBddNodes);
1383+
}
1384+
1385+
public int getMaxUsedBddNodes() {
1386+
return maxUsedBddNodes;
1387+
}
1388+
}
1389+
1390+
/**
1391+
* Singleton object for maximum used BDD nodes statistics.
1392+
*/
1393+
protected MaxUsedBddNodesStats maxusedbddnodesstats = new MaxUsedBddNodesStats();
1394+
1395+
/**
1396+
* <p>Return the current maximum used BDD nodes statistics for this BDD factory.</p>
1397+
*
1398+
* @return maximum used BDD nodes statistics
1399+
*/
1400+
public MaxUsedBddNodesStats getMaxUsedBddNodesStats() {
1401+
return maxusedbddnodesstats;
1402+
}
1403+
1404+
/**
1405+
* Stores continuously statistics about the BDD nodes usage and BDD operations,
1406+
* where BDD operations is a proxy for time.
1407+
*
1408+
* @author mgoorden
1409+
*/
1410+
public static class ContinuousStats {
1411+
protected boolean enabled = false;
1412+
protected List<Integer> contUsedBddNodes = new ArrayList<Integer>();
1413+
protected List<Long> contOperations = new ArrayList<Long>();
1414+
1415+
protected ContinuousStats() { }
1416+
1417+
public void enableMeasurements() {
1418+
enabled = true;
1419+
}
1420+
1421+
public void disableMeasurements() {
1422+
enabled = false;
1423+
}
1424+
1425+
public void resetMeasurements() {
1426+
contUsedBddNodes = new ArrayList<Integer>();
1427+
contOperations = new ArrayList<Long>();
1428+
}
1429+
1430+
public List<Integer> getNodesStats() {
1431+
if (contUsedBddNodes.size() != contOperations.size()) {
1432+
throw new AssertionError("Incorrect data collection.");
1433+
}
1434+
return contUsedBddNodes;
1435+
}
1436+
1437+
public List<Long> getOperationsStats() {
1438+
if (contUsedBddNodes.size() != contOperations.size()) {
1439+
throw new AssertionError("Incorrect data collection.");
1440+
}
1441+
return contOperations;
1442+
}
1443+
}
1444+
1445+
/**
1446+
* Singleton object for continuous statistics.
1447+
*/
1448+
protected ContinuousStats continuousstats = new ContinuousStats();
1449+
1450+
/**
1451+
* <p>Return the current continuous statistics for this BDD factory.</p>
1452+
*
1453+
* @return continuous statistics
1454+
*/
1455+
public ContinuousStats getContinuousStats() {
1456+
return continuousstats;
1457+
}
1458+
13301459
// TODO: bdd_sizeprobe_hook
13311460
// TODO: bdd_reorder_probe
13321461

0 commit comments

Comments
 (0)