added some code for debugging memory issue

This commit is contained in:
Eric J. Bowersox 2004-05-02 23:42:18 +00:00
parent 7008993545
commit 4550100675
3 changed files with 51 additions and 8 deletions

View File

@ -30,6 +30,14 @@
</layout> </layout>
</appender> </appender>
<!-- Define the memory logging appender. -->
<appender name="MEM" class="org.apache.log4j.FileAppender">
<param name="File" value="/home/erbo/venice.memory.log"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d [%x] - %m%n"/>
</layout>
</appender>
<!-- Turn down the standard detail in some areas --> <!-- Turn down the standard detail in some areas -->
<category name="com.silverwrist.util.ServletMultipartHandler"> <category name="com.silverwrist.util.ServletMultipartHandler">
<priority value="debug"/> <priority value="debug"/>
@ -38,6 +46,11 @@
<priority value="fatal"/> <priority value="fatal"/>
</category> </category>
<category name="MEMLOG" additivity="false">
<priority value="info"/>
<appender-ref ref="MEM"/>
</category>
<!-- Define the root configuration for logging. --> <!-- Define the root configuration for logging. -->
<root> <root>
<priority value="debug"/> <priority value="debug"/>
@ -45,7 +58,3 @@
</root> </root>
</log4j:configuration> </log4j:configuration>

View File

@ -11,7 +11,7 @@
* *
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>, * The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
* Copyright (C) 2001-02 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. * Copyright (C) 2001-04 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
* *
* Contributor(s): * Contributor(s):
*/ */
@ -79,7 +79,8 @@ public abstract class BaseServlet extends HttpServlet
private static final String ENGINE_INIT_PARAM = "venice.config"; private static final String ENGINE_INIT_PARAM = "venice.config";
private static final String UICONFIG_INIT_PARAM = "ui.config"; private static final String UICONFIG_INIT_PARAM = "ui.config";
private static Category logger = Category.getInstance(BaseServlet.class); private static Logger logger = Logger.getLogger(BaseServlet.class);
private static Logger memlog = Logger.getLogger("MEMLOG");
private static VeniceUISessionFactory factory = new HttpSessionFactory(); private static VeniceUISessionFactory factory = new HttpSessionFactory();
@ -127,6 +128,7 @@ public abstract class BaseServlet extends HttpServlet
} // end catch } // end catch
String str_request = the_request.toString();
String default_location = the_request.getLocation(); String default_location = the_request.getLocation();
// log the username with all log messages, if the user is logged in // log the username with all log messages, if the user is logged in
@ -173,12 +175,19 @@ public abstract class BaseServlet extends HttpServlet
{ // filter out RuntimeExceptions and rethrow them { // filter out RuntimeExceptions and rethrow them
logger.error("BaseServlet caught runtime exception" + e.getClass().getName() logger.error("BaseServlet caught runtime exception" + e.getClass().getName()
+ " in commonProcess",e); + " in commonProcess",e);
throw (RuntimeException)e; throw new ServletException(e);
} // end if } // end if
my_output = translateException(the_request,e); my_output = translateException(the_request,e);
} // end catch
catch (VirtualMachineError e)
{ // OutOfMemoryError and similar come here...
System.gc(); // garbage collect so we have enough space to handle the error
logger.error("Virtual machine failure " + e.getClass().getName() + " in commonProcess",e);
throw new ServletException(e);
} // end catch } // end catch
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
@ -198,6 +207,13 @@ public abstract class BaseServlet extends HttpServlet
the_request.outputRaw(my_output.toString()); the_request.outputRaw(my_output.toString());
} // end try } // end try
catch (VirtualMachineError e)
{ // OutOfMemoryError and similar come here...
System.gc(); // garbage collect so we have enough space to handle the error
logger.error("Virtual machine failure " + e.getClass().getName() + " in commonProcess(2)",e);
throw new ServletException(e);
} // end catch
finally finally
{ // end the request { // end the request
the_request.end(); the_request.end();
@ -206,7 +222,12 @@ public abstract class BaseServlet extends HttpServlet
} // end try } // end try
finally finally
{ // make sure and pop the diagnostic context, if it was pushed { // log memory usage
Runtime r = Runtime.getRuntime();
memlog.info("After: " + str_request + " Cur: " + r.totalMemory() + " Max: " + r.maxMemory() + " Free: "
+ r.freeMemory());
// make sure and pop the diagnostic context, if it was pushed
if (record_user) if (record_user)
NDC.pop(); NDC.pop();

View File

@ -756,6 +756,19 @@ public class RequestImpl implements RequestInput
} // end expandServletPath } // end expandServletPath
/*--------------------------------------------------------------------------------
* Overrides from class Object
*--------------------------------------------------------------------------------
*/
public String toString()
{
StringBuffer buf = new StringBuffer("{RequestImpl from [");
buf.append(request.getRemoteAddr()).append("] for ").append(request.getServletPath()).append("}");
return buf.toString();
} // end toString
/*-------------------------------------------------------------------------------- /*--------------------------------------------------------------------------------
* Implementations from interface ServiceProvider * Implementations from interface ServiceProvider
*-------------------------------------------------------------------------------- *--------------------------------------------------------------------------------