# Path: tacc_stats/analysis/gen/utils.py
# class utils():
#   def __init__(self, job):
#     freq_list = {"intel_snb" : 2.7, "intel_ivb" : 2.8, "intel_hsw" : 2.3,
#                  "intel_bdw" : 2.6, "intel_knl" : 1.4, "intel_skx" : 2.1,
#                  "intel_8pmc3" : 2.7, "intel_4pmc3" : 2.7}
#     imc_list  = ["intel_snb_imc", "intel_ivb_imc", "intel_hsw_imc",
#                  "intel_bdw_imc", "intel_knl_mc_dclk", "intel_skx_imc"]
#     cha_list = ["intel_knl_cha", "intel_skx_cha"]
#     self.job = job
#     self.nhosts = len(job.hosts.keys())
#     self.hostnames  = sorted(job.hosts.keys())
#     self.wayness = int(job.acct['cores'])/int(job.acct['nodes'])
#     self.hours = ((job.times[:] - job.times[0])/3600.).astype(float)
#     self.t = job.times
#     self.nt = len(job.times)
#     self.dt = (job.times[-1] - job.times[0]).astype(float)
#     for typename in  job.schemas.keys():
#       if typename in freq_list:
#           self.pmc  = typename
#           self.freq = freq_list[typename]
#       if typename in imc_list:
#           self.imc = typename
#       if typename in cha_list:
#           self.cha = typename
# 
#   def get_type(self, typename, aggregate = True):
#     if typename == "imc": typename = self.imc
#     if typename == "pmc": typename = self.pmc
#     if typename == "cha": typename = self.cha
#     if not typename: return
# 
#     schema = self.job.schemas[typename]
#     stats = {}
#     for hostname, host in self.job.hosts.items():
#       if aggregate:
#         stats[hostname] = 0
#         for devname in host.stats[typename]:
#           stats[hostname] += host.stats[typename][devname].astype(float)
#       else:
#         stats[hostname] = {}
#         for devname in host.stats[typename]:
#           stats[hostname][devname] = host.stats[typename][devname].astype(float)
#     return schema, stats


import sys
import operator, traceback
import pickle as p
import multiprocessing
from tacc_stats.analysis.gen import utils
from numpy import diff, amax, zeros, maximum, mean, isnan, trapz
  def run(self, filelist):
    if not filelist: 
      print("Please specify a job file list.")
      sys.exit()
    pool = multiprocessing.Pool(processes = self.processes) 

    metrics = pool.map(_unwrap, zip([self]*len(filelist), filelist))
    #metrics = map(_unwrap, zip([self]*len(filelist), filelist))
    return metrics

  # Compute metric
  def compute_metrics(self, jobpath):
    try:
      with open(jobpath, 'rb') as fd: 
        try: job = p.load(fd)
        except UnicodeDecodeError as e: 
          try: 
            job = p.load(fd, encoding = "latin1") # Python2 Compatibility
          except: return jobpath, None
    except MemoryError as e:
      print('File ' + jobpath + ' to large to load')
      return jobpath, None
    except IOError as e:
      print('File ' + jobpath + ' not found')
      return jobpath, None
    except EOFError as e:
      print('End of file error for: ' + jobpath)
      return jobpath, None
    except:
      return jobpath, None

# Path: tacc_stats/analysis/gen/utils.py
# class utils():
#   def __init__(self, job):
#     freq_list = {"intel_snb" : 2.7, "intel_ivb" : 2.8, "intel_hsw" : 2.3,
#                  "intel_bdw" : 2.6, "intel_knl" : 1.4, "intel_skx" : 2.1,
#                  "intel_8pmc3" : 2.7, "intel_4pmc3" : 2.7}
#     imc_list  = ["intel_snb_imc", "intel_ivb_imc", "intel_hsw_imc",
#                  "intel_bdw_imc", "intel_knl_mc_dclk", "intel_skx_imc"]
#     cha_list = ["intel_knl_cha", "intel_skx_cha"]
#     self.job = job
#     self.nhosts = len(job.hosts.keys())
#     self.hostnames  = sorted(job.hosts.keys())
#     self.wayness = int(job.acct['cores'])/int(job.acct['nodes'])
#     self.hours = ((job.times[:] - job.times[0])/3600.).astype(float)
#     self.t = job.times
#     self.nt = len(job.times)
#     self.dt = (job.times[-1] - job.times[0]).astype(float)
#     for typename in  job.schemas.keys():
#       if typename in freq_list:
#           self.pmc  = typename
#           self.freq = freq_list[typename]
#       if typename in imc_list:
#           self.imc = typename
#       if typename in cha_list:
#           self.cha = typename
# 
#   def get_type(self, typename, aggregate = True):
#     if typename == "imc": typename = self.imc
#     if typename == "pmc": typename = self.pmc
#     if typename == "cha": typename = self.cha
#     if not typename: return
# 
#     schema = self.job.schemas[typename]
#     stats = {}
#     for hostname, host in self.job.hosts.items():
#       if aggregate:
#         stats[hostname] = 0
#         for devname in host.stats[typename]:
#           stats[hostname] += host.stats[typename][devname].astype(float)
#       else:
#         stats[hostname] = {}
#         for devname in host.stats[typename]:
#           stats[hostname][devname] = host.stats[typename][devname].astype(float)
#     return schema, stats


# Path: tacc_stats/analysis/metrics/metrics.py
import sys
import operator, traceback
import pickle as p
import multiprocessing
from tacc_stats.analysis.gen import utils
from numpy import diff, amax, zeros, maximum, mean, isnan, trapz

  def run(self, filelist):
    if not filelist: 
      print("Please specify a job file list.")
      sys.exit()
    pool = multiprocessing.Pool(processes = self.processes) 

    metrics = pool.map(_unwrap, zip([self]*len(filelist), filelist))
    #metrics = map(_unwrap, zip([self]*len(filelist), filelist))
    return metrics

  # Compute metric
  def compute_metrics(self, jobpath):
    try:
      with open(jobpath, 'rb') as fd: 
        try: job = p.load(fd)
        except UnicodeDecodeError as e: 
          try: 
            job = p.load(fd, encoding = "latin1") # Python2 Compatibility
          except: return jobpath, None
    except MemoryError as e:
      print('File ' + jobpath + ' to large to load')
      return jobpath, None
    except IOError as e:
      print('File ' + jobpath + ' not found')
      return jobpath, None
    except EOFError as e:
      print('End of file error for: ' + jobpath)
      return jobpath, None
    except:
      return jobpath, None

    u = utils.utils(job)