logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ceki Gülcü <c...@qos.ch>
Subject Re: LocationInfo performance, StackTraceElement
Date Mon, 17 May 2004 07:53:56 GMT

Hello Martin,

Thanks for the code. What kind of improvement are we talking about? Do you 
have figures by any chance?

We should use the Throwable.getStackTrace() method when running with JDK 
1.4 and later. Doing this while keeping *compile* time compatibility with 
JDK 1.2 is a little tricky but feasible.

I am really interested to look at figures comparing the current approach 
and the one using JDK 1.4.


At 08:47 PM 5/16/2004, you wrote:
>I have been profiling log4j a little bit and found that LocationInfo (if 
>used in the pattern) is a particular
>bottleneck.  I find it amazing that nobody seems to have suggested yet to 
>use Throwable.getStackTrace()
>instead of parsing the output of the printout. (as of JDK 1.4).
>
>In fact, since this was a very simple excercise, I have just finished the 
>implementation and found it a huge
>speed and memory improvement over the current state.
>
>Of course, if backwards compatibility is a goal (haven't found a statement 
>in that respect),  this code
>would have to be merged with the existing code line, avoiding using any 
>unavailable features.
>
>I have attached the class for review etc.  If that is stripped off or 
>bounces, just let me know where to
>put it.
>
>And yes, just for those who really want to know, it is still a relatively 
>expensive piece of information to get at.
>
>Thanks!
>
>Martin
>
>
>
>/*
>  * Copyright (C) The Apache Software Foundation. All rights reserved.
>  *
>  * This software is published under the terms of the Apache Software
>  * License version 1.1, a copy of which has been included with this
>  * distribution in the LICENSE.txt file.  */
>
>// Contributors: Mathias Rupprecht <mmathias.rupprecht@fja.com>
>
>package org.apache.log4j.spi;
>
>import org.apache.log4j.helpers.LogLog;
>import org.apache.log4j.Layout;
>
>/**
>    The internal representation of caller location information.
>
>    @since 0.8.3
>*/
>public class LocationInfo implements java.io.Serializable {
>
>   public StackTraceElement location;
>
>   /**
>      When location information is not available the constant
>      <code>NA</code> is returned. Current value of this string
>      constant is <b>?</b>.  */
>   public final static String NA = "?";
>
>   static final long serialVersionUID = -1325822038990805636L;
>
>   /**
>      Instantiate location information based on a Throwable.
>      We use the StackTraceElement class available since 1.4
>     */
>
>     public LocationInfo(Throwable t, String fqnOfCallingClass) {
>       if(t == null)
>         return;
>
>       StackTraceElement[] stes = t.getStackTrace();
>
>       for ( int i = 0; i<stes.length-1; i++) {
>         StackTraceElement ste = stes[i];
>         if ( ste.getClassName().equals(fqnOfCallingClass) ) {
>             // there are several nested calls from fqnOfCallingClass to 
> fqnOfCallingClass.
>             i++;
>             for ( ; i<stes.length-1; i++) {
>                 ste = stes[i];
>                 if ( !ste.getClassName().equals(fqnOfCallingClass) ) {
>                     this.location = ste;
>                     return;
>                 }
>             }
>         }
>       }
>     }
>
>     /**
>        Return the fully qualified class name of the caller making the
>        logging request.
>     */
>     public
>     String getClassName() {
>         return location == null ? NA : location.getClassName();
>     }
>
>     /**
>        Return the file name of the caller.
>
>        <p>This information is not always available.
>     */
>     public
>     String getFileName() {
>         return location == null ? NA : location.getFileName();
>     }
>
>     /**
>        Returns the line number of the caller.
>
>        <p>This information is not always available.
>     */
>     public
>     String getLineNumber() {
>         if ( location == null )
>           return NA;
>         int ln = location.getLineNumber();
>         return ln < 0 ? NA:Integer.toString(ln);
>     }
>
>     /**
>        Returns the method name of the caller.
>     */
>     public
>     String getMethodName() {
>         return location == null ? NA : location.getMethodName();
>     }
>}
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
>For additional commands, e-mail: log4j-dev-help@logging.apache.org

-- 
Ceki Gülcü

      For log4j documentation consider "The complete log4j manual"
      ISBN: 2970036908 http://www.qos.ch/shop/products/clm_t.jsp  



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Mime
View raw message