| 1 | # Copyright (C) 2015 - Philippe Proulx <pproulx@efficios.com> |
| 2 | # Copyright (C) 2014 - David Goulet <dgoulet@efficios.com> |
| 3 | # |
| 4 | # This library is free software; you can redistribute it and/or modify it under |
| 5 | # the terms of the GNU Lesser General Public License as published by the Free |
| 6 | # Software Foundation; version 2.1 of the License. |
| 7 | # |
| 8 | # This library is distributed in the hope that it will be useful, but WITHOUT |
| 9 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 10 | # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
| 11 | # details. |
| 12 | # |
| 13 | # You should have received a copy of the GNU Lesser General Public License |
| 14 | # along with this library; if not, write to the Free Software Foundation, Inc., |
| 15 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 16 | |
| 17 | from __future__ import unicode_literals, print_function |
| 18 | import logging |
| 19 | import time |
| 20 | import sys |
| 21 | |
| 22 | |
| 23 | def _perror(msg): |
| 24 | print(msg, file=sys.stderr) |
| 25 | sys.exit(1) |
| 26 | |
| 27 | |
| 28 | try: |
| 29 | import lttngust |
| 30 | except (ImportError) as e: |
| 31 | _perror('lttngust package not found: {}'.format(e)) |
| 32 | |
| 33 | |
| 34 | def _main(): |
| 35 | ev1 = logging.getLogger('python-ev-test1'); |
| 36 | ev2 = logging.getLogger('python-ev-test2'); |
| 37 | |
| 38 | logging.basicConfig() |
| 39 | |
| 40 | try: |
| 41 | nr_iter = int(sys.argv[1]) |
| 42 | wait_time = float(sys.argv[2]) |
| 43 | fire_debug_ev = False |
| 44 | fire_second_ev = False |
| 45 | except (IndexError) as e: |
| 46 | _perror('missing arguments: {}'.format(e)) |
| 47 | except (ValueError) as e: |
| 48 | _perror('invalid arguments: {}'.format(e)) |
| 49 | |
| 50 | try: |
| 51 | if len(sys.argv) > 3: |
| 52 | fire_debug_ev = int(sys.argv[3]) |
| 53 | if len(sys.argv) > 4: |
| 54 | fire_second_ev = int(sys.argv[4]) |
| 55 | except (ValueError) as e: |
| 56 | _perror('invalid arguments: {}'.format(e)) |
| 57 | |
| 58 | for i in range(nr_iter): |
| 59 | ev1.info('{} fired [INFO]'.format(ev1.name)) |
| 60 | |
| 61 | if fire_debug_ev: |
| 62 | ev1.debug('{} fired [DEBUG]'.format(ev1.name)) |
| 63 | |
| 64 | time.sleep(wait_time) |
| 65 | |
| 66 | if fire_second_ev: |
| 67 | ev2.info('{} fired [INFO]'.format(ev2.name)) |
| 68 | |
| 69 | |
| 70 | if __name__ == '__main__': |
| 71 | _main() |