You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Ralph Einfeldt <ra...@uptime-isc.de> on 2001/02/15 11:15:19 UTC

AW: Monitor memory and CPU usage of servlets from inside of Tomca t

One easy way to achieve the memory part:

We use our own logging and have build in something like
the following in the log method:

// snip
    boolean oWatchMemory = false;
    Runtime oRuntime = Runtime.getRuntime();
    int oGCCount = 0;
    int oGCInterval = 100;
// snip
void log(....) {
  if (oWatchMemory) {
    if ((oGCInterval > 0) && (oGCCount >= oGCInterval)) {
      mBuffer.append("gc#");
      System.gc();
      oGCCount = 0;
    }
    oGCCount++;
    mBuffer.append("used#" + 
                            (oRuntime.totalMemory() - 
                             oRuntime.freeMemory()) +
                             "total#" + oRuntime.totalMemory() +
                             "#free#" + oRuntime.freeMemory()+ "#");
// snip
  }
// snip
}	

It's nothing compared against a good memory profiler, 
but is cheap and easy to use.

I don't know any free profilers for java. (Haven't searched much)

> -----Ursprungliche Nachricht-----
> Von: Emil Genov [mailto:egenov@simplesoft.bg]
> Gesendet: Donnerstag, 15. Februar 2001 11:43
> An: tomcat-user@jakarta.apache.org; egenov@simplsoft.bg
> Betreff: Monitor memory and CPU usage of servlets from inside 
> of Tomcat
<snip/>
> I need to monitor memory usage
<snap/>