コード例 #1
0
ファイル: LoadRatePercent.py プロジェクト: adrifloresm/ssplot
  def run_command(args, plt):
    # read in all rate stats
    rate_stats = []
    for stat in args.rate_stats:
      gs = gridstats.GridStats()
      gs.read(stat)
      rate_stats.append(gs)

    # create LoadRate stats object
    lrstats = ssplot.LoadRateStats(
      args.start, args.stop, args.step, rate_stats)

    # read in all hops stats
    hops_stats = []
    for stat in args.hops_stats:
      gs = gridstats.GridStats()
      gs.read(stat)
      hops_stats.append(gs)

    # create LoadHops stats object
    lhstats = ssplot.LoadHopsStats(
      args.start, args.stop, args.step, hops_stats)

    # determine the fields and data labels to plot
    fields = ['Mean', 'Minimal', 'NonMinimal']
    labels = ['Mean', 'Minimal', 'Non-Minimal']

    # gather data
    xdata = lhstats.data['Load']
    mean_rate = lrstats.data['Mean']
    min_percent = lhstats.data['PerMinimal']
    nmin_percent = lhstats.data['PerNonMinimal']
    ydatas = []
    ydatas.append(mean_rate)
    ydatas.append(numpy.multiply(mean_rate, min_percent))
    ydatas.append(numpy.multiply(mean_rate, nmin_percent))

    # create x and y axis labels
    xlabel = 'Injected Rate (%)'
    ylabel = 'Delivered Rate (%)'

    # plot
    mlp = ssplot.MultilinePlot(plt, xdata, ydatas)
    mlp.set_xlabel(xlabel)
    mlp.set_ylabel(ylabel)
    mlp.set_data_labels(labels)
    mlp.apply_args(args, *LoadRatePercent._SKIP)
    mlp.plot(args.plotfile)

    return 0
コード例 #2
0
ファイル: TimeLatency.py プロジェクト: adrifloresm/ssplot
    def run_command(args, plt):
        # create a sample stats object of latencies
        stats = gridstats.GridStats()
        stats.read(args.ifile)

        # determine the fields and data labels to plot
        fields = ssplot.LoadLatencyStats.FIELDS
        if not args.minimum:
            fields.remove('Minimum')
        fields = list(reversed(fields))

        # gather data
        xdata = stats.row_names()
        ydatas = []
        for field in fields:
            ydatas.append(stats.get_column(field))

        # create x and y axis labels
        xlabel = 'Time'
        ylabel = 'Latency'
        if args.units:
            ylabel += ' ({0})'.format(args.units)

        # plot
        mlp = ssplot.MultilinePlot(plt, xdata, ydatas)
        mlp.set_xlabel(xlabel)
        mlp.set_ylabel(ylabel)
        mlp.set_data_labels(fields)
        mlp.apply_args(args, *TimeLatency._SKIP)
        mlp.plot(args.plotfile)

        return 0
コード例 #3
0
ファイル: LoadRate.py プロジェクト: adrifloresm/ssplot
    def run_command(args, plt):
        # read in all stats
        stats = []
        for stat in args.stats:
            gs = gridstats.GridStats()
            gs.read(stat)
            stats.append(gs)

        # create the LoadRate stats object
        lrstats = ssplot.LoadRateStats(args.start, args.stop, args.step, stats)

        # determine fields to plot
        fields = ssplot.LoadRateStats.FIELDS

        # gather data
        xdata = lrstats.data['Injected']
        ydatas = []
        for field in fields:
            ydatas.append(lrstats.data[field])

        # create x and y axis labels
        xlabel = 'Injected Rate (%)'
        ylabel = 'Delivered Rate (%)'

        # plot
        mlp = ssplot.MultilinePlot(plt, xdata, ydatas)
        mlp.set_xlabel(xlabel)
        mlp.set_ylabel(ylabel)
        mlp.set_data_labels(fields)
        mlp.apply_args(args, *LoadRate._SKIP)
        mlp.plot(args.plotfile)

        return 0
コード例 #4
0
ファイル: TimeAverageHops.py プロジェクト: adrifloresm/ssplot
    def run_command(args, plt):
        # create a sample stats object of latencies
        stats = gridstats.GridStats()
        stats.read(args.ifile)

        # determine the fields and data labels to plot
        fields = ['AveMinHops', 'AveHops', 'AveNonMinHops']
        labels = ['Minimal Hops', 'Total Hops', 'Non-Minimal Hops']
        if not args.non_minimal:
            fields = fields[:-1]
            labels = labels[:-1]

        # gather data
        xdata = stats.row_names()
        ydatas = []
        for field in fields:
            ydatas.append(stats.get_column(field))

        # create x and y axis labels
        xlabel = 'Time'
        ylabel = 'Average Hops'

        # plot
        mlp = ssplot.MultilinePlot(plt, xdata, ydatas)
        mlp.set_xlabel(xlabel)
        mlp.set_ylabel(ylabel)
        mlp.set_data_labels(labels)
        mlp.apply_args(args, *TimeAverageHops._SKIP)
        mlp.plot(args.plotfile)

        return 0
コード例 #5
0
  def run_command(args, plt):
    # create a sample stats object of latencies
    stats = gridstats.GridStats()
    stats.read(args.ifile)

    # determine the fields and data labels to plot
    fields = ['PerMinimal', 'PerNonMinimal']
    labels = ['Minimal %', 'Non-Minimal %']

    # gather data
    xdata = stats.row_names()
    ydatas = []
    for field in fields:
      ydatas.append(stats.get_column(field))

    # create x and y axis labels
    xlabel = 'Time'
    ylabel = 'Packets (%)'

    # plot
    mlp = ssplot.MultilinePlot(plt, xdata, ydatas)
    mlp.set_xlabel(xlabel)
    mlp.set_ylabel(ylabel)
    mlp.set_data_labels(labels)
    mlp.apply_args(args, *TimePercentMinimal._SKIP)
    mlp.plot(args.plotfile)

    return 0
コード例 #6
0
    def cable_csv(self, filename):
        """
    This generates a CSV file containing cable information
    """
        # gather raw data
        cable_lengths = sorted(self._cables)
        cable_counts = [self._cables[lng][1] for lng in sorted(self._cables)]
        cable_costs = [
            self._cables[lng][1] * self._cables[lng][0].cost
            for lng in sorted(self._cables)
        ]
        cable_powers = [
            self._cables[lng][1] * self._cables[lng][0].power
            for lng in sorted(self._cables)
        ]

        # create a gridstats object to hold the data
        grid = gridstats.GridStats()
        fields = ['Count', 'Cost ($)', 'Power (W)']
        grid.create('Length(m)', cable_lengths, fields)

        # load all data
        for length, count, cost, power in zip(cable_lengths, cable_counts,
                                              cable_costs, cable_powers):
            grid.set(length, 'Count', count)
            grid.set(length, 'Cost ($)', '{0:.00f}'.format(cost))
            grid.set(length, 'Power (W)', '{0:.00f}'.format(power))

        # write the file
        grid.write(filename)
コード例 #7
0
    def router_csv(self, filename):
        """
    This generates a CSV file containing router information
    """
        # gather raw data
        router_radices = sorted(self._routers)
        router_counts = [
            self._routers[rdx][1] for rdx in sorted(self._routers)
        ]
        router_costs = [
            self._routers[rdx][1] * self._routers[rdx][0].cost
            for rdx in sorted(self._routers)
        ]
        router_powers = [
            self._routers[rdx][1] * self._routers[rdx][0].power
            for rdx in sorted(self._routers)
        ]

        # create a gridstats object to hold the data
        grid = gridstats.GridStats()
        fields = ['Count', 'Cost ($)', 'Power (W)']
        grid.create('Radix', router_radices, fields)

        # load all data
        for radix, count, cost, power in zip(router_radices, router_counts,
                                             router_costs, router_powers):
            grid.set(radix, 'Count', count)
            grid.set(radix, 'Cost ($)', '{0:.00f}'.format(cost))
            grid.set(radix, 'Power (W)', '{0:.00f}'.format(power))

        # write the file
        grid.write(filename)
コード例 #8
0
    def run_command(args, plt):
        # read in all stats
        stats = []
        for stat in args.stats:
            gs = gridstats.GridStats()
            gs.read(stat)
            stats.append(gs)

        # create LoadHops stats object
        lhstats = ssplot.LoadHopsStats(args.start, args.stop, args.step, stats)

        # determine the fields and data labels to plot
        fields = ['PerMinimal', 'PerNonMinimal']
        labels = ['Minimal %', 'Non-Minimal %']

        # gather data
        xdata = lhstats.data['Load']
        ydatas = []
        for field in fields:
            ydatas.append(lhstats.data[field])

        # create x and y axis labels
        xlabel = 'Load (%)'
        ylabel = 'Packets (%)'

        # plot
        mlp = ssplot.MultilinePlot(plt, xdata, ydatas)
        mlp.set_xlabel(xlabel)
        mlp.set_ylabel(ylabel)
        mlp.set_data_labels(labels)
        mlp.apply_args(args, *LoadPercentMinimal._SKIP)
        mlp.plot(args.plotfile)

        return 0
コード例 #9
0
    def run_command(args, plt):
        # check inputs
        gridsPerSet = len(numpy.arange(args.start, args.stop, args.step))
        if len(args.stats) % gridsPerSet != 0:
            print(('The number of stats file for data set is {0},\n'
                   'yet you specified {1} stats files. What gives?').format(
                       gridsPerSet, len(args.stats)))
            return -1
        dataSets = len(args.stats) // gridsPerSet

        # read in all stats
        stats = []
        for stat in args.stats:
            gs = gridstats.GridStats()
            gs.read(stat)
            stats.append(gs)

        # create LoadLatency stats objects
        llstats = []
        for idx in range(dataSets):
            # create the LoadLatencyStats object
            llstat = ssplot.LoadLatencyStats(
                args.start,
                args.stop,
                args.step,
                stats[idx * gridsPerSet:(idx + 1) * gridsPerSet],
                row=args.row)

            # save the object
            llstats.append(llstat)

        # make sure the loads are all the same, gather data
        xdata = llstats[0].data['Load']
        ydatas = []
        assert args.field in ssplot.LoadLatencyStats.FIELDS
        for stat in llstats:
            assert len(xdata) == len(set(xdata).intersection(stat.data['Load'])), \
              '{0} != {1}'.format(mload, stat.data['Load'])
            ydatas.append(stat.data[args.field])

        # create x and y labels
        xlabel = 'Load (%)'
        ylabel = '{0} Latency'.format(args.field)
        if args.units:
            ylabel += ' ({0})'.format(args.units)

        # plot
        mlp = ssplot.MultilinePlot(plt, xdata, ydatas)
        mlp.set_xlabel(xlabel)
        mlp.set_ylabel(ylabel)
        mlp.apply_args(args, *LoadLatencyCompare._SKIP)
        mlp.plot(args.plotfile)

        return 0
コード例 #10
0
ファイル: LoadLatency.py プロジェクト: adrifloresm/ssplot
    def run_command(args, plt):
        # read in all stats
        stats = []
        for stat in args.stats:
            gs = gridstats.GridStats()
            gs.read(stat)
            stats.append(gs)

        # create LoadLatency stats object
        llstats = ssplot.LoadLatencyStats(args.start,
                                          args.stop,
                                          args.step,
                                          stats,
                                          row=args.row)

        # determine the fields to plot
        fields = ssplot.LoadLatencyStats.FIELDS
        if not args.minimum:
            fields.remove('Minimum')
        fields = list(reversed(fields))

        # gather data
        xdata = llstats.data['Load']
        ydatas = []
        for field in fields:
            ydatas.append(llstats.data[field])

        # create x and y axis labels
        xlabel = 'Load (%)'
        ylabel = 'Latency'
        if args.units:
            ylabel += ' ({0})'.format(args.units)

        # plot
        mlp = ssplot.MultilinePlot(plt, xdata, ydatas)
        mlp.set_xlabel(xlabel)
        mlp.set_ylabel(ylabel)
        mlp.set_data_labels(fields)
        mlp.apply_args(args, *LoadLatency._SKIP)
        mlp.plot(args.plotfile)

        return 0
コード例 #11
0
def main(args):
  TOLERANCE = 1e-6

  # read file to find start and end
  filename = args.infile
  opener = gzip.open if filename.endswith('.gz') else open
  lines = 0
  start = float('inf')
  end = 0
  with opener(filename, 'rb') as fd:
    for line in fd:
      line = line.decode('utf-8').strip()
      if line.find('F') != -1:
        cols = line.split(',')
        send_time = int(cols[2])
        recv_time = int(cols[2])
        if args.scalar:
          send_time *= args.scalar
          recv_time *= args.scalar
        if send_time < start:
          start = send_time
        if recv_time > end:
          end = recv_time

  # check times
  if args.mintime and args.maxtime:
    assert args.mintime <= args.maxtime, "start must be <= end"
  if args.mintime:
    assert (args.mintime < end + TOLERANCE and
            args.mintime >= start - TOLERANCE) \
            ("Start [" + str(args.mintime) + "] not in sim range: " +
             str(s) + "-" + str(e))
    start = args.mintime
  if args.maxtime:
    assert (args.maxtime > start - TOLERANCE and
            args.maxtime <= e + TOLERANCE) \
            ("End [" + str(args.maxtime) + "] not in sim range: " +
             + str(s) + "-" + str(e))
    end = args.maxtime
  if start == float('inf') or end == 0:
    outfile = args.outfile
    opener = gzip.open if outfile.endswith('.gz') else open
    with opener(outfile, 'wb') as fd:
      fd.write(''.encode('utf-8'))
    exit(0)

  # create buckets
  numBins = args.buckets
  binWidth = (end - start) / numBins
  binTimesOrg = numpy.linspace(start, end - binWidth, numBins)
  binTimes = numpy.append(binTimesOrg, end)

  print("Running ssparse for range {0}-{1} with {2} bins"
        .format(start, end, numBins))
  # call bin -> tmp file
  hopFiles = []
  latFiles = []
  error = None
  for idx in range(numBins):
    b_start = binTimes[idx]
    b_end = binTimes[idx+1]

    hopfile_fd, hopfile_name = tempfile.mkstemp(prefix='trans_')
    latfile_fd, latfile_name = tempfile.mkstemp(prefix='trans_')
    os.close(hopfile_fd)
    os.close(latfile_fd)
    hopFiles.append(hopfile_name)
    latFiles.append(latfile_name)

    # ssparse cmd
    cmd = ('{0} -c {1} -l {2} -f +{3}={4}-{5} {6}'
           .format(args.ssparse,
                   hopfile_name,
                   latfile_name,
                   args.time, b_start, b_end,
                   args.infile))
    if args.scalar:
      cmd += (' -s {0}'.format(args.scalar))

    if args.filters:
      for filter in args.filters:
        cmd += ' -f {0}'.format(filter)

    try:
      subprocess.check_call(cmd, shell=True)
    except subprocess.CalledProcessError:
      error = True
    if error:
      break

  if error:
    assert(len(hopFiles) == len(latFiles))
    for hopfile, latfile in zip(hopFiles,latFiles):
      os.remove(hopfile)
      os.remove(latfile)
    exit(-1)

  # headers
  uColsLat = []
  gridsLat = []
  uColsHop = []
  gridsHop = []
  assert(len(hopFiles) == len(latFiles))
  for hopfile, latfile in zip(hopFiles,latFiles):
    gLat = gridstats.GridStats()
    gLat.read(latfile)
    gridsLat.append(gLat)
    currColsLat = gLat.column_names()

    gHop = gridstats.GridStats()
    gHop.read(hopfile)
    gridsHop.append(gHop)
    currColsHop = gHop.column_names()

    for x in currColsLat:
      if x not in uColsLat:
        uColsLat.append(x)

    for x in currColsHop:
      if x not in uColsHop:
        uColsHop.append(x)

  # sort hops
  PerHops = []
  PerMinHops = []
  PerNonMinHops = []
  for x in uColsHop:
    if "PerHops" in x:
      PerHops.append(x)
    if "PerMinHops" in x:
      PerMinHops.append(x)
    if "PerNonMinHops" in x:
      PerNonMinHops.append(x)

  sColsHop = ['AveHops']
  sColsHop.extend(PerHops)
  sColsHop.append('AveMinHops')
  sColsHop.append('PerMinimal')
  sColsHop.extend(PerMinHops)
  sColsHop.append('AveNonMinHops')
  sColsHop.append('PerNonMinimal')
  sColsHop.extend(PerNonMinHops)

  # delete tmp files
  for hopfile, latfile in zip(hopFiles,latFiles):
    os.remove(hopfile)
    os.remove(latfile)

  # write out.csv
  fGrid = gridstats.GridStats()
  fGrid.create('Time', binTimesOrg, sColsHop + uColsLat)

  assert len(gridsLat) == len(binTimesOrg) and len(gridsHop) == len(binTimesOrg)
  for gridLat, gridHop, binTime in zip(gridsLat, gridsHop, binTimesOrg):
    for colHop in uColsHop:
      value = gridHop.get('Packet', colHop, default='nan')
      fGrid.set(binTime, colHop, value)
    for colLat in uColsLat:
      value = gridLat.get('Packet', colLat, default='nan')
      fGrid.set(binTime, colLat, value)
  fGrid.write(args.outfile)