Skip to content

Commit c94c742

Browse files
committed
Fixes from review
- Allow stat measurements to be disabled - More consistent naming of stat objects and methods. - Move stats measurements at several places to a separate method.
1 parent 956937f commit c94c742

File tree

2 files changed

+50
-51
lines changed

2 files changed

+50
-51
lines changed

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

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,44 +1355,52 @@ public void enableMeasurements() {
13551355
enabled = true;
13561356
}
13571357

1358+
public void disableMeasurements() {
1359+
enabled = false;
1360+
}
1361+
13581362
public void newMeasurement(int newUsedBddNodes) {
13591363
maxUsedBddNodes = Math.max(newUsedBddNodes, maxUsedBddNodes);
13601364
}
13611365

1362-
public int getMaxNodes() {
1366+
public int getMaxUsedNodes() {
13631367
return maxUsedBddNodes;
13641368
}
13651369
}
13661370

13671371
/**
1368-
* Singleton object for maximum BDD nodes statistics.
1372+
* Singleton object for maximum used BDD nodes statistics.
13691373
*/
1370-
protected MaxUsedBddNodesStats maxbddnodesstats = new MaxUsedBddNodesStats();
1374+
protected MaxUsedBddNodesStats maxusedbddnodesstats = new MaxUsedBddNodesStats();
13711375

13721376
/**
1373-
* <p>Return the current maximum BDD nodes statistics for this BDD factory.</p>
1377+
* <p>Return the current maximum used BDD nodes statistics for this BDD factory.</p>
13741378
*
1375-
* @return maximum memory statistics
1379+
* @return maximum used BDD statistics
13761380
*/
1377-
public MaxUsedBddNodesStats getMaxBddNodesStats() {
1378-
return maxbddnodesstats;
1381+
public MaxUsedBddNodesStats getMaxUsedBddNodesStats() {
1382+
return maxusedbddnodesstats;
13791383
}
13801384

13811385
/**
13821386
* Stores statistics about the maximum memory usage.
13831387
*
13841388
* @author mgoorden
13851389
*/
1386-
public static class MaxMemoryStats {
1390+
public static class MaxUsedMemoryStats {
13871391
protected boolean enabled = false;
13881392
protected long maxUsedMemory;
13891393

1390-
protected MaxMemoryStats() { }
1394+
protected MaxUsedMemoryStats() { }
13911395

13921396
public void enableMeasurements() {
13931397
enabled = true;
13941398
}
13951399

1400+
public void disableMeasurements() {
1401+
enabled = false;
1402+
}
1403+
13961404
public void newMeasurement(long newMemory) {
13971405
maxUsedMemory = Math.max(newMemory, maxUsedMemory);
13981406
}
@@ -1403,50 +1411,55 @@ public long getMaxUsedMemory() {
14031411
}
14041412

14051413
/**
1406-
* Singleton object for maximum memory statistics.
1414+
* Singleton object for maximum used memory statistics.
14071415
*/
1408-
protected MaxMemoryStats maxmemorystats = new MaxMemoryStats();
1416+
protected MaxUsedMemoryStats maxusedmemorystats = new MaxUsedMemoryStats();
14091417

14101418
/**
1411-
* <p>Return the current maximum memory statistics for this BDD factory.</p>
1419+
* <p>Return the current maximum used memory statistics for this BDD factory.</p>
14121420
*
1413-
* <p>Note that measuring max memory usages fluctuates over time, tool
1421+
* <p>Note that measuring max used memory usages fluctuates over time, tool
14141422
* implementation, used hardware, etc.</p>
14151423
*
1416-
* @return maximum memory statistics
1424+
* @return maximum used memory statistics
14171425
*/
1418-
public MaxMemoryStats getMaxMemoryStats() {
1419-
return maxmemorystats;
1426+
public MaxUsedMemoryStats getMaxUsedMemoryStats() {
1427+
return maxusedmemorystats;
14201428
}
14211429

14221430
/**
1423-
* Stores continuously statistics about the memory usage and BDD operations.
1431+
* Stores continuously statistics about the BDD nodes usage and BDD operations,
1432+
* where BDD operations is a proxy for time.
14241433
*
14251434
* @author mgoorden
14261435
*/
14271436
public static class ContinuousStats {
14281437
protected boolean enabled = false;
14291438
protected List<Integer> contUsedBddNodes = new ArrayList<Integer>();
1430-
protected List<Long> contUsedOperations = new ArrayList<Long>();
1439+
protected List<Long> contOperations = new ArrayList<Long>();
14311440

14321441
protected ContinuousStats() { }
14331442

14341443
public void enableMeasurements() {
14351444
enabled = true;
14361445
}
14371446

1447+
public void disableMeasurements() {
1448+
enabled = false;
1449+
}
1450+
14381451
public List<Integer> getNodesStats() {
1439-
if (contUsedBddNodes.size() != contUsedOperations.size()) {
1452+
if (contUsedBddNodes.size() != contOperations.size()) {
14401453
throw new AssertionError("Incorrect data collection.");
14411454
}
14421455
return contUsedBddNodes;
14431456
}
14441457

14451458
public List<Long> getOperationsStats() {
1446-
if (contUsedBddNodes.size() != contUsedOperations.size()) {
1459+
if (contUsedBddNodes.size() != contOperations.size()) {
14471460
throw new AssertionError("Incorrect data collection.");
14481461
}
1449-
return contUsedOperations;
1462+
return contOperations;
14501463
}
14511464
}
14521465

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

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3522,25 +3522,7 @@ int bdd_used_nodes_count() {
35223522
}
35233523

35243524
int bdd_delref(int root) {
3525-
// The number of currently used BDD nodes, between 0 and bddnodesize.
3526-
// -1 indicates that it has not yet been calculated.
3527-
int usedBddNodes = -1;
3528-
3529-
if (maxbddnodesstats.enabled) {
3530-
if (usedBddNodes == -1) usedBddNodes = bdd_used_nodes_count();
3531-
maxbddnodesstats.newMeasurement(usedBddNodes);
3532-
}
3533-
3534-
if (maxmemorystats.enabled) {
3535-
long memory = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
3536-
maxmemorystats.newMeasurement(memory);
3537-
}
3538-
3539-
if (continuousstats.enabled) {
3540-
if (usedBddNodes == -1) usedBddNodes = bdd_used_nodes_count();
3541-
continuousstats.contUsedBddNodes.add(usedBddNodes);
3542-
continuousstats.contUsedOperations.add(cachestats.opMiss);
3543-
}
3525+
bdd_add_per_stats();
35443526

35453527
if (root == INVALID_BDD)
35463528
bdd_error(BDD_BREAK); /* distinctive */
@@ -5069,32 +5051,36 @@ int bdd_reorder_gain() {
50695051
}
50705052

50715053
public void done() {
5054+
bdd_add_per_stats();
5055+
5056+
super.done();
5057+
bdd_done();
5058+
}
5059+
5060+
void bdd_add_per_stats() {
50725061
// The number of currently used BDD nodes, between 0 and bddnodesize.
50735062
// -1 indicates that it has not yet been calculated.
50745063
int usedBddNodes = -1;
50755064

5076-
if (maxbddnodesstats.enabled) {
5065+
if (maxusedbddnodesstats.enabled) {
50775066
if (usedBddNodes == -1) usedBddNodes = bdd_used_nodes_count();
5078-
maxbddnodesstats.newMeasurement(usedBddNodes);
5067+
maxusedbddnodesstats.newMeasurement(usedBddNodes);
50795068
}
50805069

5081-
if (maxmemorystats.enabled) {
5070+
if (maxusedmemorystats.enabled) {
50825071
long memory = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
5083-
maxmemorystats.newMeasurement(memory);
5084-
System.gc(); // To make sure subsequent memory measurements are accurate.
5072+
maxusedmemorystats.newMeasurement(memory);
50855073
}
5086-
5074+
50875075
if (continuousstats.enabled) {
50885076
if (usedBddNodes == -1) usedBddNodes = bdd_used_nodes_count();
50895077
continuousstats.contUsedBddNodes.add(usedBddNodes);
5090-
continuousstats.contUsedOperations.add(cachestats.opMiss);
5078+
// cachestats.opMiss is the number of BDD operations performed until now that could not
5079+
// be taken from the cache. Thus it approximates time.
5080+
continuousstats.contOperations.add(cachestats.opMiss);
50915081
}
5092-
5093-
super.done();
5094-
bdd_done();
50955082
}
50965083

5097-
50985084
void bdd_done() {
50995085
/*sanitycheck(); FIXME */
51005086
//bdd_fdd_done();

0 commit comments

Comments
 (0)