2828import java .util .Collections ;
2929import java .util .List ;
3030import org .apache .logging .log4j .core .async .AsyncLoggerContextSelector ;
31- import org .apache .logging .log4j .core .impl . Log4jPropertyKey ;
31+ import org .apache .logging .log4j .core .util . Integers ;
3232
3333/**
3434 * Runs a sequence of performance tests.
3535 */
3636public class PerfTestDriver {
3737 private static final String DEFAULT_WAIT_STRATEGY = "Block" ;
3838
39- enum WaitStrategy {
39+ static enum WaitStrategy {
4040 Sleep ,
4141 Yield ,
4242 Block ;
@@ -95,17 +95,17 @@ List<String> processArguments(final String java) {
9595 // args.add("-XX:+PrintGCApplicationConcurrentTime");
9696 // args.add("-XX:+PrintSafepointStatistics");
9797
98- args .add ("-D" + Log4jPropertyKey . Constant . CONFIG_V1_FILE_NAME + '=' + log4jConfig ); // 1.2
99- args .add ("-D" + Log4jPropertyKey . Constant . CONFIG_LOCATION + '=' + log4jConfig ); // 2.x
98+ args .add ("-Dlog4j.configuration=" + log4jConfig ); // log4j 1.2
99+ args .add ("-Dlog4j.configurationFile=" + log4jConfig ); // log4j 2
100100 args .add ("-Dlogback.configurationFile=" + log4jConfig ); // logback
101101
102102 final int ringBufferSize = getUserSpecifiedRingBufferSize ();
103103 if (ringBufferSize >= 128 ) {
104- args .add ("-D" + Log4jPropertyKey . Constant . ASYNC_CONFIG_RING_BUFFER_SIZE + '=' + ringBufferSize );
105- args .add ("-D" + Log4jPropertyKey . Constant . ASYNC_LOGGER_RING_BUFFER_SIZE + '=' + ringBufferSize );
104+ args .add ("-DAsyncLoggerConfig.RingBufferSize=" + ringBufferSize );
105+ args .add ("-DAsyncLogger.RingBufferSize=" + ringBufferSize );
106106 }
107- args .add ("-D" + Log4jPropertyKey . Constant . ASYNC_CONFIG_WAIT_STRATEGY + '=' + wait );
108- args .add ("-D" + Log4jPropertyKey . Constant . ASYNC_LOGGER_WAIT_STRATEGY + '=' + wait );
107+ args .add ("-DAsyncLoggerConfig.WaitStrategy=" + wait );
108+ args .add ("-DAsyncLogger.WaitStrategy=" + wait );
109109 if (systemProperties != null ) {
110110 Collections .addAll (args , systemProperties );
111111 }
@@ -121,7 +121,7 @@ List<String> processArguments(final String java) {
121121
122122 private int getUserSpecifiedRingBufferSize () {
123123 try {
124- return Integer .parseInt (System .getProperty ("RingBufferSize" , "-1" ));
124+ return Integers .parseInt (System .getProperty ("RingBufferSize" , "-1" ));
125125 } catch (final Exception ignored ) {
126126 return -1 ;
127127 }
@@ -179,7 +179,7 @@ public Stats(final String raw) {
179179 average += Long .parseLong (parts [i ++].split ("=" )[1 ]);
180180 pct99 += Long .parseLong (parts [i ++].split ("=" )[1 ]);
181181 pct99_99 += Long .parseLong (parts [i ++].split ("=" )[1 ]);
182- count += Integer .parseInt (parts [i ].split ("=" )[1 ]);
182+ count += Integers .parseInt (parts [i ].split ("=" )[1 ]);
183183 } else {
184184 throughputRowCount ++;
185185 final String number = line .substring (0 , line .indexOf (' ' ));
@@ -203,14 +203,14 @@ public String toString() {
203203 }
204204 }
205205
206- enum Runner {
206+ static enum Runner {
207207 Log4j12 (RunLog4j1 .class ), //
208208 Log4j2 (RunLog4j2 .class ), //
209209 Logback (RunLogback .class );
210210
211211 private final Class <? extends IPerfTestRunner > implementationClass ;
212212
213- Runner (final Class <? extends IPerfTestRunner > cls ) {
213+ private Runner (final Class <? extends IPerfTestRunner > cls ) {
214214 this .implementationClass = cls ;
215215 }
216216 }
@@ -232,13 +232,11 @@ private static List<Setup> selectTests() throws IOException {
232232 final List <Setup > tests = new ArrayList <>();
233233
234234 // final String CACHEDCLOCK = "-Dlog4j.Clock=CachedClock";
235- final String SYSCLOCK = asArgument (Log4jPropertyKey .Constant .CONFIG_CLOCK , "SystemClock" );
236- final String ALL_ASYNC = asArgument (
237- Log4jPropertyKey .Constant .CONTEXT_SELECTOR_CLASS_NAME , AsyncLoggerContextSelector .class .getName ());
235+ final String SYSCLOCK = "-Dlog4j.Clock=SystemClock" ;
236+ final String ALL_ASYNC = "-DLog4jContextSelector=" + AsyncLoggerContextSelector .class .getName ();
238237
239- final String THREADNAME = asArgument (
240- Log4jPropertyKey .Constant .ASYNC_LOGGER_THREAD_NAME_STRATEGY ,
241- System .getProperty (Log4jPropertyKey .Constant .ASYNC_LOGGER_THREAD_NAME_STRATEGY , "CACHED" ));
238+ final String THREADNAME = "-DAsyncLogger.ThreadNameStrategy=" //
239+ + System .getProperty ("AsyncLogger.ThreadNameStrategy" , "CACHED" );
242240
243241 // includeLocation=false
244242 add (tests , 1 , "perf3PlainNoLoc.xml" , Runner .Log4j2 , "Loggers all async" , ALL_ASYNC , SYSCLOCK , THREADNAME );
@@ -310,7 +308,7 @@ private static void add(
310308 private static void runPerfTests (final String [] args , final List <Setup > tests )
311309 throws IOException , InterruptedException , FileNotFoundException {
312310 final String java = args .length > 0 ? args [0 ] : "java" ;
313- final int repeat = args .length > 1 ? Integer .parseInt (args [1 ]) : 5 ;
311+ final int repeat = args .length > 1 ? Integers .parseInt (args [1 ]) : 5 ;
314312 int x = 0 ;
315313 for (final Setup setup : tests ) {
316314 System .out .print (setup .description ());
@@ -385,8 +383,4 @@ public void run() {
385383 t .start ();
386384 return t ;
387385 }
388-
389- private static String asArgument (final String key , final String value ) {
390- return String .format ("-D%s=%s" , key , value );
391- }
392386}
0 commit comments