Last active
May 28, 2018 16:39
-
-
Save ethercflow/8b10b7a450dfe021d7cf27e4182c5a3f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| # -*- coding: utf-8 -*- | |
| import argparse | |
| import logging | |
| import os | |
| import threading | |
| def parse_opts(): | |
| parser = argparse.ArgumentParser(prog='iops') | |
| parser.add_argument('--dev', help='dev(major:minor)' ) | |
| parser.add_argument('--base', type = int, help='iops') | |
| parser.add_argument('--step', type = int, help='step') | |
| parser.add_argument('--cycle', type = int, help='cycle') | |
| parser.add_argument('--type', choices='rw', help='riops or wiops') | |
| subparsers = parser.add_subparsers(help='sub-command help') | |
| parser_inc = subparsers.add_parser('inc', help='inc iops') | |
| parser_inc.set_defaults(func=inc) | |
| parser_dec = subparsers.add_parser('dec', help='dec iops') | |
| parser_dec.set_defaults(func=dec) | |
| return parser.parse_args() | |
| def inc(args): | |
| item = 'write' | |
| if args.type == 'r': | |
| item = "read" | |
| run(args.cycle, item, args.dev, args.base, args.step) | |
| def dec(args): | |
| item = 'write' | |
| if args.type == 'r': | |
| item = "read" | |
| run(args.cycle, item, args.dev, args.base, -args.step) | |
| def run(cycle, item, dev, iops, step): | |
| cmd = 'cgset -r blkio.throttle.%s_iops_device="%s %d" iothrottle' % (item, dev, iops) | |
| logging.info(cmd) | |
| ret = os.system(cmd) != 0 | |
| if ret != 0: | |
| logging.fatal(cmd) | |
| exit(1) | |
| iops += step | |
| if iops < 0: | |
| iops = 0 | |
| t = threading.Timer(cycle, run, (cycle, item, dev, iops, step)) | |
| t.start() | |
| if __name__ == "__main__": | |
| logging.basicConfig(level=logging.INFO) | |
| args = parse_opts() | |
| args.func(args) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
eg:
参数说明: