blob: 38bc9b531abce16111c0ed5e467a8e9ebf1304ad [file] [log] [blame]
mbligh15971eb2009-12-29 02:55:23 +00001import itertools
jadmanski91cd58c2008-12-02 15:34:53 +00002import common
3
jadmanski043e1132008-11-19 17:10:32 +00004
mbligh15971eb2009-12-29 02:55:23 +00005def _get_unpassable_types(arg):
jadmanski043e1132008-11-19 17:10:32 +00006 """ Given an argument, returns a set of types contained in arg that are
7 unpassable. If arg is an atomic type (e.g. int) it either returns an
8 empty set (if the type is passable) or a singleton of the type (if the
9 type is not passable). """
10 if isinstance(arg, (basestring, int, long)):
11 return set()
12 elif isinstance(arg, (list, tuple, set, frozenset, dict)):
13 if isinstance(arg, dict):
14 # keys and values must both be passable
15 parts = itertools.chain(arg.iterkeys(), arg.itervalues())
16 else:
17 # for all other containers we just iterate
18 parts = iter(arg)
19 types = set()
20 for part in parts:
mbligh15971eb2009-12-29 02:55:23 +000021 types |= _get_unpassable_types(part)
jadmanski043e1132008-11-19 17:10:32 +000022 return types
23 else:
24 return set([type(arg)])
25
26
mbligh15971eb2009-12-29 02:55:23 +000027def _validate_args(args):
jadmanski043e1132008-11-19 17:10:32 +000028 """ Validates arguments. Lists and dictionaries are valid argument types,
29 so you can pass *args and **dargs in directly, rather than having to
30 iterate over them yourself. """
mbligh15971eb2009-12-29 02:55:23 +000031 unpassable_types = _get_unpassable_types(args)
jadmanski043e1132008-11-19 17:10:32 +000032 if unpassable_types:
33 msg = "arguments of type '%s' cannot be passed to remote profilers"
34 msg %= ", ".join(t.__name__ for t in unpassable_types)
35 raise TypeError(msg)
36
37
38class profiler_proxy(object):
39 """ This is a server-side class that acts as a proxy to a real client-side
40 profiler class."""
41
mbligh15971eb2009-12-29 02:55:23 +000042 def __init__(self, profiler_name):
jadmanski043e1132008-11-19 17:10:32 +000043 self.name = profiler_name
jadmanski043e1132008-11-19 17:10:32 +000044
jadmanski91cd58c2008-12-02 15:34:53 +000045 # does the profiler support rebooting?
46 profiler_module = common.setup_modules.import_module(
47 profiler_name, "autotest_lib.client.profilers.%s" % profiler_name)
48 profiler_class = getattr(profiler_module, profiler_name)
49 self.supports_reboot = profiler_class.supports_reboot
50
jadmanski043e1132008-11-19 17:10:32 +000051
jadmanski043e1132008-11-19 17:10:32 +000052 def initialize(self, *args, **dargs):
mbligh15971eb2009-12-29 02:55:23 +000053 _validate_args(args)
54 _validate_args(dargs)
mblighb3c0c912008-11-27 00:32:45 +000055 self.args, self.dargs = args, dargs
56
57
58 def setup(self, *args, **dargs):
59 assert self.args == args and self.dargs == dargs
60 # the actual setup happens lazily at start()
61
62
jadmanski4f909252008-12-01 20:47:10 +000063 def start(self, test, host=None):
mbligh15971eb2009-12-29 02:55:23 +000064 raise NotImplementedError('start not implemented')
jadmanski043e1132008-11-19 17:10:32 +000065
66
jadmanski4f909252008-12-01 20:47:10 +000067 def stop(self, test, host=None):
mbligh15971eb2009-12-29 02:55:23 +000068 raise NotImplementedError('stop not implemented')
jadmanski043e1132008-11-19 17:10:32 +000069
70
jadmanski4f909252008-12-01 20:47:10 +000071 def report(self, test, host=None, wait_on_client=True):
mbligh15971eb2009-12-29 02:55:23 +000072 raise NotImplementedError('report not implemented')