001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
003: */
004: package com.tc.objectserver.impl;
005:
006: import com.tc.logging.TCLogger;
007: import com.tc.objectserver.api.GCStats;
008: import com.tc.stats.LossyStack;
009:
010: import java.util.List;
011: import java.util.Set;
012:
013: public class GCLogger {
014: private TCLogger logger;
015: private final LossyStack gcHistory = new LossyStack(1000);
016: private final boolean verboseGC;
017:
018: public GCLogger(TCLogger logger, boolean verboseGC) {
019: this .logger = logger;
020: this .verboseGC = verboseGC;
021: }
022:
023: public void push(Object obj) {
024: gcHistory.push(obj);
025: }
026:
027: public GCStats[] getGarbageCollectorStats() {
028: return (GCStats[]) gcHistory.toArray(new GCStats[gcHistory
029: .depth()]);
030: }
031:
032: public void log_GCStart(long iteration) {
033: if (verboseGC())
034: logGC("GC: START " + iteration);
035: }
036:
037: public void log_markStart(Set managedIdSet) {
038: if (verboseGC())
039: logGC("GC: pre-GC managed id count: " + managedIdSet.size());
040: }
041:
042: public void log_markResults(Set gcResults) {
043: if (verboseGC())
044: logGC("GC: pre-rescue GC results: " + gcResults.size());
045: }
046:
047: public void log_quiescing() {
048: if (verboseGC())
049: logGC("GC: quiescing...");
050: }
051:
052: public void log_paused() {
053: if (verboseGC())
054: logGC("GC: paused.");
055: }
056:
057: public void log_rescue(int pass, Set objectIDs) {
058: if (verboseGC())
059: logGC("GC: rescue pass " + pass + " on " + objectIDs.size()
060: + " objects...");
061: }
062:
063: public void log_sweep(Set toDelete) {
064: if (verboseGC())
065: logGC("GC: deleting garbage: " + toDelete.size()
066: + " objects");
067: }
068:
069: public void log_notifyGCComplete() {
070: if (verboseGC())
071: logGC("GC: notifying gc complete...");
072: }
073:
074: public void log_GCDisabled() {
075: if (verboseGC())
076: logGC("GC: Not running gc since its disabled...");
077: }
078:
079: public void log_GCComplete(long startMillis, long pauseStartMillis,
080: List rescueTimes, long endMillis, long iteration) {
081: if (verboseGC()) {
082: long pausedMillis = endMillis - pauseStartMillis;
083: long totalMillis = endMillis - startMillis;
084: for (int i = 0; i < rescueTimes.size(); i++) {
085: logGC("GC: rescue " + (i + 1) + " time : "
086: + rescueTimes.get(i) + " ms.");
087: }
088: logGC("GC: paused gc time : " + pausedMillis + " ms.");
089: logGC("GC: total gc time : " + totalMillis + " ms.");
090: logGC("GC: STOP " + iteration);
091: }
092: }
093:
094: public boolean verboseGC() {
095: return verboseGC;
096: }
097:
098: private void logGC(Object o) {
099: if (verboseGC) {
100: logger.info(o);
101: }
102: }
103: }
|