1   package org.slf4j.profiler;
2   
3   import org.slf4j.Logger;
4   import org.slf4j.LoggerFactory;
5   
6   
7   
8   /**
9    * 
10   * This demo illustrates usage of SLF4J profilers. It is almost identical to
11   * the first NestProfilerDemo, except that it uses a logger instead of
12   * printing its output on the console.
13   * 
14  
15   * @author Ceki Gulcu
16   */
17  public class NestedProfilerDemo2 {
18  
19    static Logger logger = LoggerFactory.getLogger(NestedProfilerDemo2.class);
20    
21    public static void main(String[] args) {
22      Profiler profiler = new Profiler("DEMO");
23      // associate a logger with the profiler
24      profiler.setLogger(logger);
25      
26      ProfilerRegistry profilerRegistry = ProfilerRegistry.getThreadContextInstance();
27      profiler.registerWith(profilerRegistry);
28      
29      profiler.start("RANDOM");
30      RandomIntegerArrayGenerator riaGenerator = new RandomIntegerArrayGenerator();
31      int n = 10*1000;
32      int[] randomArray = riaGenerator.generate(n);
33      
34      profiler.startNested(SortAndPruneComposites.NESTED_PROFILER_NAME);
35      
36      SortAndPruneComposites pruner = new SortAndPruneComposites(randomArray);
37      pruner.sortAndPruneComposites();
38      
39      // stop and log
40      profiler.stop().log();
41    }
42  }