1import time 2from autotest_lib.client.common_lib import error 3from autotest_lib.client.bin import test, utils 4 5 6class profiler_test(test.test): 7 version = 2 8 9 10 def initialize(self, profiler=None, profiler_args=(), profiler_dargs=None): 11 """ 12 Initialize this test with the profiler name, args and dargs. 13 14 @param profiler: Profiler name. 15 @param profiler_args: Profiler non-keyword arguments. 16 @param profiler_dargs: Profiler keyword arguments. 17 """ 18 if not profiler: 19 raise error.TestError('No profiler specified.') 20 self._profiler = profiler 21 self._profiler_args = profiler_args 22 self._profiler_dargs = profiler_dargs or {} 23 24 25 def execute(self, seconds=5): 26 """ 27 Add and start the profiler, sleep some seconds, stop and delete it. 28 29 We override "execute" and not "run_once" because we need to control 30 profilers here and in "run_once" it would be too late for that. 31 32 @param seconds: Number of seconds to sleep while the profiler is 33 running. 34 """ 35 profilers = self.job.profilers 36 profilers.add(self._profiler, *self._profiler_args, 37 **self._profiler_dargs) 38 profilers.start(self) 39 40 time.sleep(seconds) 41 42 profilers.stop(self) 43 profilers.report(self) 44 # TODO: check for profiler result files? 45 profilers.delete(self._profiler) 46