Home | History | Annotate | Download | only in r8
      1 // Copyright (c) 2016, the R8 project authors. Please see the AUTHORS file
      2 // for details. All rights reserved. Use of this source code is governed by a
      3 // BSD-style license that can be found in the LICENSE file.
      4 package com.android.tools.r8;
      5 
      6 import com.android.tools.r8.graph.DexItemFactory;
      7 import com.android.tools.r8.shaking.ProguardConfigurationParser;
      8 import com.android.tools.r8.shaking.ProguardRuleParserException;
      9 import com.android.tools.r8.utils.Timing;
     10 import java.io.IOException;
     11 import java.nio.file.Paths;
     12 
     13 /**
     14  * Benchmark for testing ability to and speed of parsing Proguard keep files.
     15  */
     16 public class ReadKeepFile {
     17 
     18   private static final String DEFAULT_KEEP_FILE_NAME = "build/proguard.cfg";
     19 
     20   final Timing timing = new Timing("ReadKeepFile");
     21 
     22   private void readProguardKeepFile(String fileName) throws ProguardRuleParserException {
     23     try {
     24       System.out.println("  - reading " + fileName);
     25       timing.begin("Reading " + fileName);
     26       new ProguardConfigurationParser(new DexItemFactory()).parse(Paths.get(fileName));
     27       timing.end();
     28     } catch (IOException e) {
     29       System.err.print("Failed to parse Proguard keep file: " + e.getMessage());
     30     }
     31   }
     32 
     33   public static void main(String[] args) throws ProguardRuleParserException {
     34     new ReadKeepFile().run(args);
     35   }
     36 
     37   private void run(String[] args) throws ProguardRuleParserException {
     38     System.out.println("ProguardKeepRuleParser benchmark.");
     39     if (args.length == 0) {
     40       readProguardKeepFile(DEFAULT_KEEP_FILE_NAME);
     41     } else {
     42       for (String name : args) {
     43         readProguardKeepFile(name);
     44       }
     45     }
     46     timing.report();
     47   }
     48 }
     49