示例#1
0
文件: lxc.py 项目: kopchik/perftest
 def create(self):
   if exists(self.root):
     raise Exception(s("Cannot create snapshot: path exists: ${self.root}"))
   sudo(s("btrfs subvolume snapshot ${self.tpl} ${self.root}"))
   os.makedirs(s("/var/lib/lxc/${self.name}/"))
   with open(s("/var/lib/lxc/${self.name}/config"), 'w') as fd:
     data = s(TPL)
     fd.write(data)
     if self.cpus:
       strcpus = ",".join(map(lambda x: str(x), self.cpus))
       fd.write("lxc.cgroup.cpuset.cpus = %s\n" % strcpus)
示例#2
0
def regen(datadir, outputdir, sibling=True, quiet=True):
  for bg in benches:
    for fg in benches:
      try:
        os.makedirs(s("${outputdir}/${bg}"))
      except FileExistsError:
        pass

      out = s("${outputdir}/${bg}/${fg}.png")
      single = s("${datadir}/single/${fg}")
      if sibling: double = s("${datadir}/double/${bg}/${fg}")
      else:       double = s("${datadir}/double_far/${bg}/${fg}")
      # print("perf bars params:", out, single, double)
      annotations = [fg+" alone", fg+"+"+bg]
      perfbars([single, double], output=out, annotations=annotations, quiet=True)
示例#3
0
文件: snm.py 项目: kopchik/snm
 def disconnect(self, ev=None):
     if self.pipe:
         run_(s("dhcpcd ${self.interface.name} -k"))
         try:
             self.pipe.wait(3)
         except TimeoutExpired:
             self.pipe.kill()
     self.pipe = None
示例#4
0
def double(prefix, far=True):
  topology = CPUTopology()
  if far:
    cpu, bgcpu = topology.cpus_no_ht[:2]
  else:
    cpu = topology.cpus_no_ht[0]
    bgcpu = topology.ht_siblings[cpu][0]

  with cgmgr:
    vm = cgmgr.start(str(cpu))
    bgvm = cgmgr.start(str(bgcpu))
    time.sleep(BOOT_TIME)

    rpc = retry(rpyc.connect, args=(str(vm.addr),), kwargs={"port":6666}, retries=10)
    bgrpc = retry(rpyc.connect, args=(str(bgvm.addr),), kwargs={"port":6666}, retries=10)

    RPopen = rpc.root.Popen
    BGRPopen = bgrpc.root.Popen

    remains = len(benchmarks)**2

    for bgname, bgcmd in benchmarks.items():
      log.debug("waiting for idleness")
      wait_idleness(IDLENESS*3.3)
      log.warning("launching %s in bg" % bgname)
      bg = BGRPopen(bgcmd)
      log.debug("warming up for %s" % WARMUP_TIME)
      time.sleep(WARMUP_TIME)

      for name, cmd in benchmarks.items():
        print("remains %s tests" % remains)
        remains -= 1

        outdir = s("${prefix}/double/${bgname}/")
        try: os.makedirs(outdir)
        except FileExistsError: pass

        output =  outdir + name
        perf_cmd = PERF_CMD.format(pid=vm.pid, t=MEASURE_TIME, events=events, output=output)
        log.debug("starting %s" % name)
        p = RPopen(cmd)
        log.debug("warming up for %s" % WARMUP_TIME)
        time.sleep(WARMUP_TIME)
        log.debug("starting measurements")
        run(perf_cmd)
        assert p.poll() is None, "test unexpectedly terminated"
        assert bg.poll() is None, "bg process suddenly died :("
        log.debug("finishing tests")
        p.killall()
        gc.collect()
      bg.killall()
      time.sleep(1)
示例#5
0
def single(vm, prefix):
  outdir = s("${prefix}/single/")
  if not exists(outdir):
    makedirs(outdir)

  remains = len(basis)
  for name, cmd in basis.items():
    log.debug("remains %s tests" % remains)
    remains -= 1
    outfile = s("${prefix}/single/${name}")

    log.debug("waiting for idleness")
    wait_idleness(IDLENESS*2.3)
    log.debug("starting %s" % name)
    p = vm.Popen(cmd)
    log.debug("warming up for %s" % WARMUP_TIME)
    time.sleep(WARMUP_TIME)
    log.debug("starting measurements")
    vm.stat(outfile)
    assert p.poll() is None, "test unexpectedly terminated"
    log.debug("finishing test")
    p.killall()
    gc.collect()
示例#6
0
文件: snm.py 项目: kopchik/snm
 def run(self):
     while True:
         try:
             result = []
             raw = run(s(
                 "wpa_cli -i ${self.ifname} scan_results")).splitlines()
             rawfields = raw.pop(0)
             fields = rawfields.split(" / ")
             for line in raw:
                 data = line.split('\t')
                 result.append(Struct(**dict(zip(fields, data))))
             self.result = result  # atomic update
             [print(bs) for bs in result]
         except Exception as e:
             log.error(e)
             sleep(1)
         sleep(5)
示例#7
0
def analyze_reverse(ref, exp, prec:float=0.95, maxtries:int=50, mode='hist', confidence:float=0.9):
  refdata = pickle.load(open(ref, 'rb')).result
  expdata = pickle.load(open(exp, 'rb')).result
  # unpack reference data
  for k,v in refdata.items():
    refdata[k] = v[0]

  # HIST
  if mode == 'hist':
    for i, (test, truevalue) in enumerate(refdata.items(), 1):
      measurements = expdata[test]
      label = " -> ".join(test)
      p.subplot(12,1,i)
      p.xlim(0,2)
      p.hist(measurements, bins=50, label=label, normed=True, histtype='stepfilled', linewidth=2, alpha=0.7)
    p.subplots_adjust(left=0, right=1, top=1, bottom=0)
  # MONTE CARLO
  elif mode == 'montecarlo':
    results = []
    failures = 0
    for test, truevalue in refdata.items():
      for _ in range(1000):
        samples = []
        for x in range(maxtries):
          samples.append(choice(expdata[test]))
          # samples.append(random())  # absolute random junk
          if precision(samples, truevalue) > prec:
            num = len(samples)
            if num > 50: print("achtung!")
            results.append(num)
            # print(truevalue, samples)
            break
        else:
          # we failed to achieve precision
          failures += 1
    frate = failures/(len(results)+failures)
    print("-= for precision %s =-" % prec)
    print("mean={:.2f}({:.0%}), failure rate={:.2%}".format(mean(results), pstdev(results), frate))
  # CONFIDENCE INTERVAL
  elif mode == 'ci':
    for test, truevalue in sorted(refdata.items()):
      ci = ci_student(expdata[test], confidence=0.95)
      print("{}: ci {:.2%}".format(test, ci))
  else:
    sys.exit(s("unknown mode ${mode}"))
示例#8
0
文件: snm.py 项目: kopchik/snm
 def down(self):
     run_(s("ifconfig ${self.name} down"))
     run_(s("ifconfig ${self.name} 0.0.0.0"))
     if self.promisc:
         run(s("ifconfig ${self.name} promisc off"))
示例#9
0
文件: snm.py 项目: kopchik/snm
 def connect(self, network):
     nid = self.run("ADD_NETWORK")
     for cmd in network.wpacfg():
         self.run(s("SET_NETWORK ${nid} ${cmd}"))
     self.run(s("SELECT_NETWORK ${nid}"))
     self.run(s("ENABLE_NETWORK ${nid}"))
示例#10
0
文件: snm.py 项目: kopchik/snm
 def __init__(self, ifname, interval=5):
     self.ifname = ifname
     self.result = []
     run(s("wpa_cli -i ${self.ifname} scan_interval ${interval}"))
     run(s("wpa_cli -i ${self.ifname} scan"))
     super().__init__(daemon=True)
示例#11
0
文件: snm.py 项目: kopchik/snm
 def connect(self, ev=None):
     self.interface.up()
     self.pipe = runbg(s("dhcpcd -t 5 -B ${self.interface.name}"))
     self.hook.waitpid(self.pipe.pid, lambda ev: log.debug("dhcp died"))
     self.hook.waitpid(self.pipe.pid, self.disconnect)
示例#12
0
文件: lxc.py 项目: kopchik/perftest
 def destroy(self):
   self.stop(t=1)
   sudo_(s("lxc-destroy -n ${self.name} -f"))
   if exists(self.root):
     sudo(s("btrfs subvolume delete ${self.root}"))
     sudo_(s("rm -rf ${self.root}"))
示例#13
0
文件: snm.py 项目: kopchik/snm
 def up(self, promisc=False):
     run(s("ifconfig ${self.name} up"))
     if promisc or self.promisc:
         run(s("ifconfig ${self.name} promisc on"))
示例#14
0
文件: pratt.py 项目: kopchik/truthon
 def __repr__(self):
   cls = self.__class__.__name__
   return s("(${cls} ${self.left} ${self.right})")
示例#15
0
文件: lxc.py 项目: kopchik/perftest
 def stop(self, t=10):
   sudo_(s("lxc-stop -n ${self.name} -t ${t}"))
示例#16
0
文件: lxc.py 项目: kopchik/perftest
 def unfreeze(self):
   sudo(s("lxc-unfreeze -n ${self.name}"))
示例#17
0
文件: lxc.py 项目: kopchik/perftest
 def freeze(self):
   sudo(s("lxc-freeze -n ${self.name}"))
示例#18
0
文件: lxc.py 项目: kopchik/perftest
 def start(self):
   #if self.started:
   #  return
   sudo(s("lxc-start -n ${self.name} -d"))