Exemplo n.º 1
0
 public JSONArray toJSONArrayWithoutDetails() {
   try {
     PerfMetrics metricsWithoutDetails =
         PerfGoldFilesUtil.fromGoldFileText(PerfGoldFilesUtil.toGoldFileText(this, false));
     JSONArray array = new JSONArray();
     for (String name : metricsWithoutDetails.getAllMetricNames()) {
       array.put(metricsWithoutDetails.getMetric(name));
     }
     return array;
   } catch (IOException e) {
     throw new RuntimeException(e);
   }
 }
Exemplo n.º 2
0
 /** @return number of metrics that are the same as the ones in the other PerfMetrics object */
 public int numSame(PerfMetrics other) {
   int numSame = 0;
   for (String name : metrics.keySet()) {
     if (getMetric(name).equals(other.getMetric(name))) {
       numSame++;
     }
   }
   return numSame;
 }
Exemplo n.º 3
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;
  }