225d31587eeb9aca226158e346c8e9730777913c,perfkitbenchmarker/publisher.py,,RepublishJSONSamples,#Any#,763

Before Change


  samples = []
  with open(path, "r") as file:
    for line in file:
      try:
        raw_dict = json.loads(line)
        labels = raw_dict.pop("labels")
        metadata = dict()
        // labels is a comma-seprated list of key, value pairs
        for pair in labels.split(","):
          // Need to strip leading and trailing "|" from each pair
          key, _, value = pair[1:-1].partition(":")
          metadata[key] = value
        raw_dict["metadata"] = metadata
        samples.append(raw_dict)
      except Exception as e:
        logging.info("Exception processing sample %s", line)
        logging.info("Exception was: %s", e)
        raise e

  // We can"t use a SampleCollector because SampleCollector.AddSamples depends on
  // having a benchmark and a benchmark_spec.
  publishers = SampleCollector._PublishersFromFlags()
  for publisher in publishers:
    publisher.PublishSamples(samples)

After Change



  with open(path, "r") as file:
    samples = [json.loads(s) for s in file if s]
  for sample in samples:
    // Chop "|" at the beginning and end of labels and split labels by "|,|"
    fields = sample.pop("labels")[1:-1].split("|,|")
    // Turn the fields into [[key, value], ...]
    key_values = [field.split(":", 1) for field in fields]
    sample["metadata"] = {k: v for k, v in key_values}

  // We can"t use a SampleCollector because SampleCollector.AddSamples depends on
  // having a benchmark and a benchmark_spec.
  publishers = SampleCollector._PublishersFromFlags()
  for publisher in publishers:
    publisher.PublishSamples(samples)
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 7

Instances


Project Name: GoogleCloudPlatform/PerfKitBenchmarker
Commit Name: 225d31587eeb9aca226158e346c8e9730777913c
Time: 2017-02-24
Author: nlavine@google.com
File Name: perfkitbenchmarker/publisher.py
Class Name:
Method Name: RepublishJSONSamples


Project Name: home-assistant/home-assistant
Commit Name: 754d536974fccd0768b90938d79071ba0910714a
Time: 2016-10-21
Author: martin@dasos.com
File Name: homeassistant/components/media_player/squeezebox.py
Class Name: LogitechMediaServer
Method Name: get_player_status


Project Name: cjekel/tindetheus
Commit Name: 5a2b9314cd5b3f4da053a3813dceed362b039043
Time: 2018-11-03
Author: cjekel@gmail.com
File Name: tindetheus/tindetheus.py
Class Name:
Method Name: command_line_run