Skip to content

Commit

Permalink
Update histogram paths and added sorting in merge
Browse files Browse the repository at this point in the history
Function to split histograms by prefix

- Amended the histogram_paths.py to prepare for the distributed
directories of histograms after splitting.
- Amended two other files that previously expected a single
histogram.xml file.
- Added sorting of histogram nodes by name in merge_xml.py.

Change-Id: I60101777806584722cbeb778c778553259419122
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2337155
Commit-Queue: Wenhan (Han) Zhang <[email protected]>
Reviewed-by: Steven Holte <[email protected]>
Cr-Commit-Position: refs/heads/master@{#796655}
  • Loading branch information
Wenhan (Han) Zhang authored and Commit Bot committed Aug 11, 2020
1 parent c8c2c64 commit 7b5ead6
Show file tree
Hide file tree
Showing 9 changed files with 1,962 additions and 1,751 deletions.
44 changes: 35 additions & 9 deletions tools/metrics/histograms/histogram_ownership.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,18 @@

from __future__ import print_function

import extract_histograms
import errno
import os
import sys
import xml.etree.ElementTree
from xml.etree import ElementTree as ET

sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'common'))
import path_util
import extract_histograms
import histogram_paths
import merge_xml

def main():
tree = xml.etree.ElementTree.parse(path_util.GetHistogramsFile())
root = tree.getroot()
assert root.tag == 'histogram-configuration'

def PrintOwners(root):
assert root.tag == 'histogram-configuration'
root_children = root.getchildren()
histograms = None
for node in root_children:
Expand All @@ -45,7 +44,6 @@ def main():
continue
if node.text == extract_histograms.OWNER_PLACEHOLDER:
continue
assert '@' in node.text
owners.append(node.text)

if not obsolete:
Expand All @@ -55,5 +53,33 @@ def main():
print(name, 'NO_OWNER')


def main():
"""Prints the owners of histograms in a specific file or of all histograms.
Args:
argv[1]: Optional argument that is the relative path to a specific
histograms.xml.
Example usage to print owners of histograms_xml/Accessibility/histograms.xml:
python histogram_ownership.py histograms_xml/Accessibility/histograms.xml
Example usage to print owners of all histograms:
python histogram_ownership.py
"""
if len(sys.argv) == 1:
merged_xml_string = merge_xml.PrettyPrintMergedFiles(
histogram_paths.ALL_XMLS)
root = ET.fromstring(merged_xml_string)
else:
rel_path = sys.argv[1]
if not os.path.exists(rel_path):
raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT))

tree = ET.parse(rel_path)
root = tree.getroot()

PrintOwners(root)


if __name__ == '__main__':
main()
40 changes: 33 additions & 7 deletions tools/metrics/histograms/histogram_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,43 @@
sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'common'))
import path_util

ALL_XMLS_RELATIVE = [
'tools/metrics/histograms/enums.xml',
'tools/metrics/histograms/histograms.xml'
]
ALL_XMLS = [path_util.GetInputFile(f) for f in ALL_XMLS_RELATIVE]
ENUMS_XML, HISTOGRAMS_XML = ALL_XMLS

def _FindHistogramsXmlFiles(base_dir):
"""Gets a list of all histograms.xml files under the directory tree, prefixed
with tools/metrics/histograms/."""
file_list = []
for dirName, _, fileList in os.walk(base_dir):
for filename in fileList:
if filename == 'histograms.xml':
filepath = os.path.join('tools/metrics/histograms/', dirName, filename)
file_list.append(filepath)
return file_list


ENUMS_XML_RELATIVE = 'tools/metrics/histograms/enums.xml'
# This file path accounts for cases where the script is executed from other
# metrics-related directories.
PATH_TO_HISTOGRAMS_XML_DIR = os.path.join('..', 'histograms/histograms_xml')
# In the middle state, histogram paths include both the large histograms.xml
# file as well as the split up files.
# TODO: Improve on the current design to avoid calling `os.walk()` at the time
# of module import.
HISTOGRAMS_XMLS_RELATIVE = (['tools/metrics/histograms/histograms.xml'] +
_FindHistogramsXmlFiles(PATH_TO_HISTOGRAMS_XML_DIR))
OBSOLETE_XML_RELATIVE = ('tools/metrics/histograms/histograms_xml/'
'obsolete_histograms.xml')
ALL_XMLS_RELATIVE = [ENUMS_XML_RELATIVE, OBSOLETE_XML_RELATIVE
] + HISTOGRAMS_XMLS_RELATIVE

ENUMS_XML = path_util.GetInputFile(ENUMS_XML_RELATIVE)
HISTOGRAMS_XMLS = [path_util.GetInputFile(f) for f in HISTOGRAMS_XMLS_RELATIVE]
OBSOLETE_XML = path_util.GetInputFile(OBSOLETE_XML_RELATIVE)
ALL_XMLS = [ENUMS_XML, OBSOLETE_XML] + HISTOGRAMS_XMLS

ALL_TEST_XMLS_RELATIVE = [
'tools/metrics/histograms/test_data/enums.xml',
'tools/metrics/histograms/test_data/histograms.xml',
'tools/metrics/histograms/test_data/ukm.xml',
]
ALL_TEST_XMLS = [path_util.GetInputFile(f) for f in ALL_TEST_XMLS_RELATIVE]
TEST_ENUMS_XML, TEST_HISTOGRAMS_XML, TEST_UKM_XML = ALL_TEST_XMLS
TEST_ENUMS_XML, TEST_HISTOGRAMS_XML, TEST_UKM_XML = ALL_TEST_XMLS
Loading

0 comments on commit 7b5ead6

Please sign in to comment.