-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Mark,

On 3/3/20 09:36, ma...@apache.org wrote:
> This is an automated email from the ASF dual-hosted git
> repository.
>
> markt pushed a commit to branch master in repository
> https://gitbox.apache.org/repos/asf/tomcat.git
>
>
> The following commit(s) were added to refs/heads/master by this
> push: new 4ad0a71  BZ 64190 Add 'proper' ms support to
> OneLineFormatter. 4ad0a71 is described below
>
> commit 4ad0a71bc11de50e0fe23fc38e6e67f134aa0589 Author: Mark Thomas
> <ma...@apache.org> AuthorDate: Tue Mar 3 14:36:08 2020 +0000
>
> BZ 64190 Add 'proper' ms support to OneLineFormatter.
>
> S SS or SSS can now be used (once) anywhere in the format String.
> Format strings without S SS or SSS are now ~30% faster The current
> default (effectively "dd-MMM-yyyy HH:mm:ss.SSS") is within less
> than 1% of the old implementation. Using S SS or SSS anywhere but
> the very end doubles the time taken to generate the timestamp. ---
> java/org/apache/juli/OneLineFormatter.java         | 77
> +++++++++++++++++++---
> .../TestOneLineFormatterMillisPerformance.java     | 70
> ++++++++++++++++++++ webapps/docs/changelog.xml
> |  5 ++ 3 files changed, 142 insertions(+), 10 deletions(-)
>
> diff --git a/java/org/apache/juli/OneLineFormatter.java
> b/java/org/apache/juli/OneLineFormatter.java index 75845cf..fad37b0
> 100644 --- a/java/org/apache/juli/OneLineFormatter.java +++
> b/java/org/apache/juli/OneLineFormatter.java @@ -51,7 +51,7 @@
> public class OneLineFormatter extends Formatter { };
>
> /* Timestamp format */ -    private static final String
> DEFAULT_TIME_FORMAT = "dd-MMM-yyyy HH:mm:ss"; +    private static
> final String DEFAULT_TIME_FORMAT = "dd-MMM-yyyy HH:mm:ss.SSS"; /**
> * The size of our global date format cache @@ -68,6 +68,8 @@ public
> class OneLineFormatter extends Formatter { */ private
> ThreadLocal<DateFormatCache> localDateCache;
>
> +    private volatile MillisHandling millisHandling =
> MillisHandling.APPEND; +
>
> public OneLineFormatter() { String timeFormat =
> LogManager.getLogManager().getProperty( @@ -86,12 +88,31 @@ public
> class OneLineFormatter extends Formatter { *
> {@link java.text.SimpleDateFormat} syntax */ public void
> setTimeFormat(final String timeFormat) { +        final String
> cachedTimeFormat; + +        if (timeFormat.endsWith(".SSS")) { +
> cachedTimeFormat = timeFormat.substring(0,  timeFormat.length() -
> 4); +            millisHandling = MillisHandling.APPEND; +        }
> else if (timeFormat.contains("SSS")) { +            millisHandling
> = MillisHandling.REPLACE_SSS; +            cachedTimeFormat =
> timeFormat; +        } else if (timeFormat.contains("SS")) { +
> millisHandling = MillisHandling.REPLACE_SS; +
> cachedTimeFormat = timeFormat; +        } else if
> (timeFormat.contains("S")) { +            millisHandling =
> MillisHandling.REPLACE_S; +            cachedTimeFormat =
> timeFormat; +        } else { +            millisHandling =
> MillisHandling.NONE; +            cachedTimeFormat = timeFormat; +
> } + final DateFormatCache globalDateCache = -                new
> DateFormatCache(globalCacheSize, timeFormat, null); +
> new DateFormatCache(globalCacheSize, cachedTimeFormat, null);
> localDateCache = new ThreadLocal<DateFormatCache>() { @Override
> protected DateFormatCache initialValue() { -                return
> new DateFormatCache(localCacheSize, timeFormat, globalDateCache); +
> return new DateFormatCache(localCacheSize, cachedTimeFormat,
> globalDateCache); } }; } @@ -156,18 +177,45 @@ public class
> OneLineFormatter extends Formatter { }
>
> protected void addTimestamp(StringBuilder buf, long timestamp) { -
> buf.append(localDateCache.get().getFormat(timestamp)); -
> long frac = timestamp % 1000; -        buf.append('.'); -        if
> (frac < 100) { -            if (frac < 10) { +        String
> cachedTimeStamp = localDateCache.get().getFormat(timestamp); +
> if (millisHandling == MillisHandling.NONE) { +
> buf.append(cachedTimeStamp); +        } else if (millisHandling ==
> MillisHandling.APPEND) { +            buf.append(cachedTimeStamp);
> +            long frac = timestamp % 1000; +
> buf.append('.'); +            if (frac < 100) { +                if
> (frac < 10) { +                    buf.append('0'); +
> buf.append('0'); +                } else { +
> buf.append('0'); +                } +            } +
> buf.append(frac); +        } else { +            // Some version of
> replace +            long frac = timestamp % 1000; +            //
> Formatted string may vary in length so the insert point may vary +
> int insertStart = cachedTimeStamp.indexOf('#');

Should the literal '#' be the DateFormatCache.msecPattern constant
instead? It's unlikely to change, but it's slightly less "magic
character"-ish if you reference the constant.

- -chris
-----BEGIN PGP SIGNATURE-----
Comment: Using GnuPG with Thunderbird - https://www.enigmail.net/

iQIyBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAl5f5RQACgkQHPApP6U8
pFh7tg/1GQOhbIMta5RdMwrNVuF6W+HuXDJsTWPg8gk+qkAHhy/aTtJT6MwTAhVs
wuJk12LkNLjP8PNDAyOXtkSZNQPH3Qjt3z+d5gtW0wSIqpluHKPwDCsbLv7ZobMr
mEUcwcH17h0IGNm2OC0qIU9i3MQ1NMf4/myuqMaW7nheukwYEQTxclNJCuJA98cM
ZK3sgsVTue07XZgtmaf7FO+PwQoQwbzkA5abht4Ia6mAgyeHEZpjXxWaV+Q+a/pf
pUhpYHGkEg2TfJqEaw56vt9lwnSR+yKFKb3p1NoItlSJGJRhh+/CH35bRPzUi6lF
b6W5A9Q5D8azOQ7u64d31nCUuxVZm3X4gktZaZl0wwGo6cn5xieAHUllIOSmMZ1A
17DR7vsVZBRgk/ieh9kW1jlW1FSzdCT0phkLNk1dYDmf8n16PHJTQw/MgX8Ziwzz
YIeA7LBFys8+frOHLwH5YMyqaZDMpciikDAOP+j5+NHOqMBzJ9nsNIkYbVk5riPu
XBSB927xpEkN1/ir1yIRyrCU+4ctCytQXEkzbEflL2pdXu2e9+sKewpEsaKlN8eN
9XHZe4cReSHbEvZYJNXoZH4EEo2TXYExcxDepMX5RKvGe5mQzxYT7aWnYnb/et0/
CtCihP25QArKO6661RG8YFpzlvBcdLhTQX/WouTNAyF4JiseFg==
=MhoK
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to