Added the first draft for distributed benchmarking.

This commit is contained in:
Roberto Agostino Vitillo 2014-03-04 20:50:30 +00:00
Родитель 03631d4e49
Коммит e1d106791c
3 изменённых файлов: 138 добавлений и 30 удалений

Просмотреть файл

@ -2,12 +2,16 @@ import os
import argparse
import json
import platform
import zmq
import time
import pickle
from wrappers.PowerGadget import PowerGadget
from wrappers.BLA import BLA
from browser import Browser
from time import sleep
from pandas import DataFrame, concat
from server import Server
class Benchmark:
def __init__(self, args):
@ -18,25 +22,26 @@ class Benchmark:
def log(self):
df = None
for page in self._get_pages():
for browser in self._get_browsers():
browser = Browser.create_browser(name=browser["name"], path=browser["path"], page=page)
args.image = os.path.basename(browser.get_path())
browser.initialize()
partial = None
sleep(self._args.sleep)
for benchmark in self._get_benchmarks():
benchmark = Benchmark._create_benchmark(benchmark, self._args)
partial = self.run(benchmark, browser, partial)
browser.finalize()
df = partial if df is None else concat([df, partial])
df = self._run_iteration(df, page, browser)
return df
def run(self, benchmark, browser, partial):
def _run_iteration(self, df, page, browser):
browser = Browser.create_browser(name=browser["name"], path=browser["path"], page=page)
args.image = os.path.basename(browser.get_path())
browser.initialize()
partial = None
sleep(self._args.sleep)
for benchmark in self._get_benchmarks():
benchmark = Benchmark._create_benchmark(benchmark, self._args)
partial = self._run_benchmark(benchmark, browser, partial)
browser.finalize()
return partial if df is None else concat([df, partial])
def _run_benchmark(self, benchmark, browser, partial):
df = benchmark.log()
df['Browser'] = browser.get_name()
df['Page'] = browser.get_page()
@ -64,8 +69,47 @@ class Benchmark:
def _get_benchmarks(self):
return self._config["Benchmarks"]
class ClientBenchmark(Benchmark):
def __init__(self, args):
self._context = zmq.Context()
self._socket = self._context.socket(zmq.REQ)
self._socket.connect("tcp://" + args.address + ":8888")
self._socket.setsockopt(zmq.RCVTIMEO, 300000)
try:
header, payload = self._send("get_configuration")
self._args, self._config = payload
except:
self._context.destroy(0)
raise Exception("Failure to connect to server: timeout")
def log(self):
df = None
while True:
try:
header, payload = self._send("pull", platform.system())
except zmq.error.Again:
self._context.destroy(0)
print("Warning: premature termination, server not reachable")
break
if header == "end":
break
page, browser = payload
df = self._run_iteration(df, page, browser)
return df
def _send(self, header, payload = None):
msg = pickle.dumps((header, payload))
self._socket.send(msg)
return pickle.loads(self._socket.recv())
if __name__ == "__main__":
parser= argparse.ArgumentParser(description="External browser benchmark suite",
parser= argparse.ArgumentParser(description="Desktop Browser Power benchmarking Utility",
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("-e", "--resolution", help="Sampling resolution in ms, if applicable", default=100, type=int)
@ -76,17 +120,33 @@ if __name__ == "__main__":
parser.add_argument("-b", "--benchmark", help="Benchmark to run", default="idle")
parser.add_argument("-c", "--config", help="Configuration file", default="config.json")
parser.add_argument("-s", "--sleep", help="Seconds to sleep before the benchmarks start recording", default=120, type=int)
parser.add_argument("-r", "--is_server", dest="is_server", action="store_true")
parser.add_argument("-a", "--address", help="Server address", default=None)
parser.set_defaults(is_server=False)
args = parser.parse_args()
benchmark = None
if args.benchmark == "idle":
benchmark = Benchmark(args)
elif args.benchmark == "PowerGadget":
benchmark = PowerGadget(args)
elif args.benchmark == "BLA":
benchmark = BLA(args)
if args.is_server:
server = Server(args)
server.run()
else:
raise Exception("Benchmark not found")
benchmark = None
df = benchmark.log()
df.to_csv(args.output, float_format="%.3f")
if args.benchmark == "idle":
if args.address is None:
benchmark = Benchmark(args)
else:
benchmark = ClientBenchmark(args)
elif args.benchmark == "PowerGadget":
benchmark = PowerGadget(args)
elif args.benchmark == "BLA":
benchmark = BLA(args)
else:
raise Exception("Benchmark not found")
df = benchmark.log()
if df is not None:
df.to_csv(args.output, float_format="%.3f")
else:
print("Warning: no output produced")

48
server.py Normal file
Просмотреть файл

@ -0,0 +1,48 @@
import zmq
import json
import pickle
context = zmq.Context()
class Server:
def __init__(self, args):
self._args = args
with open(args.config) as f:
self._config = json.load(f)
self._socket = context.socket(zmq.REP)
self._socket.bind("tcp://*:8888")
self._get_next_page = {"Darwin": self._page_generator("Darwin"),
"Linux": self._page_generator("Linux"),
"Windows": self._page_generator("Windows")}
def _page_generator(self, os):
for page in self._get_pages():
for browser in self._get_browsers(os):
yield page, browser
def _get_pages(self):
return self._config["Pages"]
def _get_browsers(self, os):
return self._config["OS"][os]
def run(self):
while True:
header, payload = pickle.loads(self._socket.recv())
if header == "get_configuration":
self._send("config", (self._args, self._config))
continue
try:
assert(header == "pull")
page, browser = next(self._get_next_page[payload])
self._send("page", (page, browser))
except StopIteration:
self._send("end")
def _send(self, header, payload = None):
msg = pickle.dumps((header, payload))
self._socket.send(msg)

Просмотреть файл

@ -76,10 +76,10 @@ class PowerGadget(Wrapper):
def _parse(self):
summary = {"Processor Watt" : 0,
"Processor Joules": 0,
"IA Watt": 0,
"IA Joules": 0,
"GT Watt": 0,
"GT Joules": 0}
"IA Watt": float('nan'),
"IA Joules": float('nan'),
"GT Watt": float('nan'),
"GT Joules": float('nan')}
regexps = {"Processor Watt" : re.compile(".* Processor Power_0 \(Watt\) = (.*)"),
"Processor Joules": re.compile(".* Processor Energy_0 \(Joules\) = (.*)"),