green-metrics-tool icon indicating copy to clipboard operation
green-metrics-tool copied to clipboard

powermetrics reporter sometimes fails when trying to read metrics from file

Open ArneTR opened this issue 1 year ago • 1 comments

This is the error I got:

Error:  Base exception occured in runner.py:  no element found: line 3015, column 43

Traceback (most recent call last):
  File "/Users/arne/Sites/green-coding/green-metrics-tool/runner.py", line 1126, in <module>
    runner.run()  # Start main code
  File "/Users/arne/Sites/green-coding/green-metrics-tool/runner.py", line 1035, in run
    self.stop_metric_providers()
  File "/Users/arne/Sites/green-coding/green-metrics-tool/runner.py", line 862, in stop_metric_providers
    df = metric_provider.read_metrics(self._project_id, self.__containers)
  File "/Users/arne/Sites/green-coding/green-metrics-tool/metric_providers/powermetrics/provider.py", line 60, in read_metrics
    data = plistlib.loads(data)
  File "/opt/homebrew/Cellar/[email protected]/3.10.11/Frameworks/Python.framework/Versions/3.10/lib/python3.10/plistlib.py", line 892, in loads
    return load(fp, fmt=fmt, dict_type=dict_type)
  File "/opt/homebrew/Cellar/[email protected]/3.10.11/Frameworks/Python.framework/Versions/3.10/lib/python3.10/plistlib.py", line 884, in load
    return p.parse(fp)
  File "/opt/homebrew/Cellar/[email protected]/3.10.11/Frameworks/Python.framework/Versions/3.10/lib/python3.10/plistlib.py", line 186, in parse
    self.parser.ParseFile(fileobj)
xml.parsers.expat.ExpatError: no element found: line 3015, column 43

The reason is most likely that the xml got truncated at a specific point when the runner process was killed. Apparently the time is not sufficent for the process to close when we send the SIGTERM or there is some form of output-buffering in place.

I added it for now also to the "Troubleshooting" part of the docs, as the easiest fix is just to run the tool again. It happens for me every 10th run or so.

ArneTR avatar May 08 '23 09:05 ArneTR