All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.arextest.diff.handler.metric.TimeConsumerWatch Maven / Gradle / Ivy

There is a newer version: 0.2.15
Show newest version
package com.arextest.diff.handler.metric;

import com.arextest.diff.model.CompareResult;
import com.arextest.diff.model.SystemConfig;
import com.arextest.diff.model.metric.MetricIndicator;
import java.util.LinkedHashMap;
import java.util.Map;

public class TimeConsumerWatch {

  private Map taskMap = new LinkedHashMap<>();

  public void start(String taskName) {
    taskMap.computeIfAbsent(taskName,
            k -> new MetricIndicator.TaskInfo(taskName, System.currentTimeMillis(), null))
        .setStartTime(System.currentTimeMillis());

  }

  public void end(String taskName) {
    MetricIndicator.TaskInfo taskInfo = taskMap.get(taskName);
    if (taskInfo != null) {
      taskInfo.setData(System.currentTimeMillis() - taskInfo.getStartTime());
    }
  }

  public void record(CompareResult compareResult) {

    if (compareResult == null) {
      return;
    }

    if (!SystemConfig.isMetricsEnable()) {
      return;
    }

    MetricIndicator metricIndicator = compareResult.getMetricIndicator();
    if (metricIndicator == null) {
      metricIndicator = new MetricIndicator();
      metricIndicator.setTimeMetric(taskMap);
      compareResult.setMetricIndicator(metricIndicator);
    } else {
      metricIndicator.setTimeMetric(taskMap);
    }

  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy