#! /usr/bin/env python3 # # Perforce benchmarks using Locust.io framework # # Copyright (C) 2016, Robert Cowham, Perforce # from __future__ import print_function import os import sys import logging from locust import Locust, events, task, TaskSet from locust.exception import StopLocust import P4 from p4benchutils import popen, fmtsize, readConfig, Timer, P4Benchmark from locust.stats import RequestStats def noop(*arg, **kwargs): logger.info("Stats reset prevented by monkey patch!") RequestStats.reset_all = noop python3 = sys.version_info[0] >= 3 logger = logging.getLogger("p4_basic") startdir = os.getcwd() CONFIG_FILE = "config_p4_basic.yml" # Configuration parameters class P4BasicBenchmark(P4Benchmark): """Performs basic benchmark test - Perforce specific subclass""" def __init__(self, startdir, config): super(P4BasicBenchmark, self).__init__(logger, startdir, config, "basicActions") def basicActions(bench, request_type): "Basic actions does sync/resolve/revert and then add/edit/delete" t = Timer(request_type) name = "actions" try: count = bench.basicFileActions() t.report_success(name, count) except Exception as e: logger.exception(e) t.report_failure(name, e) def reportingActions(bench, request_type): "Does describe/fstat/filelog" t = Timer(request_type) name = "reporting" try: count = bench.reportingActions() t.report_success(name, count) except Exception as e: logger.exception(e) t.report_failure(name, e) class AllTasks(TaskSet): """Entry point for locust""" min_wait = 1000 max_wait = 3000 request_type = "p4" def __init__(self, *args, **kwargs): super(AllTasks, self).__init__(*args, **kwargs) self.config = readConfig(startdir, CONFIG_FILE) self.min_wait = self.config["general"]["min_wait"] self.max_wait = self.config["general"]["max_wait"] self.repeat_count = 0 if "repeat" in self.config["perforce"]: self.repeat_count = self.config["perforce"]["repeat"] self.count = 0 self.task_name = "p4basic" self.bench = P4BasicBenchmark(startdir, self.config) def on_start(self): count = 0 t = Timer(self.request_type) name = "create" try: self.bench.createWorkspace() count = 1 t.report_success(name, count) except Exception as e: logger.exception(e) t.report_failure(name, e) t = Timer(self.request_type) name = "sync" try: count = self.bench.syncWorkspace(t) t.report_success(name, count) except Exception as e: logger.exception(e) t.report_failure(name, e) @task(10) def basicActions(self): basicActions(self.bench, self.task_name) logger.info("Finished %s" % self.task_name) self.count += 1 if self.repeat_count and self.count >= self.repeat_count: raise StopLocust(self.task_name) # Die if done @task(10) def reportingActions(self): "Run describe, filelog and fstat" reportingActions(self.bench, self.task_name) logger.info("Finished %s" % self.task_name) self.count += 1 if self.repeat_count and self.count >= self.repeat_count: raise StopLocust(self.task_name) # Die if done class P4RepoTestLocust(Locust): """Will be imported and then run by locust""" task_set = AllTasks
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#5 | 25529 | Robert Cowham |
Latest copy of files including docker compose setup. Merging //guest/robert_cowham/p4benchmark/pb/... to //guest/robert_cowham/p4benchmark/main/... |
||
#4 | 24755 | Robert Cowham |
Fix repeat implementation. Reset local file list after delete |
||
#3 | 24754 | Robert Cowham |
Only sync workspace once. Implement repeat count. |
||
#2 | 24727 | Robert Cowham | Refactored | ||
#1 | 24711 | Robert Cowham | Restructure and tidy up | ||
//guest/robert_cowham/p4benchmark/main/p4_basic.py | |||||
#4 | 24705 | Robert Cowham | Use createfiles functions | ||
#3 | 22135 | Robert Cowham | Python3 has no unicode | ||
#2 | 22134 | Robert Cowham | Python3 has no unicode | ||
#1 | 22132 | Robert Cowham | Basic test | ||
//guest/robert_cowham/p4benchmark/main/p4_test.py | |||||
#1 | 22129 | Robert Cowham | New file for basic |