def testExportSteps(self): manager = Manager() stepsStats = dict() for project in manager.listProjects(): projectFolder = manager.getProjectPath(project.projName) project = Project(pyworkflow.Config.getDomain(), projectFolder) project.load() for prot in project.getRuns(): protName = prot.getClassName() for step in prot.loadSteps(): stepName = "-".join([ prot.getClassPackageName(), protName, step.funcName.get() ]) stepSeconds = step.getElapsedTime().total_seconds() if stepName not in stepsStats: stepsStats[stepName] = [] stepsStats[stepName].append(stepSeconds) # average steps for name in stepsStats: plugin, protClass, step = name.split("-") stepStats = stepsStats[name] mean = sum(stepStats) / len(stepStats) # DO not send mean values if higher than a threshold to keep chart in a decent visualization range # We are loosing long duration steps, probably due to large if mean < 30: bm = Benchmark(time=mean, name="-".join([protClass, step])) codespeed.sendData(bm)
def measureSetIteration(set, performanceTag): """ Measures the time taken to iterate over the set passed. :parameter set set to iterate on :parameter performanceTag: text to name the benchmark""" iterT = Timer() iterT.tic() for item in set.iterItems(): pass iterT.toc() bm = Benchmark(time=iterT.getElapsedTime().total_seconds(), name="Iteration-%s" % performanceTag) codespeed.sendData(bm)
def testUsingGet(self): """ This benchmarks the time accessing an item as a dictionary, like set[id].""" items = 100 soc = createSet(SetOfCoordinates) createItems(soc, self.basiccoordsFactory, numberofitems=items) t = Timer("A %s Set.__item__ calls" % items) t.tic() for id in range(1, items + 1): soc[id] t.toc() bm = Benchmark(time=t.getElapsedTime().total_seconds(), name="A %s Set.__item__ calls" % items) codespeed.sendData(bm)
def testLoadProjectGUI(self): t = Timer() localProjects = self.findProjects() t.tic() for projectFolder in localProjects: print("Profiling %s" % projectFolder) project = pwobj.Project(pw.Config.getDomain(), os.path.join(self.projectsPath, projectFolder)) try: project.load() canvas = self.createCanvas() runsGraph = self.getRunsGraph(project) layout = pwgui.LevelTreeLayout() canvas.drawGraph(runsGraph, layout, drawNode=None) loadProjectTime = t.getElapsedTime() bm = Benchmark(time=loadProjectTime.total_seconds(), name="Load project %s with GUI with %s protocols" % ( projectFolder, self.numberofprotocols)) codespeed.sendData(bm) except Exception as e: print("Error loading the project %s" % projectFolder)
def createItems(set, itemfactory, numberofitems=100000, performanceTag=None): """ Create X items using numberofitems and the itemfactory method and reports its instantiation time and persistence time to the benchmark server :parameter set: Set instance to be used :parameter itemfactory: method to call to create a specific item. Receives the index of the iteration :parameter performanceTag: tag to use to create the benchmark name""" # To hold sum elapsed time creation = timedelta() append = timedelta() t = Timer() for i in range(numberofitems): t.tic() newItem = itemfactory(i) creation += t.getElapsedTime() t.tic() set.append(newItem) append += t.getElapsedTime() set.write() if performanceTag: bm = Benchmark(time=creation.total_seconds(), name="Instantiation of %s %s" % (numberofitems, performanceTag)) codespeed.sendData(bm) bm = Benchmark(time=append.total_seconds(), name="Persistence of %s %s" % (numberofitems, performanceTag)) codespeed.sendData(bm) measureSetIteration(set, performanceTag)