# Copyright (c) 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
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')

# Copyright (c) 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
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
