Debian Codegraph @

net/sf/saxon/trace/Instrumentation.java

raw symbols SCIP
1 package net.sf.saxon.trace;
2
3 import net.sf.saxon.trans.CommandLineOptions;
4
5 import java.util.HashMap;
6 import java.util.Map;
7
8 /**
9 * Internal class used for instrumentation purposes. It maintains a number of counters and displays these at the
10 * end of the run. Currently implemented only for the Transform command line, with -t option set.
11 */
12
13 public class Instrumentation {
14
15 public static final boolean ACTIVE = false;
16
17 public static HashMap<String, Integer> counters = new HashMap<>();
18
19 public static void count(String counter) {
20 if (counters.containsKey(counter)) {
21 counters.put(counter, counters.get(counter) + 1);
22 } else {
23 counters.put(counter, 1);
24 }
25 }
26
27 public static void count(String counter, int increment) {
28 if (counters.containsKey(counter)) {
29 counters.put(counter, counters.get(counter) + increment);
30 } else {
31 counters.put(counter, increment);
32 }
33 }
34
35 public static void report() {
36 if (ACTIVE && !counters.isEmpty()) {
37 System.err.println("COUNTERS");
38 for (Map.Entry<String, Integer> c : counters.entrySet()) {
39 System.err.println(c.getKey() + " = " + c.getValue());
40 }
41 }
42 }
43
44 public static void freeMemory(String label) {
45 System.err.println(label+" "+CommandLineOptions.showMemoryUsed());
46
47 }
48
49 public static void reset() {
50 counters.clear();
51 }
52
53 }
54