1#!/usr/bin/python -t
2# Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6import sys
7import threading
8import time
9
10import common
11from autotest_lib.site_utils.lib import infra
12from autotest_lib.site_utils.stats import registry
13
14
15def main():
16    """
17    Runs all of the registered functions in stats/
18    """
19
20    threads = []
21    pollers = registry.registered_functions()
22
23    for sam in infra.sam_servers():
24        for f in pollers.get('sam', []):
25            threads.append(threading.Thread(target=f, args=(sam,)))
26
27    for drone in infra.drone_servers():
28        for f in pollers.get('drone', []):
29            threads.append(threading.Thread(target=f, args=(drone,)))
30
31    for devserver in infra.devserver_servers():
32        for f in pollers.get('devserver', []):
33            threads.append(threading.Thread(target=f, args=(devserver,)))
34
35    for f in pollers.get(None, []):
36        threads.append(threading.Thread(target=f))
37
38    for thread in threads:
39        thread.daemon = True
40        thread.start()
41
42    # Now we want to stay responsive to ctrl-c, so we need to just idle the main
43    # thread.  If we notice that all of our threads disappeared though, there's
44    # no point in continuing to run.
45    while threading.active_count() > 0:
46        time.sleep(1)
47
48
49if __name__ == '__main__':
50    sys.exit(main())
51