Commit a7e0a644 authored by Vincent Pelletier's avatar Vincent Pelletier

Add support for reading state data from stdin.

parent 6f7c77f3
......@@ -993,10 +993,12 @@ def main():
parser.add_argument('-Q', dest='extra_quiet', action='store_true',
help='Suppress progress indication (file being parsed, lines counter). '
'Does not imply -q.')
parser.add_argument('--state-file', nargs='+', default=[], type=file,
help='Use given JSON files as initial state. Mixing files generated with '
'different parameters is allowed, but no correction is made. Output may '
'be unusable (ex: different --apdex, different --period, ...).')
parser.add_argument('--state-file', nargs='+', default=[],
help='Use given JSON files as initial state. Use - for stdin. Loading'
'multiple files through stdin is not possible). Mixing '
'files generated with different parameters is allowed, but no '
'correction is made. Output may be unusable (ex: different --apdex, '
'different --period, ...).')
group = parser.add_argument_group('generated content')
group.add_argument('-a', '--apdex', default=1.0, type=float,
......@@ -1132,32 +1134,40 @@ def main():
error_detail = args.error_detail
file_count = len(infile_list)
per_site = {}
for state_file in args.state_file:
print >> sys.stderr, 'Loading', state_file.name, '...',
load_start = time.time()
state = json.load(state_file, encoding='ascii')
for url, site_state in state:
if url is None:
site = None
action = default_action
else:
for site, prefix_match, action in site_list:
if site == url:
break
else:
if '-' in args.state_file and '-' in infile_list:
print >> sys.stderr, 'stdin cannot be used both as log and state input.'
sys.exit(1)
for state_file_name in args.state_file:
print >> sys.stderr, 'Loading', state_file_name, '...',
if state_file_name == '-':
state_file = sys.stdin
else:
state_file = open(state_file_name)
with state_file:
load_start = time.time()
state = json.load(state_file, encoding='ascii')
for url, site_state in state:
if url is None:
site = None
action = default_action
if action is None:
print >> sys.stderr, 'Info: no prefix match %r, stats skipped' % url
continue
site_stats = action.func.fromJSONState(site_state,
getDuration, action.keywords['suffix'])
if site in per_site:
per_site[site].accumulateFrom(site_stats)
else:
per_site[site] = site_stats
print >> sys.stderr, 'done (%s)' % timedelta(seconds=time.time()
- load_start)
else:
for site, prefix_match, action in site_list:
if site == url:
break
else:
site = None
action = default_action
if action is None:
print >> sys.stderr, 'Info: no prefix match %r, stats skipped' % url
continue
site_stats = action.func.fromJSONState(site_state,
getDuration, action.keywords['suffix'])
if site in per_site:
per_site[site].accumulateFrom(site_stats)
else:
per_site[site] = site_stats
print >> sys.stderr, 'done (%s)' % timedelta(seconds=time.time()
- load_start)
skip_user_agent = list(itertools.chain(*args.skip_user_agent))
malformed_lines = 0
skipped_lines = 0
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment