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

Class Profiler

src/main/java/pascal/taie/analysis/pta/plugin/Profiler.java:56–165  ·  view source on GitHub ↗

Profiler to help identify analysis hot spots in the analyzed program and assist performance tuning for pointer analysis.

Source from the content-addressed store, hash-verified

54 * and assist performance tuning for pointer analysis.
55 */
56public class Profiler implements Plugin {
57
58 private static final Logger logger = LogManager.getLogger(Profiler.class);
59
60 private static final String PROFILE_FILE = "pta-profile.txt";
61
62 /**
63 * Reports the results for top N elements.
64 */
65 private static final int TOP_N = 100;
66
67 private Solver solver;
68
69 private CSManager csManager;
70
71 private final Map<CSVar, MutableInt> csVarVisited = Maps.newMap();
72
73 private final Map<Var, MutableInt> varVisited = Maps.newMap();
74
75 @Override
76 public void setSolver(Solver solver) {
77 this.solver = solver;
78 this.csManager = solver.getCSManager();
79 }
80
81 @Override
82 public void onNewPointsToSet(CSVar csVar, PointsToSet pts) {
83 csVarVisited.computeIfAbsent(csVar, __ -> new MutableInt(0)).add(1);
84 varVisited.computeIfAbsent(csVar.getVar(), __ -> new MutableInt(0)).add(1);
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 });

Callers

nothing calls this directly

Calls 1

newMapMethod · 0.95

Tested by

no test coverage detected