Coverage Report - org.apache.giraph.benchmark.GiraphBenchmark
 
Classes in this File Line Coverage Branch Coverage Complexity
GiraphBenchmark
0%
0/39
0%
0/14
3.2
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one
 3  
  * or more contributor license agreements.  See the NOTICE file
 4  
  * distributed with this work for additional information
 5  
  * regarding copyright ownership.  The ASF licenses this file
 6  
  * to you under the Apache License, Version 2.0 (the
 7  
  * "License"); you may not use this file except in compliance
 8  
  * with the License.  You may obtain a copy of the License at
 9  
  *
 10  
  *     http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  
  * See the License for the specific language governing permissions and
 16  
  * limitations under the License.
 17  
  */
 18  
 
 19  
 package org.apache.giraph.benchmark;
 20  
 
 21  
 import org.apache.commons.cli.CommandLine;
 22  
 import org.apache.commons.cli.CommandLineParser;
 23  
 import org.apache.commons.cli.HelpFormatter;
 24  
 import org.apache.commons.cli.Options;
 25  
 import org.apache.commons.cli.PosixParser;
 26  
 import org.apache.giraph.conf.GiraphConfiguration;
 27  
 import org.apache.giraph.job.GiraphJob;
 28  
 import org.apache.giraph.utils.LogVersions;
 29  
 import org.apache.hadoop.conf.Configuration;
 30  
 import org.apache.hadoop.util.Tool;
 31  
 import org.apache.log4j.Logger;
 32  
 
 33  
 import java.util.Set;
 34  
 
 35  
 /**
 36  
  * Abstract class which benchmarks should extend.
 37  
  */
 38  0
 public abstract class GiraphBenchmark implements Tool {
 39  
   /** Class logger */
 40  0
   private static final Logger LOG = Logger.getLogger(GiraphBenchmark.class);
 41  
   /** Configuration */
 42  
   private Configuration conf;
 43  
 
 44  
   @Override
 45  
   public void setConf(Configuration conf) {
 46  0
     this.conf = conf;
 47  0
   }
 48  
 
 49  
   @Override
 50  
   public Configuration getConf() {
 51  0
     return conf;
 52  
   }
 53  
 
 54  
   @Override
 55  
   public int run(String[] args) throws Exception {
 56  0
     Set<BenchmarkOption> giraphOptions = getBenchmarkOptions();
 57  0
     giraphOptions.add(BenchmarkOption.HELP);
 58  0
     giraphOptions.add(BenchmarkOption.VERBOSE);
 59  0
     giraphOptions.add(BenchmarkOption.WORKERS);
 60  0
     Options options = new Options();
 61  0
     for (BenchmarkOption giraphOption : giraphOptions) {
 62  0
       giraphOption.addToOptions(options);
 63  0
     }
 64  
 
 65  0
     HelpFormatter formatter = new HelpFormatter();
 66  0
     if (args.length == 0) {
 67  0
       formatter.printHelp(getClass().getName(), options, true);
 68  0
       return 0;
 69  
     }
 70  0
     CommandLineParser parser = new PosixParser();
 71  0
     CommandLine cmd = parser.parse(options, args);
 72  0
     for (BenchmarkOption giraphOption : giraphOptions) {
 73  0
       if (!giraphOption.checkOption(cmd, LOG)) {
 74  0
         return -1;
 75  
       }
 76  0
     }
 77  0
     if (BenchmarkOption.HELP.optionTurnedOn(cmd)) {
 78  0
       formatter.printHelp(getClass().getName(), options, true);
 79  0
       return 0;
 80  
     }
 81  
 
 82  0
     GiraphJob job = new GiraphJob(getConf(), getClass().getName());
 83  0
     int workers = Integer.parseInt(BenchmarkOption.WORKERS.getOptionValue(cmd));
 84  
 
 85  0
     GiraphConfiguration giraphConf = job.getConfiguration();
 86  0
     giraphConf.addWorkerObserverClass(LogVersions.class);
 87  0
     giraphConf.addMasterObserverClass(LogVersions.class);
 88  
 
 89  0
     giraphConf.setWorkerConfiguration(workers, workers, 100.0f);
 90  0
     prepareConfiguration(giraphConf, cmd);
 91  
 
 92  0
     boolean isVerbose = false;
 93  0
     if (BenchmarkOption.VERBOSE.optionTurnedOn(cmd)) {
 94  0
       isVerbose = true;
 95  
     }
 96  0
     if (job.run(isVerbose)) {
 97  0
       return 0;
 98  
     } else {
 99  0
       return -1;
 100  
     }
 101  
   }
 102  
 
 103  
   /**
 104  
    * Get the options to use in this benchmark.
 105  
    * BenchmarkOption.VERBOSE, BenchmarkOption.HELP and BenchmarkOption.WORKERS
 106  
    * will be added automatically, so you don't have to specify those.
 107  
    *
 108  
    * @return Options to use in this benchmark
 109  
    */
 110  
   public abstract Set<BenchmarkOption> getBenchmarkOptions();
 111  
 
 112  
   /**
 113  
    * Process options from CommandLine and prepare configuration for running
 114  
    * the job.
 115  
    * BenchmarkOption.VERBOSE, BenchmarkOption.HELP and BenchmarkOption.WORKERS
 116  
    * will be processed automatically so you don't have to process them.
 117  
    *
 118  
    * @param conf Configuration
 119  
    * @param cmd Command line
 120  
    */
 121  
   protected abstract void prepareConfiguration(GiraphConfiguration conf,
 122  
       CommandLine cmd);
 123  
 }