#!/usr/bin/env python
# Copyright (c) 2012-2013 SwiftStack, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import sys
import argparse
import logging

from ssbench.worker import Worker

if __name__ == "__main__":
    arg_parser = argparse.ArgumentParser(
        formatter_class=argparse.ArgumentDefaultsHelpFormatter,
        description='Benchmark your Swift installation')
    arg_parser.add_argument('worker_id', type=int, help='An integer ID '
                            'number; must be unique among all workers')
    arg_parser.add_argument('--qhost', default="127.0.0.1",
                            help='beanstalkd host')
    arg_parser.add_argument('--qport', default=11300, type=int,
                            help='beanstalkd port')
    arg_parser.add_argument('-c', '--concurrency', type=int, default=256,
                            help='Maximum concurrency this worker will '
                            'provide.')
    arg_parser.add_argument('--retries', default=10, type=int,
                            help='Maximum number of times to retry a job.')
    arg_parser.add_argument('-p', '--profile-count', type=int, metavar='COUNT',
                            default=0,
                            help='Profile %(metavar)s work jobs, starting '
                            'with the first.')
    arg_parser.add_argument('-v', '--verbose', action='store_true',
                            default=False, help='Enable more verbose output.')

    args = arg_parser.parse_args(sys.argv[1:])

    logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO)
    logging.captureWarnings(True)

    worker = Worker(args.qhost, args.qport, args.worker_id, args.retries,
                    profile_count=args.profile_count,
                    concurrency=args.concurrency)
    worker.go()
