def __init__(self, workdir=None, logfile=None, pt_job_title=None, pt_server_url=None): self.workdir = workdir if workdir else os.path.join(gettempdir(), "%s.%d" % (basename, os.getpid())) self.logfile = logfile self.opts = None self.urls = [] self.pt_suite = ptSuite("UI crawler job" if pt_job_title is None else pt_job_title, pt_server_url=pt_server_url)
def main(): op = OptionParser("PerfTracker suite example", description="%program [options] URL1 [URL2 [...]]") op.add_option("-v", "--verbose", action="store_true", help="enable verbose mode") op.add_option("-c", "--concurrency", default="1,4,16", help="comma separated list of concurrencies to use") op.add_option("-n", "--requests", default=100, type=int, help="total number of requests to execute on every step") op.add_option("-i", "--iterations", default=3, type=int, help="number of iterations for every test") suite = ptSuite(suite_ver="1.0.0", product_name="My web site", product_ver="1.0-1234") suite.addOptions(op) opts, urls = op.parse_args() if not urls: op.print_help() print("Example:\n %s http://www.google.com/" % basename) sys.exit(EXIT_NOR_URLS) loglevel = logging.DEBUG if opts.verbose else logging.INFO logging.basicConfig( level=loglevel, format="%(asctime)s - %(module)s - %(levelname)s - %(message)s") suite.handleOptions(opts) ab = ABLauncher( suite, urls, concurrencies=[int(c.strip()) for c in opts.concurrency.split(",")], requests=opts.requests, iterations=opts.iterations) ab.init() ab.launch()
def main(): op = OptionParser("PerfTracker suite example", description="%program [options] URL1 [URL2 [...]]") op.add_option("-v", "--verbose", action="store_true", help="enable verbose mode") op.add_option( "-c", "--concurrency", default="1,2,4", help="comma separated list of concurrencies to use, default: %default") op.add_option( "-n", "--requests", default=0, type=int, help= "limit every test by given number of requests (time limit is default, see -t)" ) op.add_option("-i", "--iterations", default=3, type=int, help="number of iterations for every test") op.add_option("-f", "--from-file", default="", help="get URLs from given file") op.add_option( "-t", "--time", default=5, type=int, help="limit every test by given time (sec), default %default") suite = ptSuite(suite_ver="1.0.0", product_name="My web site", product_ver="1.0-1234") suite.addOptions(op) opts, urls = op.parse_args() if opts.from_file: f = open(opts.from_file, 'r') urls = f.readlines() f.close() if not urls: op.print_help() print("Example:\n %s http://www.google.com/" % basename) sys.exit(EXIT_NO_URLS) loglevel = logging.DEBUG if opts.verbose else logging.INFO logging.basicConfig( level=loglevel, format="%(asctime)s - %(module)s - %(levelname)s - %(message)s") suite.handleOptions(opts) ab = ABLauncher( suite, urls, concurrencies=[int(c.strip()) for c in opts.concurrency.split(",")], requests=opts.requests, iterations=opts.iterations, time=opts.time) ab.init() ab.launch()
group=g, metrics="seconds", scores=[344, 329, 351])) suite.upload() if __name__ == "__main__": op = OptionParser("PerfTracker suite example") op.add_option("-v", "--verbose", action="store_true", help="enable verbose mode") suite = ptSuite(suite_ver="1.0.0", product_name="My web app", product_ver="1.0-1234") suite.addOptions(op) opts, args = op.parse_args() loglevel = logging.DEBUG if opts.verbose else logging.INFO logging.basicConfig( level=loglevel, format="%(asctime)s - %(module)s - %(levelname)s - %(message)s") suite.handleOptions(opts) main(suite)
group=group, category=volume, metrics="accounts/sec", duration_sec=540, description= "PUT /accounts in 16 threads (update 1600 accounts)", scores=[320 - 0.1 * sqrt(accounts_in_db + 10) ])) # fake score suite.upload() if __name__ == "__main__": op = OptionParser("PerfTracker suite example") op.add_option("-v", "--verbose", action="store_true", help="enable verbose mode") suite = ptSuite(suite_ver="1.0.0", product_name="Account Server", product_ver="1.0-1234") suite.addOptions(op) opts, args = op.parse_args() logging.basicConfig(level=logging.DEBUG if opts.verbose else logging.INFO) suite.handleOptions(opts) main(suite)
ptTest("Simple benchmark", description="A simple benchmark output", metrics="loops/sec", scores=[random.randint(10, 20) / 10.0], loops=100)) suite.upload() if __name__ == "__main__": op = OptionParser("PerfTracker suite example") op.add_option("-v", "--verbose", action="store_true", help="enable verbose mode") suite = ptSuite(suite_ver="1.0.0", product_name="My product", product_ver="1.0-123", project_name="Default project") opts, args = op.parse_args() loglevel = logging.DEBUG if opts.verbose else logging.INFO logging.basicConfig( level=loglevel, format="%(asctime)s - %(module)s - %(levelname)s - %(message)s") main(suite)
def main(): usage = "usage: %prog [options] -- command line" description = """ The %%prog laucnhes given command line an parse output in the following format: 1. Text format (default): mandatory fields: tag: $STR; score: $FLOAT; tag: $STR; score: $FLOAT; ... optional fields: time: $FLOAT; metrics: $STR; loops: $INT; cmdline: $STR; less_better: true; errors: $INT; warnings: $INT; group: $STR; category: $STR; 2. JSON format (-j) [ { /* Mandatory fields */ "name": "string", "score": float, /* Optional fields */ "time": float, /* seconds */ "metrics": "string", "loops": int, "cmdline": "string", "less_better": true, "errors": int, "warnings": int, "group": "string", "category": "string" }, { ... } ] """ op = OptionParser(description=description, usage=usage, formatter=formatter()) op.add_option("-v", "--verbose", action="store_true", help="enable verbose mode") op.add_option("-j", "--json", action="store_true", help="treat input data as json") op.add_option("-f", "--file", help="get results from file, not from command line") suite = ptSuite() suite.addOptions(op) opts, args = op.parse_args() loglevel = logging.DEBUG if opts.verbose else logging.INFO logging.basicConfig( level=loglevel, format="%(asctime)s - %(module)17s - %(levelname).3s - %(message)s", datefmt='%H:%M:%S') suite.handleOptions(opts) if not opts.file and len(args) == 0: op.print_usage() print("error: command line is required") sys.exit(-1) run(suite, opts.json, opts.file, subprocess.list2cmdline(args))