private void compute(MapReduceTaskData[] taskDatas, long containerSize, long idealStartTime) {

    long peakMemoryNeed = 0;
    long taskFinishTimeMax = 0;
    long taskDurationMax = 0;

    // if there are zero tasks, then nothing to compute.
    if(taskDatas == null || taskDatas.length == 0) {
      return;
    }

    for (MapReduceTaskData taskData: taskDatas) {
      if (!taskData.isTimeAndCounterDataPresent()) {
        continue;
      }
      long taskMemory = taskData.getCounters().get(MapReduceCounterData.CounterName.PHYSICAL_MEMORY_BYTES)/ FileUtils.ONE_MB; // MB
      long taskVM = taskData.getCounters().get(MapReduceCounterData.CounterName.VIRTUAL_MEMORY_BYTES)/ FileUtils.ONE_MB; // MB
      long taskDuration = taskData.getFinishTimeMs() - taskData.getStartTimeMs(); // Milliseconds
      long taskCost =  (containerSize) * (taskDuration / Statistics.SECOND_IN_MS); // MB Seconds

      durations.add(taskDuration);
      finishTimes.add(taskData.getFinishTimeMs());

      //peak Memory usage
      long memoryRequiredForVM = (long) (taskVM/CLUSTER_MEMORY_FACTOR);
      long biggerMemoryRequirement = memoryRequiredForVM > taskMemory ? memoryRequiredForVM : taskMemory;
      peakMemoryNeed = biggerMemoryRequirement > peakMemoryNeed ? biggerMemoryRequirement : peakMemoryNeed;

      if(taskFinishTimeMax < taskData.getFinishTimeMs()) {
        taskFinishTimeMax = taskData.getFinishTimeMs();
      }

      if(taskDurationMax < taskDuration) {
        taskDurationMax = taskDuration;
      }
      _resourceUsed += taskCost;
    }

    // Compute the delay in starting the task.
    _delay = taskFinishTimeMax - (idealStartTime + taskDurationMax);

    // invalid delay
    if(_delay < 0) {
      _delay = 0;
    }

    // wastedResources
    long wastedMemory = containerSize - (long) (peakMemoryNeed * MEMORY_BUFFER); // give a 50% buffer
    if(wastedMemory > 0) {
      for (long duration : durations) {
        _resourceWasted += (wastedMemory) * (duration / Statistics.SECOND_IN_MS); // MB Seconds
      }
    }
  }
Computes the aggregated metrics -> peakMemory, delay, total task duration, wasted resources and memory usage.
Aggregated metrics are expected to be approximation when sampling is enabled.
@param taskDatas
@param containerSize
@param idealStartTime
app/com/linkedin/drelephant/mapreduce/TaskLevelAggregatedMetrics.java