Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / tools / swarming_client / tools / spam.py
1 #!/usr/bin/env python
2 # Copyright 2014 The Swarming Authors. All rights reserved.
3 # Use of this source code is governed under the Apache License, Version 2.0 that
4 # can be found in the LICENSE file.
5
6 """spam.py spams stdout for load testing the stdout handler.
7
8 To use on the server, use:
9   export ISOLATE=https://your-server.appspot.com
10   export SWARMING=https://your-server.appspot.com
11   ../isolate.py archive -I $ISOLATE -i spam.isolate -s spam.isolated
12   # Where Linux can also be Mac or Windows.
13   ../swarming.py run -I $ISOLATE -S $SWARMING spam.isolated -d os Linux \
14 --priority 10 -- --duration 600 --sleep 0.5 --size 1024
15
16 ./run_on_bot.py can also be used to trigger systematically on all bots.
17  """
18
19 import optparse
20 import sys
21 import time
22
23
24 def main():
25   parser = optparse.OptionParser(
26       description=sys.modules[__name__].__doc__, usage='%prog [options]')
27   parser.format_description = lambda _: parser.description
28   parser.add_option(
29       '--duration', type='float', default=5., help='Duration in seconds')
30   parser.add_option(
31       '--sleep', type='float', default=1.,
32       help='Sleep in seconds between burst')
33   parser.add_option(
34       '--size', type='int', default=10, help='Data written at each burst')
35   options, args = parser.parse_args()
36   if args:
37     parser.error('Unknown args: %s' % args)
38   if options.duration <= 0:
39     parser.error('Invalid --duration')
40   if options.sleep < 0:
41     parser.error('Invalid --sleep')
42   if options.size < 1:
43     parser.error('Invalid --size')
44
45   print('Duration: %gs' % options.duration)
46   print('Sleep: %gs' % options.sleep)
47   print('Bursts size: %d' % options.size)
48   start = time.time()
49   end = start + options.duration
50   index = 0
51   while True:
52     sys.stdout.write(str(index) * (options.size - 1))
53     sys.stdout.write('\n')
54     if time.time() > end:
55       break
56     time.sleep(options.sleep)
57     index = (index + 1) % 10
58   return 0
59
60
61 if __name__ == '__main__':
62   sys.exit(main())