Exemple #1
0
  /**
   * Combines the metrics from multiple metrics objects into a single one. If a metric appears in
   * more than one metric object the first metric value found is used.
   */
  public static PerfMetrics combine(PerfMetrics... metricsList) {
    PerfMetrics combined = null;
    List<JSONObject> devToolsLog = null;
    Map<String, ?> jsProfilerData = null;
    Map<String, ?> heapSnapshot = null;

    for (PerfMetrics metrics : metricsList) {
      if (metrics != null) {
        if (devToolsLog == null) {
          devToolsLog = metrics.getDevToolsLog();
        }
        if (jsProfilerData == null) {
          jsProfilerData = metrics.getJSProfilerData();
        }
        if (heapSnapshot == null) {
          heapSnapshot = metrics.getHeapSnapshot();
        }
        if (combined == null) {
          // so we return null if all metrics in metricsList are null
          combined = new PerfMetrics();
        }
        for (String name : metrics.getAllMetricNames()) {
          if (!combined.hasMetric(name)) {
            combined.setMetric(metrics.getMetric(name));
          }
        }
      }
    }
    if (combined != null) {
      combined.setDevToolsLog(devToolsLog);
      combined.setJSProfilerData(jsProfilerData);
      combined.setHeapSnapshot(heapSnapshot);
    }
    return combined;
  }