Exemple #1
0
def collectCPIStackDataFIC(verbose=False, requested_cores_list=[]):
    totalinstructioncount = 0
    groupedintervals = groupIntervalsOnInstructionCount(
        getTotalInstructionCount() / num_intervals, verbose)
    usedcomponents = dict.fromkeys(cpiitems.names, 0)
    usedsimplecomponents = []
    ipcvaluesfic[0]["data"] = [
        dict(x=0, y=0) for x in xrange(len(groupedintervals))
    ]
    for key in cpificcomponents.keys():
        cpificcomponents[key] = [[0 for x in xrange(2)]
                                 for x in xrange(len(groupedintervals))]
    for key in simplifiedcpificcomponents.keys():
        simplifiedcpificcomponents[key] = [
            [0 for x in xrange(2)] for x in xrange(len(groupedintervals))
        ]
    for i in range(1, len(groupedintervals)):
        if verbose:
            print 'Collect CPI stack info for intervals with a fixed instruction count (interval ' + str(
                i + 1) + ' / ' + str(len(groupedintervals)) + ')' + "\r",
        cyclecountstart = groupedintervals[i - 1]["cyclecount"]
        instructioncount = groupedintervals[i]["instructioncount"]
        nameintervalstart = groupedintervals[i - 1]["intervalname"]
        nameintervalstop = groupedintervals[i]["intervalname"]
        currentinterval = (nameintervalstart, nameintervalstop)

        num_exceptions = 0
        simple = False

        try:
            results = cpistack.cpistack_compute(
                config=config,
                stats=stats,
                partial=currentinterval,
                use_simple=simple,
                use_simple_mem=True,
                no_collapse=True,
                aggregate=True,
                cores_list=requested_cores_list,
            )
            data = results.get_data('cpi')

            totalcpi = sum(data[0].itervalues())
            if totalcpi > 0:
                ipc = 1. / totalcpi
            else:
                ipc = 0
            ipcvaluesfic[0]["data"][i] = dict(x=cyclecountstart / 1e9, y=ipc)

            for key in results.labels:
                cpi = data[0][key]
                ipc = 0
                if cpi > 0.0:
                    usedcomponents[key] = 1
                cpificcomponents[key][i][0] = cpi
                cpificcomponents[key][i][
                    1] = cyclecountstart / 1e9  #now in microseconds
                simplecomponent = cpiitems.names_to_contributions[key]
                simplifiedcpificcomponents[simplecomponent][i][0] += cpi
                simplifiedcpificcomponents[simplecomponent][i][
                    1] = cyclecountstart / 1e9  #now in microseconds
                if not simplecomponent in usedsimplecomponents:
                    usedsimplecomponents.append(simplecomponent)

            totalinstructioncount += instructioncount

        except ValueError:
            num_exceptions += 1
            totalinstructioncount += instructioncount
            continue

    for component in cpiitems.names:
        if usedcomponents[component] == 1:
            usedcpificcomponents.append(component)

    def writeJSON(components, usedcomponents, name):
        jsonoutput = [0 for x in xrange(len(usedcomponents))]
        index = 0
        for key in usedcomponents:
            jsonoutput[index] = {}
            jsonoutput[index]["name"] = key
            jsonoutput[index]["data"] = [
                0 for x in xrange(len(groupedintervals))
            ]
            for i in range(0, len(groupedintervals)):
                xvalue = str(components[key][i][1])
                yvalue = str(components[key][i][0])
                jsonoutput[index]["data"][i] = dict(x=xvalue, y=yvalue)
            index += 1
        output = re.sub(r'("[xy]": )"([^\"]*)"', r'\1\2',
                        json.dumps(jsonoutput, indent=4))
        mkdir_p(os.path.join(outputdir, 'levels', 'level2', 'data'))
        jsonfile = open(
            os.path.join(outputdir, 'levels', 'level2', 'data',
                         title + '-' + name + '.json'), "w")
        jsonfile.write(output)
        jsonfile.close()

    writeJSON(cpificcomponents, usedcpificcomponents, 'cpific')
    writeJSON(simplifiedcpificcomponents, usedsimplecomponents, 'cpificsimple')

    if verbose:
        print
Exemple #2
0
def collectCPIStackDataFCC(verbose=False, requested_cores_list=[]):
    from StringIO import StringIO
    instructioncount = 0
    num_exceptions = 0
    usedcomponents = dict.fromkeys(cpiitems.names, 0)

    for i in range(0, num_intervals):
        if verbose:
            print 'Collect CPI stack info for intervals with a fixed time span (interval ' + str(
                i + 1) + ' / ' + str(num_intervals) + ')' + "\r",
        currentinterval = ("periodic-" + str(i * interval) + ":periodic-" +
                           str((i + 1) * interval)).split(":")

        newinstructioncount = getInstructionCount(currentinterval)
        instructioncountlist.append(newinstructioncount)
        instructioncount += newinstructioncount
        instructioncountsumlist.append(instructioncount)

        try:
            results = cpistack.cpistack_compute(
                config=config,
                stats=stats,
                partial=currentinterval,
                use_simple=False,
                use_simple_mem=True,
                no_collapse=True,
                aggregate=True,
                cores_list=requested_cores_list,
            )
            data = results.get_data('cpi')

            totalcpi = sum(data[0].itervalues())
            if totalcpi > 0:
                ipc = 1. / totalcpi
            else:
                ipc = 0

            ipcvalues[0]["data"][i] = dict(x=i * interval / 1e9, y=ipc)

            for key in results.labels:
                cpi = data[0][key]
                if totalcpi > 0:
                    cpipercentage = 100. * cpi / totalcpi
                else:
                    cpipercentage = 0

                if cpi > 0:
                    usedcomponents[key] = 1
                cpicomponents[key][i][0] = i
                cpicomponents[key][i][1] = cpipercentage
                cpicomponents[key][i][2] = cpi
                simplecomponent = cpiitems.names_to_contributions[key]
                simplifiedcpicomponents[simplecomponent][i][0] = i
                simplifiedcpicomponents[simplecomponent][i][1] += cpipercentage
                simplifiedcpicomponents[simplecomponent][i][2] += cpi
                if not simplecomponent in usedsimplifiedcpicomponents:
                    usedsimplifiedcpicomponents.append(simplecomponent)

        except ValueError:
            ipcvalues[0]["data"][i] = dict(x=i, y=0)
            num_exceptions += 1
            continue

    for component in cpiitems.names:
        if usedcomponents[component] == 1:
            usedcpicomponents.append(component)

    if verbose:
        print
        if (num_exceptions > 0):
            print "There was no useful information for " + str(
                num_exceptions) + " intervals."
            print "You might want to increase the interval size."
Exemple #3
0
def collectCPIStackDataFIC(verbose=False, requested_cores_list = []):
  totalinstructioncount = 0
  groupedintervals = groupIntervalsOnInstructionCount(getTotalInstructionCount()/num_intervals, verbose)
  usedcomponents = dict.fromkeys(cpiitems.names,0)
  usedsimplecomponents = []
  ipcvaluesfic[0]["data"]=[dict(x=0,y=0) for x in xrange(len(groupedintervals))]
  for key in cpificcomponents.keys():
    cpificcomponents[key] = [[0 for x in xrange(2)] for x in xrange(len(groupedintervals))]
  for key in simplifiedcpificcomponents.keys():
    simplifiedcpificcomponents[key] = [[0 for x in xrange(2)] for x in xrange(len(groupedintervals))]
  for i in range (1, len(groupedintervals)):
    if verbose:
      print 'Collect CPI stack info for intervals with a fixed instruction count (interval '+str(i+1)+' / '+str(len(groupedintervals))+')'+"\r",
    cyclecountstart = groupedintervals[i-1]["cyclecount"]
    instructioncount = groupedintervals[i]["instructioncount"]
    nameintervalstart = groupedintervals[i-1]["intervalname"]
    nameintervalstop = groupedintervals[i]["intervalname"]
    currentinterval = (nameintervalstart, nameintervalstop)

    num_exceptions = 0
    simple=False

    try:
      results = cpistack.cpistack_compute(
        config = config,
        stats = stats,
        partial = currentinterval,
        use_simple = simple,
        use_simple_mem = True,
        no_collapse = True,
        aggregate = True,
        cores_list = requested_cores_list,
      )
      data = results.get_data('cpi')

      totalcpi=sum(data[0].itervalues())
      if totalcpi > 0:
        ipc = 1./totalcpi
      else:
        ipc = 0
      ipcvaluesfic[0]["data"][i]=dict(x=cyclecountstart/1e9, y=ipc)


      for key in results.labels:
        cpi = data[0][key]
        ipc = 0
        if cpi > 0.0:
          usedcomponents[key]=1
        cpificcomponents[key][i][0]=cpi
        cpificcomponents[key][i][1]=cyclecountstart/1e9 #now in microseconds
        simplecomponent = cpiitems.names_to_contributions[key]
        simplifiedcpificcomponents[simplecomponent][i][0]+=cpi
        simplifiedcpificcomponents[simplecomponent][i][1]=cyclecountstart/1e9 #now in microseconds
        if not simplecomponent in usedsimplecomponents:
          usedsimplecomponents.append(simplecomponent)

      totalinstructioncount+=instructioncount

    except ValueError:
      num_exceptions += 1
      totalinstructioncount+=instructioncount
      continue

  for component in cpiitems.names:
    if usedcomponents[component]==1:
      usedcpificcomponents.append(component)


  def writeJSON(components, usedcomponents, name):
    jsonoutput = [0 for x in xrange(len(usedcomponents))]
    index=0
    for key in usedcomponents:
      jsonoutput[index]={}
      jsonoutput[index]["name"]=key
      jsonoutput[index]["data"]=[0 for x in xrange(len(groupedintervals))]
      for i in range(0,len(groupedintervals)):
        xvalue = str(components[key][i][1])
        yvalue = str(components[key][i][0])
        jsonoutput[index]["data"][i]=dict(x=xvalue, y=yvalue)
      index+=1
    output = re.sub(r'("[xy]": )"([^\"]*)"',r'\1\2',json.dumps(jsonoutput, indent=4))
    mkdir_p(os.path.join(outputdir,'levels','level2','data'))
    jsonfile = open(os.path.join(outputdir,'levels','level2','data',title+'-'+name+'.json'), "w")
    jsonfile.write(output)
    jsonfile.close()

  writeJSON(cpificcomponents,usedcpificcomponents,'cpific')
  writeJSON(simplifiedcpificcomponents,usedsimplecomponents,'cpificsimple')

  if verbose:
    print
Exemple #4
0
def collectCPIStackDataFCC(verbose = False, requested_cores_list = []):
  from StringIO import StringIO
  instructioncount=0
  num_exceptions=0
  usedcomponents = dict.fromkeys(cpiitems.names,0)

  for i in range(0,num_intervals):
    if verbose:
      print 'Collect CPI stack info for intervals with a fixed time span (interval '+str(i+1)+' / '+str(num_intervals)+')'+"\r",
    currentinterval = ("periodic-"+str(i*interval)+":periodic-"+str((i+1)*interval)).split(":")

    newinstructioncount=getInstructionCount(currentinterval)
    instructioncountlist.append(newinstructioncount)
    instructioncount+=newinstructioncount
    instructioncountsumlist.append(instructioncount)

    try:
      results = cpistack.cpistack_compute(
        config = config,
        stats = stats,
        partial = currentinterval,
        use_simple = False,
        use_simple_mem = True,
        no_collapse = True,
        aggregate = True,
        cores_list = requested_cores_list,
      )
      data = results.get_data('cpi')

      totalcpi=sum(data[0].itervalues())
      if totalcpi > 0:
        ipc = 1./totalcpi
      else:
        ipc = 0

      ipcvalues[0]["data"][i]=dict(x=i*interval/1e9, y=ipc)

      for key in results.labels:
        cpi = data[0][key]
        if totalcpi > 0:
          cpipercentage = 100.*cpi/totalcpi
        else:
          cpipercentage = 0

        if cpi > 0:
          usedcomponents[key]=1
        cpicomponents[key][i][0]=i
        cpicomponents[key][i][1]=cpipercentage
        cpicomponents[key][i][2]=cpi
        simplecomponent = cpiitems.names_to_contributions[key]
        simplifiedcpicomponents[simplecomponent][i][0]=i
        simplifiedcpicomponents[simplecomponent][i][1]+=cpipercentage
        simplifiedcpicomponents[simplecomponent][i][2]+=cpi
        if not simplecomponent in usedsimplifiedcpicomponents:
          usedsimplifiedcpicomponents.append(simplecomponent)

    except ValueError:
      ipcvalues[0]["data"][i]=dict(x=i, y=0)
      num_exceptions += 1
      continue

  for component in cpiitems.names:
    if usedcomponents[component]==1:
      usedcpicomponents.append(component)

  if verbose:
    print
    if(num_exceptions>0):
      print "There was no useful information for "+str(num_exceptions)+" intervals."
      print "You might want to increase the interval size."
def createJSONData(interval,
                   num_intervals,
                   resultsdir,
                   outputdir,
                   title,
                   verbose=False):
    if verbose:
        print 'Generate JSON data for Level 3'

    stats = sniper_stats.SniperStats(resultsdir)
    config = sniper_config.parse_config(
        file(os.path.join(resultsdir, 'sim.cfg')).read())

    ncores = int(config['general/total_cores'])
    if verbose:
        print ncores, "cores detected"

    intervaldata = [0 for x in xrange(num_intervals)]
    num_exceptions = 0
    for i in range(0, num_intervals):
        if verbose:
            print "Parsing interval " + str(i + 1) + "/" + str(
                num_intervals) + "\r",

        try:
            results = cpistack.cpistack_compute(
                config=config,
                stats=stats,
                partial=[
                    "periodic-" + str(i * interval), "periodic-" + str(
                        (i + 1) * interval)
                ],
                use_simple=False,
                use_simple_mem=True,
                no_collapse=False,
                aggregate=False)
            data = results.get_data('cpi')

            intervaldata[i] = [0 for x in xrange(ncores)]

            for core in xrange(ncores):
                if core in results.cores:
                    intervaldata[i][core] = {
                        'time': (i * interval / 1000000),
                        'ipc': 1. / sum(data[core].itervalues())
                    }
                else:
                    intervaldata[i][core] = {
                        'time': (i * interval / 1000000),
                        'ipc': 0
                    }

        except ValueError:
            intervaldata[i] = [0 for x in xrange(ncores)]
            for j in range(0, ncores):
                intervaldata[i][j] = dict(time=(i * interval / 1000000), ipc=0)
            num_exceptions += 1
            continue

    # Write JSON to file
    mkdir_p(os.path.join(outputdir, 'levels', 'level3', 'data'))
    f = open(
        os.path.join(outputdir, 'levels', 'level3', 'data', 'ipcvalues.txt'),
        "w")
    f.write("intervalsize = " + str(interval) + ";\n")
    f.write("ipcvaluestr = '" + json.dumps(intervaldata) + "';")
    f.close()
    f = open(
        os.path.join(outputdir, 'levels', 'level3', 'data', 'ipcvalues.json'),
        "w")
    f.write(json.dumps(intervaldata, indent=4))
    f.close()
    if verbose:
        print
    if (num_exceptions > 0):
        if verbose:
            print("There was no useful information for " +
                  str(num_exceptions) + " intervals.")
            print("You might want to increase the interval size.")
    if verbose:
        print('[OK]')
Exemple #6
0
def createJSONData(interval, num_intervals, resultsdir, outputdir, title, verbose = False):
  if verbose:
    print 'Generate JSON data for Level 3'

  stats = sniper_stats.SniperStats(resultsdir)
  config = sniper_config.parse_config(file(os.path.join(resultsdir, 'sim.cfg')).read())

  ncores = int(config['general/total_cores'])
  if verbose:
    print ncores, "cores detected"

  intervaldata = [0 for x in xrange(num_intervals)]
  num_exceptions=0
  for i in range(0,num_intervals):
    if verbose:
      print "Parsing interval "+str(i+1)+"/"+str(num_intervals)+"\r",

    try:
      results = cpistack.cpistack_compute(
        config = config,
        stats = stats,
        partial = ["periodic-"+str(i*interval),"periodic-"+str((i+1)*interval)],
        use_simple = False,
        use_simple_mem = True,
        no_collapse = False,
        aggregate = False
      )
      data = results.get_data('cpi')

      intervaldata[i] = [0 for x in xrange(ncores)]

      for core in xrange(ncores):
        if core in results.cores:
          intervaldata[i][core] = {'time':(i*interval/1000000), 'ipc':1./sum(data[core].itervalues())}
        else:
          intervaldata[i][core] = {'time':(i*interval/1000000), 'ipc':0}

    except ValueError:
      intervaldata[i] = [0 for x in xrange(ncores)]
      for j in range(0,ncores):
        intervaldata[i][j] = dict(time=(i*interval/1000000), ipc=0)
      num_exceptions += 1
      continue

  # Write JSON to file
  mkdir_p(os.path.join(outputdir,'levels','level3','data'))
  f = open(os.path.join(outputdir,'levels','level3','data','ipcvalues.txt'), "w")
  f.write("intervalsize = "+str(interval)+";\n")
  f.write("ipcvaluestr = '"+json.dumps(intervaldata)+"';")
  f.close()
  f = open(os.path.join(outputdir,'levels','level3','data','ipcvalues.json'), "w")
  f.write(json.dumps(intervaldata, indent=4))
  f.close()
  if verbose:
    print
  if(num_exceptions>0):
    if verbose:
      print("There was no useful information for "+str(num_exceptions)+" intervals.")
      print("You might want to increase the interval size.")
  if verbose:
    print('[OK]')