KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > objectserver > impl > GCLogger


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.objectserver.impl;
5
6 import com.tc.logging.TCLogger;
7 import com.tc.objectserver.api.GCStats;
8 import com.tc.stats.LossyStack;
9
10 import java.util.List JavaDoc;
11 import java.util.Set JavaDoc;
12
13 public class GCLogger {
14   private TCLogger logger;
15   private final LossyStack gcHistory = new LossyStack(1000);
16   private final boolean verboseGC;
17
18   public GCLogger(TCLogger logger, boolean verboseGC) {
19     this.logger = logger;
20     this.verboseGC = verboseGC;
21   }
22
23   public void push(Object JavaDoc obj) {
24     gcHistory.push(obj);
25   }
26
27   public GCStats[] getGarbageCollectorStats() {
28     return (GCStats[]) gcHistory.toArray(new GCStats[gcHistory.depth()]);
29   }
30
31   public void log_GCStart(long iteration) {
32     if (verboseGC()) logGC("GC: START " + iteration);
33   }
34
35   public void log_markStart(Set JavaDoc managedIdSet) {
36     if (verboseGC()) logGC("GC: pre-GC managed id count: " + managedIdSet.size());
37   }
38
39   public void log_markResults(Set JavaDoc gcResults) {
40     if (verboseGC()) logGC("GC: pre-rescue GC results: " + gcResults.size());
41   }
42
43   public void log_quiescing() {
44     if (verboseGC()) logGC("GC: quiescing...");
45   }
46
47   public void log_paused() {
48     if (verboseGC()) logGC("GC: paused.");
49   }
50
51   public void log_rescue(int pass, Set JavaDoc objectIDs) {
52     if (verboseGC()) logGC("GC: rescue pass " + pass + " on " + objectIDs.size() + " objects...");
53   }
54
55   public void log_sweep(Set JavaDoc toDelete) {
56     if (verboseGC()) logGC("GC: deleting garbage: " + toDelete.size() + " objects");
57   }
58
59   public void log_notifyGCComplete() {
60     if (verboseGC()) logGC("GC: notifying gc complete...");
61   }
62
63   public void log_GCComplete(long startMillis, long pauseStartMillis, List JavaDoc rescueTimes, long endMillis, long iteration) {
64     if (verboseGC()) {
65       long pausedMillis = endMillis - pauseStartMillis;
66       long totalMillis = endMillis - startMillis;
67       for (int i = 0; i < rescueTimes.size(); i++) {
68         logGC("GC: rescue " + (i + 1) + " time : " + rescueTimes.get(i) + " ms.");
69       }
70       logGC("GC: paused gc time : " + pausedMillis + " ms.");
71       logGC("GC: total gc time : " + totalMillis + " ms.");
72       logGC("GC: STOP " + iteration);
73     }
74   }
75
76   public boolean verboseGC() {
77     return verboseGC;
78   }
79
80   private void logGC(Object JavaDoc o) {
81     if (verboseGC) {
82       logger.info(o);
83     }
84   }
85 }
86
Popular Tags