[browser-stories] refactor reading logs
{do_raw_json} and {do_json} both read the log files to construct a dictionary of stats. This CL extracts that logic and eliminates code duplication No-Try: true Bug: v8:9448 Change-Id: I375920c25942a92cc12790ac60a4c7960cfd44b2 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1706473 Auto-Submit: Tamer Tas <tmrts@chromium.org> Commit-Queue: Ulan Degenbaev <ulan@chromium.org> Reviewed-by: Ulan Degenbaev <ulan@chromium.org> Cr-Commit-Position: refs/heads/master@{#62768}
This commit is contained in:
parent
618e290d0e
commit
bc96cbd68c
@ -547,7 +547,7 @@ def create_total_page_stats(domains, args):
|
||||
|
||||
# Generate Raw JSON file.
|
||||
|
||||
def do_raw_json(args):
|
||||
def _read_logs(args):
|
||||
versions = {}
|
||||
for path in args.logdirs:
|
||||
if os.path.isdir(path):
|
||||
@ -562,6 +562,11 @@ def do_raw_json(args):
|
||||
read_stats(os.path.join(root, filename),
|
||||
versions[version][domain], args)
|
||||
|
||||
return versions
|
||||
|
||||
def do_raw_json(args):
|
||||
versions = _read_logs(args)
|
||||
|
||||
for version, domains in versions.items():
|
||||
if args.aggregate:
|
||||
create_total_page_stats(domains, args)
|
||||
@ -584,19 +589,8 @@ def do_raw_json(args):
|
||||
# Generate JSON file.
|
||||
|
||||
def do_json(args):
|
||||
versions = {}
|
||||
for path in args.logdirs:
|
||||
if os.path.isdir(path):
|
||||
for root, dirs, files in os.walk(path):
|
||||
version = os.path.basename(root)
|
||||
if version not in versions: versions[version] = {}
|
||||
for filename in files:
|
||||
if filename.endswith(".txt"):
|
||||
m = re.match(r'^([^#]+)(#.*)?\.txt$', filename)
|
||||
domain = m.group(1)
|
||||
if domain not in versions[version]: versions[version][domain] = {}
|
||||
read_stats(os.path.join(root, filename),
|
||||
versions[version][domain], args)
|
||||
versions = _read_logs(args)
|
||||
|
||||
for version, domains in versions.items():
|
||||
if args.aggregate:
|
||||
create_total_page_stats(domains, args)
|
||||
|
Loading…
Reference in New Issue
Block a user