import gzip
import os
import shutil
import tempfile

from perf_insights import trace_handle


class LocalFileTraceHandle(trace_handle.TraceHandle):
  def __init__(self, run_info, filename):
    super(LocalFileTraceHandle, self).__init__(run_info)
    self.filename = filename

  def Open(self):
    temp_trace_file = tempfile.NamedTemporaryFile(
        dir=os.path.dirname(self.filename))
    try:
      with gzip.GzipFile(self.filename) as unzipped:
        shutil.copyfileobj(unzipped, temp_trace_file)
        temp_trace_file.flush()
        return temp_trace_file
    except IOError:
      temp_trace_file.close()
      return open(self.filename, 'r')

from perf_insights import trace_handle


class LocalFileTraceHandle(trace_handle.TraceHandle):
  def __init__(self, run_info, filename):
    super(LocalFileTraceHandle, self).__init__(run_info)
    self.filename = filename

  def Open(self):
    return open(self.filename, 'r')

Revert gunzip in python from performance insights mapping
Revert gunzip in python from performance insights mapping

Reverts ade2e1a90cc69169b8c613606b44ac7503b64503. This appears to be
causing significant contention on at least z840 machines. Only ~12 d8
instances run at any given time despite -j48.

As noted in https://github.com/catapult-project/catapult/issues/1193
the speedup by moving unzip to python was negligible.

BUG=#1193

Review URL: https://codereview.chromium.org/1304143009

- import gzip
- import os
- import shutil
- import tempfile
- 
  from perf_insights import trace_handle
  
  
  class LocalFileTraceHandle(trace_handle.TraceHandle):
    def __init__(self, run_info, filename):
      super(LocalFileTraceHandle, self).__init__(run_info)
      self.filename = filename
  
    def Open(self):
-     temp_trace_file = tempfile.NamedTemporaryFile(
-         dir=os.path.dirname(self.filename))
-     try:
-       with gzip.GzipFile(self.filename) as unzipped:
-         shutil.copyfileobj(unzipped, temp_trace_file)
-         temp_trace_file.flush()
-         return temp_trace_file
-     except IOError:
-       temp_trace_file.close()
-       return open(self.filename, 'r')
+     return open(self.filename, 'r')
  
Revert gunzip in python from performance insights mapping
## Code Before:
import gzip
import os
import shutil
import tempfile

from perf_insights import trace_handle


class LocalFileTraceHandle(trace_handle.TraceHandle):
  def __init__(self, run_info, filename):
    super(LocalFileTraceHandle, self).__init__(run_info)
    self.filename = filename

  def Open(self):
    temp_trace_file = tempfile.NamedTemporaryFile(
        dir=os.path.dirname(self.filename))
    try:
      with gzip.GzipFile(self.filename) as unzipped:
        shutil.copyfileobj(unzipped, temp_trace_file)
        temp_trace_file.flush()
        return temp_trace_file
    except IOError:
      temp_trace_file.close()
      return open(self.filename, 'r')

## Instruction:
Revert gunzip in python from performance insights mapping
## Code After:
from perf_insights import trace_handle


class LocalFileTraceHandle(trace_handle.TraceHandle):
  def __init__(self, run_info, filename):
    super(LocalFileTraceHandle, self).__init__(run_info)
    self.filename = filename

  def Open(self):
    return open(self.filename, 'r')
