Beispiel #1
0
 def test_to_csv_no_header(self):
     metric = CurieMetric()
     metric.CopyFrom(self.counter_template)
     metric.timestamps.extend([1454092320, 1454092321])
     metric.values.extend([1, 2])
     new_results = {"node_0": [metric]}
     csv = ScenarioUtil.results_map_to_csv(new_results, header=False)
     self.assertEqual(
         csv, "1454092320,node_0,CpuUsage.Avg.Percent,Aggregated,1\n" +
         "1454092321,node_0,CpuUsage.Avg.Percent,Aggregated,2\n")
Beispiel #2
0
 def test_to_csv_newline(self):
     metric = CurieMetric()
     metric.CopyFrom(self.counter_template)
     metric.timestamps.extend([1454092320, 1454092321])
     metric.values.extend([1, 2])
     new_results = {"node_0": [metric]}
     csv = ScenarioUtil.results_map_to_csv(new_results, newline="\r\n")
     self.assertEqual(
         csv, "timestamp,node_id,metric_name,instance,value\r\n" +
         "1454092320,node_0,CpuUsage.Avg.Percent,Aggregated,1\r\n" +
         "1454092321,node_0,CpuUsage.Avg.Percent,Aggregated,2\r\n")
Beispiel #3
0
 def test_to_csv_rate(self):
     metric = CurieMetric()
     metric.CopyFrom(self.counter_template)
     metric.timestamps.extend([1454092320, 1454092321])
     metric.values.extend([1, 2])
     metric.name = CurieMetric.kNetTransmitted
     metric.unit = CurieMetric.kKilobytes
     metric.rate = CurieMetric.kPerSecond
     new_results = {"node_0": [metric]}
     csv = ScenarioUtil.results_map_to_csv(new_results, newline="\r\n")
     self.assertEqual(
         csv, "timestamp,node_id,metric_name,instance,value\r\n" +
         "1454092320,node_0,NetTransmitted.Avg.KilobytesPerSecond,Aggregated,1\r\n"
         +
         "1454092321,node_0,NetTransmitted.Avg.KilobytesPerSecond,Aggregated,2\r\n"
     )
Beispiel #4
0
  def _cluster_results_update(self, start_time_secs=None):
    """
    Update the in-memory and on-disk cluster results.

    Returns:
      int or None: Epoch time passed through from
        ScenarioUtil.append_cluster_stats, or None if no data was collected.
    """
    cluster_stats_dir = self.cluster_stats_dir()
    if cluster_stats_dir is None:
      log.warning("Cluster results not collected because the output directory "
                  "is not set")
      return None
    try:
      # If data has been collected before, get the data after the previous
      # collection. Otherwise, latest_appended_time_secs is None, and the
      # default number of the latest samples will be collected.
      results_map = self.cluster.collect_performance_stats(
        start_time_secs=start_time_secs)
    except Exception:
      log.exception("An exception occurred while updating cluster results. "
                    "This operation will be retried.")
      return None
    else:
      csv_path = os.path.join(cluster_stats_dir, "cluster_stats.csv")
      appended_time_secs = ScenarioUtil.append_cluster_stats(
        results_map, self.cluster_stats_dir())
      # Write the results in CSV format for easier analysis.
      if os.path.isfile(csv_path):
        mode = "a"
        header = False
      else:
        mode = "w"
        header = True
      with open(csv_path, mode) as csv_file:
        csv_file.write(
          ScenarioUtil.results_map_to_csv(results_map, header=header))
      return appended_time_secs