OLD | NEW |
---|---|
1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import json | |
5 import os | 6 import os |
6 import os.path | 7 import os.path |
7 import sys | 8 import sys |
8 | 9 |
9 import log_parser | |
10 import loading_model | 10 import loading_model |
11 import loading_trace | |
11 | 12 |
12 | 13 |
13 def SitesFromDir(directory): | 14 def SitesFromDir(directory): |
14 """Extract sites from a data directory. | 15 """Extract sites from a data directory. |
15 | 16 |
16 Based on ./analyze.py fetch file name conventions. We assume each site | 17 Based on ./analyze.py fetch file name conventions. We assume each site |
17 corresponds to two files, <site>.json and <site>.json.cold, and that no other | 18 corresponds to two files, <site>.json and <site>.json.cold, and that no other |
18 kind of file appears in the data directory. | 19 kind of file appears in the data directory. |
19 | 20 |
20 Args: | 21 Args: |
(...skipping 24 matching lines...) Expand all Loading... | |
45 | 46 |
46 Based on ./analyze.py fetch file name conventions. | 47 Based on ./analyze.py fetch file name conventions. |
47 | 48 |
48 Args: | 49 Args: |
49 datadir: the directory containing site JSON data. | 50 datadir: the directory containing site JSON data. |
50 site: a site string. | 51 site: a site string. |
51 | 52 |
52 Returns: | 53 Returns: |
53 A loading model object. | 54 A loading model object. |
54 """ | 55 """ |
55 return loading_model.ResourceGraph(log_parser.FilterRequests( | 56 with file(os.path.join(datadir, site + '.json')) as f: |
56 log_parser.ParseJsonFile(os.path.join(datadir, site + '.json')))) | 57 return loading_model.ResourceGraph(loading_trace.LoadingTrace.FromJsonDict( |
58 json.load(f))) | |
57 | 59 |
58 | 60 |
59 def ColdGraph(datadir, site): | 61 def ColdGraph(datadir, site): |
60 """Return a loading model graph for the cold pull of site. | 62 """Return a loading model graph for the cold pull of site. |
61 | 63 |
62 Based on ./analyze.py fetch file name conventions. | 64 Based on ./analyze.py fetch file name conventions. |
63 | 65 |
64 Args: | 66 Args: |
65 datadir: the directory containing site JSON data. | 67 datadir: the directory containing site JSON data. |
66 site: a site string. | 68 site: a site string. |
67 | 69 |
68 Returns: | 70 Returns: |
69 A loading model object. | 71 A loading model object. |
70 """ | 72 """ |
71 return loading_model.ResourceGraph(log_parser.FilterRequests( | 73 with file(os.path.join(datadir, site + '.json.cold')) as f: |
72 log_parser.ParseJsonFile(os.path.join(datadir, site + '.json.cold')))) | 74 return loading_model.ResourceGraph(loading_trace.LoadingTrace.FromJsonDict( |
blundell
2016/01/21 14:11:38
given the number of times that you're doing this,
mattcary
2016/01/21 16:11:35
I am going to have ResourceGraph take a json dict
| |
75 json.load(f))) | |
OLD | NEW |