Coverage Report - org.apache.giraph.utils.JMapHistoDumper
 
Classes in this File Line Coverage Branch Coverage Complexity
JMapHistoDumper
0%
0/29
N/A
1.154
JMapHistoDumper$1
0%
0/5
0%
0/2
1.154
 
 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.utils;
 20  
 
 21  
 import org.apache.giraph.conf.GiraphConstants;
 22  
 import org.apache.giraph.conf.ImmutableClassesGiraphConfiguration;
 23  
 import org.apache.giraph.master.MasterObserver;
 24  
 import org.apache.giraph.metrics.AggregatedMetrics;
 25  
 import org.apache.giraph.partition.PartitionStats;
 26  
 import org.apache.giraph.worker.WorkerObserver;
 27  
 import org.apache.log4j.Logger;
 28  
 
 29  
 import java.util.List;
 30  
 
 31  
 /**
 32  
  * An observer for both worker and master that periodically dumps the memory
 33  
  * usage using jmap tool.
 34  
  */
 35  0
 public class JMapHistoDumper implements MasterObserver, WorkerObserver {
 36  
   /** Logger */
 37  0
   private static final Logger LOG = Logger.getLogger(JMapHistoDumper.class);
 38  
 
 39  
   /** How many msec to sleep between calls */
 40  
   private int sleepMillis;
 41  
   /** How many lines of output to print */
 42  
   private int linesToPrint;
 43  
   /** Should only print live objects */
 44  
   private boolean liveObjectsOnly;
 45  
 
 46  
   /** The jmap printing thread */
 47  
   private Thread thread;
 48  
   /** Halt jmap thread */
 49  0
   private volatile boolean stop = false;
 50  
   /** Path to jmap*/
 51  
   private String jmapPath;
 52  
 
 53  
   @Override
 54  
   public void preLoad() {
 55  
     // This is called by both WorkerObserver and MasterObserver
 56  0
     startJMapThread();
 57  0
   }
 58  
 
 59  
   @Override
 60  
   public void postSave() {
 61  
     // This is called by both WorkerObserver and MasterObserver
 62  0
     joinJMapThread();
 63  0
   }
 64  
 
 65  
   @Override
 66  
   public void preApplication() {
 67  0
   }
 68  
 
 69  
   @Override
 70  
   public void postApplication() {
 71  0
   }
 72  
 
 73  
   /**
 74  
    * Join the jmap thread
 75  
    */
 76  
   private void joinJMapThread() {
 77  0
     stop = true;
 78  
     try {
 79  0
       thread.interrupt();
 80  0
       thread.join(sleepMillis + 5000);
 81  0
     } catch (InterruptedException e) {
 82  0
       LOG.error("Failed to join jmap thread");
 83  0
     }
 84  0
   }
 85  
 
 86  
   /**
 87  
    * Start the jmap thread
 88  
    */
 89  
   public void startJMapThread() {
 90  0
     stop = false;
 91  0
     thread = ThreadUtils.startThread(new Runnable() {
 92  
       @Override
 93  
       public void run() {
 94  0
         while (!stop) {
 95  0
           JMap.heapHistogramDump(linesToPrint, liveObjectsOnly, jmapPath);
 96  0
           ThreadUtils.trySleep(sleepMillis);
 97  
         }
 98  0
       }
 99  
     }, "jmap-dumper");
 100  0
   }
 101  
 
 102  
   @Override
 103  0
   public void preSuperstep(long superstep) { }
 104  
 
 105  
   @Override
 106  0
   public void postSuperstep(long superstep) { }
 107  
 
 108  
   @Override
 109  
   public void superstepMetricsUpdate(long superstep,
 110  
       AggregatedMetrics aggregatedMetrics,
 111  0
       List<PartitionStats> partitionStatsList) { }
 112  
 
 113  
   @Override
 114  0
   public void applicationFailed(Exception e) { }
 115  
 
 116  
   @Override
 117  
   public void setConf(ImmutableClassesGiraphConfiguration configuration) {
 118  0
     sleepMillis = GiraphConstants.JMAP_SLEEP_MILLIS.get(configuration);
 119  0
     linesToPrint = GiraphConstants.JMAP_PRINT_LINES.get(configuration);
 120  0
     liveObjectsOnly = GiraphConstants.JMAP_LIVE_ONLY.get(configuration);
 121  0
     jmapPath = GiraphConstants.JMAP_PATH.get(configuration);
 122  0
   }
 123  
 
 124  
   @Override
 125  
   public ImmutableClassesGiraphConfiguration getConf() {
 126  0
     return null;
 127  
   }
 128  
 }