62
63 /**
64 * A reference to the pulse logger. This will be null if pulse logging
65 * is not enabled.
66 */
67 public static final PulseLogger PULSE_LOGGER = PULSE_LOGGING_ENABLED ? new PulseLogger() : null;
68
69 /**
70 * A time in milliseconds which defines the threshold. If a pulse lasts <em>longer</em> than
71 * the threshold, then it is logged, otherwise an abbreviated representation including
72 * only the time of the pulse is logged.
73 */
74 private static long THRESHOLD = (long)
75 AccessController.doPrivileged(new PrivilegedAction<Integer>() {
76 @Override public Integer run() {
77 return Integer.getInteger("javafx.pulseLogger.threshold", 17);
78 }
79 });
80
81 /**
82 * We have a simple counter that keeps track of the current pulse number.
83 * INTER_PULSE_DATA is used to mark data that comes between pulses.
84 */
85 private int pulseCount = 1;
86 private static final int INTER_PULSE_DATA = -1;
87
88 /**
89 * When printing the truncated form of the pulse, we just print one truncated
90 * form after another, such as:
91 *
92 * [5][2][4]
93 *
94 * This way we don't cause the console to scroll far vertically in the case of fast
95 * pulses. We do this so that relevant information (pulses that exceed the threshold)
96 * is easy to find and remains visible as long as possible in the console. However,
97 * we don't want to scroll too far off to the right either, so we keep track of
98 * how many "quick pulses" have happened in a row. When we've exceeded some fixed
99 * number (20, say) then we will insert a newline into the log.
100 */
101 private volatile int wrapCount = 0;
425 System.err.print(message);
426 if (!counters.isEmpty()) {
427 System.err.println("Counters:");
428 List<Map.Entry<String,Integer>> entries = new ArrayList<Map.Entry<String,Integer>>(counters.entrySet());
429 Collections.sort(entries, new Comparator<Map.Entry<String,Integer>>() {
430 public int compare(Map.Entry<String,Integer> a, Map.Entry<String,Integer> b) {
431 return a.getKey().compareTo(b.getKey());
432 }
433 });
434 for (Map.Entry<String, Integer> entry : entries) {
435 System.err.println("\t" + entry.getKey() + ": " + entry.getValue());
436 }
437 }
438 wrapCount = 0;
439 }
440
441 // Reset the state
442 message.setLength(0);
443 counters.clear();
444 state = AVAILABLE;
445 }
446 }
447 }
|
62
63 /**
64 * A reference to the pulse logger. This will be null if pulse logging
65 * is not enabled.
66 */
67 public static final PulseLogger PULSE_LOGGER = PULSE_LOGGING_ENABLED ? new PulseLogger() : null;
68
69 /**
70 * A time in milliseconds which defines the threshold. If a pulse lasts <em>longer</em> than
71 * the threshold, then it is logged, otherwise an abbreviated representation including
72 * only the time of the pulse is logged.
73 */
74 private static long THRESHOLD = (long)
75 AccessController.doPrivileged(new PrivilegedAction<Integer>() {
76 @Override public Integer run() {
77 return Integer.getInteger("javafx.pulseLogger.threshold", 17);
78 }
79 });
80
81 /**
82 * Optionally exit after a given number of pulses
83 */
84 private static final int EXIT_ON_PULSE =
85 AccessController.doPrivileged(new PrivilegedAction<Integer>() {
86 @Override
87 public Integer run() {
88 return Integer.getInteger("javafx.pulseLogger.exitOnPulse", 0);
89 }
90 });
91
92 /**
93 * We have a simple counter that keeps track of the current pulse number.
94 * INTER_PULSE_DATA is used to mark data that comes between pulses.
95 */
96 private int pulseCount = 1;
97 private static final int INTER_PULSE_DATA = -1;
98
99 /**
100 * When printing the truncated form of the pulse, we just print one truncated
101 * form after another, such as:
102 *
103 * [5][2][4]
104 *
105 * This way we don't cause the console to scroll far vertically in the case of fast
106 * pulses. We do this so that relevant information (pulses that exceed the threshold)
107 * is easy to find and remains visible as long as possible in the console. However,
108 * we don't want to scroll too far off to the right either, so we keep track of
109 * how many "quick pulses" have happened in a row. When we've exceeded some fixed
110 * number (20, say) then we will insert a newline into the log.
111 */
112 private volatile int wrapCount = 0;
436 System.err.print(message);
437 if (!counters.isEmpty()) {
438 System.err.println("Counters:");
439 List<Map.Entry<String,Integer>> entries = new ArrayList<Map.Entry<String,Integer>>(counters.entrySet());
440 Collections.sort(entries, new Comparator<Map.Entry<String,Integer>>() {
441 public int compare(Map.Entry<String,Integer> a, Map.Entry<String,Integer> b) {
442 return a.getKey().compareTo(b.getKey());
443 }
444 });
445 for (Map.Entry<String, Integer> entry : entries) {
446 System.err.println("\t" + entry.getKey() + ": " + entry.getValue());
447 }
448 }
449 wrapCount = 0;
450 }
451
452 // Reset the state
453 message.setLength(0);
454 counters.clear();
455 state = AVAILABLE;
456 if (EXIT_ON_PULSE > 0 && pulseCount >= EXIT_ON_PULSE) {
457 System.err.println("Exiting after pulse #" + pulseCount);
458 System.exit(0);
459 }
460 }
461 }
462 }
|