1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 from perfdocs
.framework_gatherers
import (
14 from perfdocs
.logger
import PerfDocLogger
15 from perfdocs
.utils
import read_yaml
17 logger
= PerfDocLogger()
19 # TODO: Implement decorator/searcher to find the classes.
21 "raptor": RaptorGatherer
,
22 "mozperftest": MozperftestGatherer
,
23 "talos": TalosGatherer
,
27 # List of file types allowed to be used as static files
28 ALLOWED_STATIC_FILETYPES
= ("rst", "png")
31 class Gatherer(object):
33 Gatherer produces the tree of the perfdoc's entries found
34 and can obtain manifest-based test lists. Used by the Verifier.
37 def __init__(self
, workspace_dir
, taskgraph
=None):
39 Initialzie the Gatherer.
41 :param str workspace_dir: Path to the gecko checkout.
43 self
.workspace_dir
= workspace_dir
44 self
.taskgraph
= taskgraph
45 self
._perfdocs
_tree
= []
47 self
.framework_gatherers
= {}
50 def perfdocs_tree(self
):
52 Returns the perfdocs_tree, and computes it
55 :return dict: The perfdocs tree containing all
56 framework perfdoc entries. See `fetch_perfdocs_tree`
57 for information on the data structure.
59 if self
._perfdocs
_tree
:
60 return self
._perfdocs
_tree
62 self
.fetch_perfdocs_tree()
63 return self
._perfdocs
_tree
65 def fetch_perfdocs_tree(self
):
67 Creates the perfdocs tree with the following structure:
70 "path": Path to the perfdocs directory.
71 "yml": Name of the configuration YAML file.
72 "rst": Name of the RST file.
73 "static": Name of the static file.
77 This method doesn't return anything. The result can be found in
78 the perfdocs_tree attribute.
81 str(pathlib
.Path(self
.workspace_dir
, ".hg")),
82 str(pathlib
.Path("tools", "lint")),
83 str(pathlib
.Path("testing", "perfdocs")),
86 for path
in pathlib
.Path(self
.workspace_dir
).rglob("perfdocs"):
87 if any(d
in str(path
.resolve()) for d
in exclude_dir
):
89 files
= [f
for f
in os
.listdir(path
)]
91 # Metrics are optional so it's only added to the matched if we
92 # find the `metrics.rst` file in the perfdocs folder
93 matched
= {"path": str(path
), "yml": "", "rst": "", "static": []}
96 # Add the yml/rst/static file to its key if re finds the searched file
97 if file == "config.yml" or file == "config.yaml":
99 elif file == "index.rst":
100 matched
["rst"] = file
101 elif file == "metrics.rst":
102 matched
["metrics"] = file
103 elif file.split(".")[-1] in ALLOWED_STATIC_FILETYPES
:
104 matched
["static"].append(file)
106 # Append to structdocs if all the searched files were found
107 if all(val
for val
in matched
.values() if type(val
) is not list):
108 self
._perfdocs
_tree
.append(matched
)
111 "Found {} perfdocs directories in {}".format(
112 len(self
._perfdocs
_tree
),
113 [d
["path"] for d
in self
._perfdocs
_tree
],
117 def get_test_list(self
, sdt_entry
):
119 Use a perfdocs_tree entry to find the test list for
120 the framework that was found.
122 :return: A framework info dictionary with fields: {
123 'yml_path': Path to YAML,
124 'yml_content': Content of YAML,
125 'name': Name of framework,
126 'test_list': Test list found for the framework
130 # If it was computed before, return it
131 yaml_path
= pathlib
.Path(sdt_entry
["path"], sdt_entry
["yml"])
132 for entry
in self
._test
_list
:
133 if entry
["yml_path"] == yaml_path
:
136 # Set up framework entry with meta data
137 yaml_content
= read_yaml(yaml_path
)
139 "yml_content": yaml_content
,
140 "yml_path": yaml_path
,
141 "name": yaml_content
["name"],
145 if yaml_content
["static-only"]:
146 framework_gatherer_cls
= StaticGatherer
148 framework_gatherer_cls
= frameworks
[framework
["name"]]
150 # Get and then store the frameworks tests
151 framework_gatherer
= self
.framework_gatherers
[framework
["name"]] = (
152 framework_gatherer_cls(
153 framework
["yml_path"], self
.workspace_dir
, self
.taskgraph
157 if not yaml_content
["static-only"]:
158 framework
["test_list"] = framework_gatherer
.get_test_list()
160 self
._test
_list
.append(framework
)