Skip to content

Commit 7a22d51

Browse files
committed
Add statistics for stream instances during typestate analysis.
1 parent e36a5d3 commit 7a22d51

File tree

4 files changed

+94
-7
lines changed

4 files changed

+94
-7
lines changed

edu.cuny.hunter.streamrefactoring.core/src/edu/cuny/hunter/streamrefactoring/core/analysis/StreamAnalyzer.java

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.eclipse.jdt.internal.corext.util.JdtFlags;
3030

3131
import com.ibm.safe.internal.exceptions.PropertiesException;
32+
import com.ibm.safe.rules.TypestateRule;
3233
import com.ibm.wala.ipa.callgraph.AnalysisOptions;
3334
import com.ibm.wala.ipa.callgraph.AnalysisOptions.ReflectionOptions;
3435
import com.ibm.wala.ipa.callgraph.CallGraph;
@@ -42,6 +43,7 @@
4243
import com.ibm.wala.util.CancelException;
4344
import com.ibm.wala.util.scope.JUnitEntryPoints;
4445

46+
import edu.cuny.hunter.streamrefactoring.core.analysis.StreamStateMachine.Statistics;
4547
import edu.cuny.hunter.streamrefactoring.core.utils.LoggerNames;
4648
import edu.cuny.hunter.streamrefactoring.core.utils.TimeCollector;
4749
import edu.cuny.hunter.streamrefactoring.core.wala.EclipseProjectAnalysisEngine;
@@ -81,6 +83,10 @@ private static void addImplicitEntryPoints(Collection<Entrypoint> target, Iterab
8183
*/
8284
private int nForStreams = N_FOR_STREAMS_DEFAULT;
8385

86+
private int numberOfProcessedStreamInstances;
87+
88+
private int numberOfSkippedStreamInstances;
89+
8490
public StreamAnalyzer() {
8591
this(false);
8692
}
@@ -208,8 +214,16 @@ public Map<IJavaProject, Collection<Entrypoint>> analyze(Optional<TimeCollector>
208214
// start the state machine for each valid stream in the project.
209215
StreamStateMachine stateMachine = new StreamStateMachine();
210216
try {
211-
stateMachine.start(projectToStreams.get(project).parallelStream().filter(s -> s.getStatus().isOK())
212-
.collect(Collectors.toSet()), engine, orderingInference);
217+
Map<TypestateRule, StreamStateMachine.Statistics> ruleToStats = stateMachine.start(projectToStreams
218+
.get(project).parallelStream().filter(s -> s.getStatus().isOK()).collect(Collectors.toSet()),
219+
engine, orderingInference);
220+
221+
// use just one the rules.
222+
assert !ruleToStats.isEmpty() : "Should have stats available.";
223+
Statistics statistics = ruleToStats.values().iterator().next();
224+
225+
this.setNumberOfProcessedStreamInstances(statistics.getNumberOfStreamInstancesProcessed());
226+
this.setNumberOfSkippedStreamInstances(statistics.getNumberOfStreamInstancesSkipped());
213227
} catch (PropertiesException | CancelException | NoniterableException | NoninstantiableException
214228
| CannotExtractSpliteratorException | InvalidClassFileException | IOException e) {
215229
LOGGER.log(Level.SEVERE, "Error while starting state machine.", e);
@@ -221,7 +235,6 @@ public Map<IJavaProject, Collection<Entrypoint>> analyze(Optional<TimeCollector>
221235
.collect(Collectors.toSet()))
222236
stream.check();
223237
} // end for each stream.
224-
225238
return ret;
226239
}
227240

@@ -435,4 +448,20 @@ public int getNForStreams() {
435448
protected void setNForStreams(int nForStreams) {
436449
this.nForStreams = nForStreams;
437450
}
451+
452+
public int getNumberOfProcessedStreamInstances() {
453+
return this.numberOfProcessedStreamInstances;
454+
}
455+
456+
protected void setNumberOfProcessedStreamInstances(int numberOfProcessedStreamInstances) {
457+
this.numberOfProcessedStreamInstances = numberOfProcessedStreamInstances;
458+
}
459+
460+
public int getNumberOfSkippedStreamInstances() {
461+
return this.numberOfSkippedStreamInstances;
462+
}
463+
464+
protected void setNumberOfSkippedStreamInstances(int numberOfSkippedStreamInstances) {
465+
this.numberOfSkippedStreamInstances = numberOfSkippedStreamInstances;
466+
}
438467
}

edu.cuny.hunter.streamrefactoring.core/src/edu/cuny/hunter/streamrefactoring/core/analysis/StreamStateMachine.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
import com.ibm.wala.util.intset.OrdinalSet;
8282
import com.ibm.wala.util.strings.Atom;
8383

84+
import edu.cuny.hunter.streamrefactoring.core.analysis.StreamStateMachine.Statistics;
8485
import edu.cuny.hunter.streamrefactoring.core.safe.ModifiedBenignOracle;
8586
import edu.cuny.hunter.streamrefactoring.core.safe.NoApplicationCodeExistsInCallStringsException;
8687
import edu.cuny.hunter.streamrefactoring.core.safe.TypestateSolverFactory;
@@ -90,6 +91,25 @@
9091

9192
public class StreamStateMachine {
9293

94+
public class Statistics {
95+
private int numberOfStreamInstancesProcessed;
96+
private int numberOfStreamInstancesSkipped;
97+
98+
public Statistics(int numberOfStreamInstancesProcessed, int numberOfStreamInstancesSkipped) {
99+
this.numberOfStreamInstancesProcessed = numberOfStreamInstancesProcessed;
100+
this.numberOfStreamInstancesSkipped = numberOfStreamInstancesSkipped;
101+
}
102+
103+
public int getNumberOfStreamInstancesProcessed() {
104+
return numberOfStreamInstancesProcessed;
105+
}
106+
107+
public int getNumberOfStreamInstancesSkipped() {
108+
return numberOfStreamInstancesSkipped;
109+
}
110+
}
111+
112+
@SuppressWarnings("unused")
93113
private static final String ARRAYS_STREAM_CREATION_METHOD_NAME = "Arrays.stream";
94114

95115
private static final Logger LOGGER = Logger.getLogger(LoggerNames.LOGGER_NAME);
@@ -926,10 +946,12 @@ private void propagateStreamInstanceProperty(Collection<InstanceKey> streamInsta
926946
.flatMap(ik -> this.getAllPredecessors(ik).stream()).collect(Collectors.toSet()));
927947
}
928948

929-
public void start(Set<Stream> streamSet, EclipseProjectAnalysisEngine<InstanceKey> engine,
949+
public Map<TypestateRule, Statistics> start(Set<Stream> streamSet, EclipseProjectAnalysisEngine<InstanceKey> engine,
930950
OrderingInference orderingInference)
931951
throws PropertiesException, CancelException, IOException, CoreException, NoniterableException,
932952
NoninstantiableException, CannotExtractSpliteratorException, InvalidClassFileException {
953+
Map<TypestateRule, Statistics> ret = new HashMap<>();
954+
933955
BenignOracle ora = new ModifiedBenignOracle(engine.getCallGraph(), engine.getPointerAnalysis());
934956

935957
PropertiesManager manager = PropertiesManager.initFromMap(Collections.emptyMap());
@@ -962,6 +984,11 @@ public void start(Set<Stream> streamSet, EclipseProjectAnalysisEngine<InstanceKe
962984
throw new RuntimeException("Exception caught during typestate analysis.", e);
963985
}
964986

987+
// record statistics.
988+
Statistics lastStatistics = ret.put(rule,
989+
new Statistics(result.processedInstancesNum(), result.skippedInstances()));
990+
assert lastStatistics == null : "Reassociating statistics.";
991+
965992
// for each instance in the typestate analysis result.
966993
for (Iterator<InstanceKey> iterator = result.iterateInstances(); iterator.hasNext();) {
967994
// get the instance's key.
@@ -1220,5 +1247,6 @@ public void start(Set<Stream> streamSet, EclipseProjectAnalysisEngine<InstanceKe
12201247
this.instancesWhoseReduceOrderingPossiblyMatters.contains(streamInstanceKey));
12211248
}
12221249
}
1250+
return ret;
12231251
}
12241252
}

edu.cuny.hunter.streamrefactoring.core/src/edu/cuny/hunter/streamrefactoring/core/refactorings/ConvertToParallelStreamRefactoringProcessor.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ public static void setLoggingLevel(int level) {
146146

147147
private int nForStreams = N_FOR_STREAMS_DEFAULT;
148148

149+
private int numberOfProcessedStreamInstances;
150+
151+
private int numberOfSkippedStreamInstances;
152+
149153
public ConvertToParallelStreamRefactoringProcessor() throws JavaModelException {
150154
this(null, null, false, true, false, false, Optional.empty());
151155
}
@@ -242,6 +246,10 @@ public RefactoringStatus checkFinalConditions(final IProgressMonitor monitor, fi
242246
// analyze and set entry points.
243247
this.projectToEntryPoints = analyzer.analyze(Optional.of(this.getExcludedTimeCollector()));
244248

249+
// set statistics for stream instances.
250+
this.setNumberOfProcessedStreamInstances(analyzer.getNumberOfProcessedStreamInstances());
251+
this.setNumberOfSkippedStreamInstances(analyzer.getNumberOfSkippedStreamInstances());
252+
245253
// map empty set to unprocessed projects.
246254
for (IJavaProject project : this.getJavaProjects())
247255
this.projectToEntryPoints.computeIfAbsent(project, p -> Collections.emptySet());
@@ -530,4 +538,20 @@ private void manageCompilationUnit(final TextEditBasedChangeManager manager, Com
530538
protected void setStreamSet(Set<Stream> streamSet) {
531539
this.streamSet = streamSet;
532540
}
541+
542+
public int getNumberOfProcessedStreamInstances() {
543+
return this.numberOfProcessedStreamInstances;
544+
}
545+
546+
protected void setNumberOfProcessedStreamInstances(int numberOfProcessedStreamInstances) {
547+
this.numberOfProcessedStreamInstances = numberOfProcessedStreamInstances;
548+
}
549+
550+
public int getNumberOfSkippedStreamInstances() {
551+
return this.numberOfSkippedStreamInstances;
552+
}
553+
554+
protected void setNumberOfSkippedStreamInstances(int numberOfSkippedStreamInstances) {
555+
this.numberOfSkippedStreamInstances = numberOfSkippedStreamInstances;
556+
}
533557
}

edu.cuny.hunter.streamrefactoring.eval/src/edu/cuny/hunter/streamrefactoring/eval/handlers/EvaluateConvertToParallelStreamRefactoringHandler.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,9 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
207207

208208
IJavaProject[] javaProjects = Util.getSelectedJavaProjectsFromEvent(event);
209209

210-
List<String> resultsHeader = new ArrayList<>(
211-
Arrays.asList("subject", "SLOC", "#entrypoints", "N", "#streams",
212-
"#optimization available streams", "#optimizable streams", "#failed preconditions"));
210+
List<String> resultsHeader = new ArrayList<>(Arrays.asList("subject", "SLOC", "#entrypoints", "N",
211+
"#streams", "#optimization available streams", "#optimizable streams", "#failed preconditions",
212+
"stream instances processed", "stream instances skipped"));
213213

214214
for (Refactoring refactoring : Refactoring.values())
215215
resultsHeader.add(refactoring.toString());
@@ -402,6 +402,12 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
402402
entry.getCode(), entry.getMessage());
403403
}
404404

405+
// #stream instances analyzed.
406+
resultsPrinter.print(processor.getNumberOfProcessedStreamInstances());
407+
408+
// #stream instances skipped.
409+
resultsPrinter.print(processor.getNumberOfSkippedStreamInstances());
410+
405411
// Refactoring type counts.
406412
for (Refactoring refactoring : Refactoring.values())
407413
resultsPrinter.print(processor.getStreamSet().parallelStream().map(Stream::getRefactoring)

0 commit comments

Comments
 (0)