TaskMonitor implements Runnable { @VisibleForTesting void setMaxMetrics(int metricIndex, double newMetricValue) { MetricWritable metric = metrics.getMetric(metricIndex); if (newMetricValue > metric.getValue()) { metric.setValue(newMetricValue); metrics.setMetric(metricIndex, metric); } } TaskMonitor(String taskType, int taskIndex,
      Configuration yarnConf, Configuration tonyConf, MetricsRpc metricsRpcClient); @Override void run(); static final List<String> METRICS_TO_COLLECT; static final int MAX_MEMORY_BYTES_INDEX; static final int AVG_MEMORY_BYTES_INDEX; static final int MAX_GPU_UTILIZATION_INDEX; static final int AVG_GPU_UTILIZATION_INDEX; static final int MAX_GPU_FB_MEMORY_USAGE_INDEX; static final int AVG_GPU_FB_MEMORY_USAGE_INDEX; static final int MAX_GPU_MAIN_MEMORY_USAGE_INDEX; static final int AVG_GPU_MAIN_MEMORY_USAGE_INDEX; }
@Test public void testSetMaxMetrics() { taskMonitor.setMaxMetrics(TaskMonitor.AVG_GPU_FB_MEMORY_USAGE_INDEX, 0.1); taskMonitor.numRefreshes++; taskMonitor.setMaxMetrics(TaskMonitor.AVG_GPU_FB_MEMORY_USAGE_INDEX, 0.4); taskMonitor.numRefreshes++; taskMonitor.setMaxMetrics(TaskMonitor.AVG_GPU_FB_MEMORY_USAGE_INDEX, 0.2); MetricsWritable metrics = taskMonitor.getMetrics(); Assert.assertEquals(metrics.getMetric(TaskMonitor.AVG_GPU_FB_MEMORY_USAGE_INDEX).getValue(), 0.4); }