Commit | Line | Data |
---|---|---|
0e115563 DG |
1 | #!/usr/bin/env python |
2 | # | |
3 | # Copyright (C) 2014 - David Goulet <dgoulet@efficios.com> | |
4 | # | |
5 | # This library is free software; you can redistribute it and/or modify it under | |
6 | # the terms of the GNU Lesser General Public License as published by the Free | |
7 | # Software Foundation; version 2.1 of the License. | |
8 | # | |
9 | # This library is distributed in the hope that it will be useful, but WITHOUT | |
10 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
11 | # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | |
12 | # details. | |
13 | # | |
14 | # You should have received a copy of the GNU Lesser General Public License | |
15 | # along with this library; if not, write to the Free Software Foundation, Inc., | |
16 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
17 | ||
18 | import sys | |
19 | import logging | |
20 | import errno | |
21 | ||
22 | from time import sleep | |
23 | ||
24 | def cleanup(code, agent = None): | |
25 | """ | |
26 | Cleanup agent and exit with given code. | |
27 | """ | |
28 | if agent is not None: | |
29 | agent.destroy() | |
30 | ||
31 | sys.exit(code) | |
32 | ||
33 | try: | |
34 | import lttng_agent | |
35 | except ImportError as e: | |
36 | print("LTTng Agent not found. Aborting") | |
37 | cleanup(errno.ENOSYS) | |
38 | ||
39 | def run(): | |
40 | """ | |
41 | Main for this test program. Based on the Java testing program that behaves | |
42 | exactly the same. | |
43 | """ | |
44 | ||
45 | agent = lttng_agent.LTTngAgent() | |
46 | ev1 = logging.getLogger("python-ev-test1"); | |
47 | ev2 = logging.getLogger("python-ev-test2"); | |
48 | ||
49 | try: | |
50 | nr_iter = int(sys.argv[1]) | |
51 | wait_time = int(sys.argv[2]) | |
52 | fire_debug_ev = 0 | |
53 | fire_second_ev = 0 | |
54 | except IndexError as e: | |
55 | print("Missing arguments. Aborting") | |
56 | cleanup(errno.EINVAL, agent) | |
57 | except ValueError as e: | |
58 | print("Invalid arguments. Aborting") | |
59 | cleanup(errno.EINVAL, agent) | |
60 | ||
61 | if len(sys.argv) > 3: | |
62 | fire_debug_ev = int(sys.argv[3]) | |
63 | if len(sys.argv) > 4: | |
64 | fire_second_ev = int(sys.argv[4]) | |
65 | ||
66 | for i in range(0, nr_iter): | |
67 | ev1.info("%s fired" % ev1.name) | |
68 | if fire_debug_ev != 0: | |
69 | ev1.debug("%s DEBUG fired" % ev1.name) | |
70 | sleep(wait_time) | |
71 | ||
72 | if fire_second_ev != 0: | |
73 | ev2.info("%s fired" % ev2.name) | |
74 | ||
75 | if __name__ == "__main__": | |
76 | run() |