MCPcopy Create free account
hub / github.com/LFYSec/MScan / onFinish

Method onFinish

src/main/java/pascal/taie/analysis/pta/plugin/Profiler.java:87–134  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

85 }
86
87 @Override
88 public void onFinish() {
89 File outFile = new File(World.get().getOptions().getOutputDir(), PROFILE_FILE);
90 try (PrintStream out = new PrintStream(new FileOutputStream(outFile))) {
91 logger.info("Dumping pointer analysis profile to {}",
92 outFile.getAbsolutePath());
93 // report variables
94 reportTop(out, "frequently-visited variables",
95 varVisited, v -> v.getMethod() + "/" + v.getName());
96 reportTop(out, "frequently-visited CS variables",
97 csVarVisited, CSVar::toString);
98 // count and report methods
99 Map<JMethod, MutableInt> methodVarVisited = Maps.newMap();
100 varVisited.forEach((v, times) ->
101 methodVarVisited.computeIfAbsent(v.getMethod(),
102 __ -> new MutableInt(0))
103 .add(times.intValue()));
104 reportTop(out, "method containers (of frequently-visited variables)",
105 methodVarVisited, JMethod::toString);
106 Map<CSMethod, MutableInt> csMethodVarVisited = Maps.newMap();
107 csVarVisited.forEach((v, times) -> {
108 CSMethod method = csManager.getCSMethod(
109 v.getContext(), v.getVar().getMethod());
110 csMethodVarVisited.computeIfAbsent(method,
111 __ -> new MutableInt(0))
112 .add(times.intValue());
113 });
114 reportTop(out, "CS method containers (of frequently-visited CS variables)",
115 csMethodVarVisited, CSMethod::toString);
116 // count and report classes
117 Map<JClass, MutableInt> classVarVisited = Maps.newMap();
118 methodVarVisited.forEach((m, times) ->
119 classVarVisited.computeIfAbsent(m.getDeclaringClass(),
120 __ -> new MutableInt(0))
121 .add(times.intValue()));
122 reportTop(out, "class containers (of frequently-visited variables)",
123 classVarVisited, JClass::toString);
124 // count and report points-to sets counter
125 PointerAnalysisResult ptaResult = solver.getResult();
126 reportPtsTop(out, "points-to set of variables", ptaResult.getCSVars());
127 reportPtsTop(out, "points-to set of static fields", ptaResult.getStaticFields());
128 reportPtsTop(out, "points-to set of instance fields", ptaResult.getInstanceFields());
129 reportPtsTop(out, "points-to set of array indexes", ptaResult.getArrayIndexes());
130 } catch (FileNotFoundException e) {
131 logger.warn("Failed to write pointer analysis profile to {}, caused by {}",
132 outFile.getAbsolutePath(), e);
133 }
134 }
135
136 private static void reportPtsTop(
137 PrintStream out, String desc, Collection<? extends Pointer> pointers) {

Callers

nothing calls this directly

Calls 15

getMethod · 0.95
reportTopMethod · 0.95
newMapMethod · 0.95
reportPtsTopMethod · 0.95
getCSVarsMethod · 0.95
getStaticFieldsMethod · 0.95
getInstanceFieldsMethod · 0.95
getArrayIndexesMethod · 0.95
getOutputDirMethod · 0.80
computeIfAbsentMethod · 0.80
intValueMethod · 0.80
getOptionsMethod · 0.65

Tested by

no test coverage detected