add customizable thresholds for termination
This commit is contained in:
parent
ad995b0845
commit
f1ac7516b0
13
impatient
13
impatient
|
@ -14,6 +14,8 @@ parser.add_argument('-f', '--final', type=str, help='Expected final size/value a
|
|||
parser.add_argument('-i', '--interval', type=int, default=10, help='Interval in seconds between samples (default 10)')
|
||||
parser.add_argument('-w', '--window', type=int, default=100, help='Number of samples to keep for the sliding window (default 100)')
|
||||
parser.add_argument('-d', '--decay', type=float, default=1, help='Decay coefficient for older samples (default 1). Must be between 0 and 1 inclusive. The lower this is, the more responsive/swingy the estimate will be.')
|
||||
parser.add_argument('-V', '--termination-value-threshold', type=float, default=0.95, metavar='FRACTION', help='Fraction of the expected final value that must be reached in order to terminate (default 0.95). Reaching this threshold is necessary but not sufficient, see also -I')
|
||||
parser.add_argument('-I', '--termination-inactivity-threshold', type=int, default=10, metavar='COUNT', help='Number of consecutive unchanged samples that must be observed in order to terminate (default 10). Reaching this threshold is necessary but not sufficient, see also -V')
|
||||
tracker_types = parser.add_mutually_exclusive_group(required=True)
|
||||
tracker_types.add_argument('-p', '--path', type=str, help='Track total disk usage of a given path')
|
||||
tracker_types.add_argument('-c', '--command', type=str, help='Track value returned by a shell command; this should return a single number, optionally with a K/M/G/T suffix')
|
||||
|
@ -28,6 +30,12 @@ if args.window < 1:
|
|||
if args.decay < 0 or args.decay > 1:
|
||||
print('decay coefficient must be between 0 and 1', file=sys.stderr)
|
||||
exit(1)
|
||||
if args.termination_value_threshold < 0 or args.termination_value_threshold > 1:
|
||||
print('termination value threshold must be between 0 and 1', file=sys.stderr)
|
||||
exit(1)
|
||||
if args.termination_inactivity_threshold < 0:
|
||||
print('termination inactivity threshold must be nonnegative', file=sys.stderr)
|
||||
exit(1)
|
||||
|
||||
def parse_value(v):
|
||||
suffix = v[-1].upper()
|
||||
|
@ -65,6 +73,9 @@ else:
|
|||
|
||||
if args.final:
|
||||
final = parse_value(args.final)
|
||||
if final <= 0:
|
||||
print('final value must be positive', file=sys.stderr)
|
||||
exit(1)
|
||||
else:
|
||||
final = None
|
||||
|
||||
|
@ -109,6 +120,6 @@ while True:
|
|||
), end='')
|
||||
sys.stdout.flush()
|
||||
|
||||
if final and current >= final and all(d == 0 for d in deltas[-10:]):
|
||||
if final and current >= args.termination_value_threshold*final and all(d == 0 for d in deltas[-args.termination_inactivity_threshold:]):
|
||||
print()
|
||||
break
|
||||
|
|
Loading…
Reference in a new issue