Commit 7b5ead61 authored by Wenhan (Han) Zhang's avatar Wenhan (Han) Zhang Committed by Commit Bot

Update histogram paths and added sorting in merge

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 <zwenhan@google.com>
Reviewed-by: default avatarSteven Holte <holte@chromium.org>
Cr-Commit-Position: refs/heads/master@{#796655}
parent c8c2c646
...@@ -9,19 +9,18 @@ histograms. ...@@ -9,19 +9,18 @@ histograms.
from __future__ import print_function from __future__ import print_function
import extract_histograms import errno
import os import os
import sys 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 extract_histograms
import path_util 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() root_children = root.getchildren()
histograms = None histograms = None
for node in root_children: for node in root_children:
...@@ -45,7 +44,6 @@ def main(): ...@@ -45,7 +44,6 @@ def main():
continue continue
if node.text == extract_histograms.OWNER_PLACEHOLDER: if node.text == extract_histograms.OWNER_PLACEHOLDER:
continue continue
assert '@' in node.text
owners.append(node.text) owners.append(node.text)
if not obsolete: if not obsolete:
...@@ -55,5 +53,33 @@ def main(): ...@@ -55,5 +53,33 @@ def main():
print(name, 'NO_OWNER') 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__': if __name__ == '__main__':
main() main()
...@@ -10,12 +10,38 @@ import sys ...@@ -10,12 +10,38 @@ import sys
sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'common')) sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'common'))
import path_util import path_util
ALL_XMLS_RELATIVE = [
'tools/metrics/histograms/enums.xml', def _FindHistogramsXmlFiles(base_dir):
'tools/metrics/histograms/histograms.xml' """Gets a list of all histograms.xml files under the directory tree, prefixed
] with tools/metrics/histograms/."""
ALL_XMLS = [path_util.GetInputFile(f) for f in ALL_XMLS_RELATIVE] file_list = []
ENUMS_XML, HISTOGRAMS_XML = ALL_XMLS 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 = [ ALL_TEST_XMLS_RELATIVE = [
'tools/metrics/histograms/test_data/enums.xml', 'tools/metrics/histograms/test_data/enums.xml',
...@@ -23,4 +49,4 @@ ALL_TEST_XMLS_RELATIVE = [ ...@@ -23,4 +49,4 @@ ALL_TEST_XMLS_RELATIVE = [
'tools/metrics/histograms/test_data/ukm.xml', 'tools/metrics/histograms/test_data/ukm.xml',
] ]
ALL_TEST_XMLS = [path_util.GetInputFile(f) for f in ALL_TEST_XMLS_RELATIVE] 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
\ No newline at end of file
This diff is collapsed.
<!--
Copyright 2013 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<!--
This file is used to generate a comprehensive list of Chrome histograms along
with a detailed description for each histogram.
For best practices on writing histogram descriptions, see
https://chromium.googlesource.com/chromium/src.git/+/HEAD/tools/metrics/histograms/README.md
For brief details on how to modify this file to add your description, see
https://chromium.googlesource.com/chromium/src.git/+/HEAD/tools/metrics/histograms/one-pager.md
Please pretty-print and validate your edits by running the pretty_print.py
and validate_format.py scripts in the same directory as this file before
uploading your change for review.
Please send CLs to chromium-metrics-reviews@google.com rather than to specific
individuals. These CLs will be automatically reassigned to a reviewer within
about 5 minutes. This approach helps the metrics team to load-balance incoming
reviews. Googlers can read more about this at go/gwsq-gerrit.
-->
<histogram-configuration>
<histograms>
<histogram name="Fingerprint.Reset.ResetContextMode"
enum="FingerprintSensorMode" expires_after="2021-01-03">
<owner>tomhughes@chromium.org</owner>
<owner>chromeos-fingerprint@google.com</owner>
<summary>The mode FPMCU was in when we reset context.</summary>
</histogram>
<histogram name="Fingerprint.SetContext.SetContextMode"
enum="FingerprintSensorMode" expires_after="2021-01-03">
<owner>yichengli@chromium.org</owner>
<owner>chromeos-fingerprint@google.com</owner>
<summary>The mode FPMCU was in when we set its context.</summary>
</histogram>
<histogram name="Fingerprint.SetContext.Success" enum="BooleanSuccess"
expires_after="2021-01-03">
<owner>yichengli@chromium.org</owner>
<owner>chromeos-fingerprint@google.com</owner>
<summary>Whether setting FPMCU mode succeeded.</summary>
</histogram>
<histogram name="Fingerprint.Unlock.AttemptsCountBeforeSuccess" units="count"
expires_after="2021-01-03">
<owner>rsorokin@chromium.org</owner>
<owner>jessejames@chromium.org</owner>
<owner>cros-oac@google.com</owner>
<summary>
Counts the number of fingerprint attempts until successful screen unlock.
</summary>
</histogram>
<histogram name="Fingerprint.Unlock.AuthSuccessful" enum="BooleanSuccess"
expires_after="2021-01-03">
<owner>rsorokin@chromium.org</owner>
<owner>jessejames@chromium.org</owner>
<owner>cros-oac@google.com</owner>
<summary>
Counts the number of times that the fingerprint match successfully vs.
rejected.
</summary>
</histogram>
<histogram name="Fingerprint.Unlock.EnrolledFingerCount" units="count"
expires_after="2021-01-03">
<owner>rsorokin@chromium.org</owner>
<owner>jessejames@chromium.org</owner>
<owner>cros-oac@google.com</owner>
<summary>Counts the number of fingers enrolled by the user.</summary>
</histogram>
<histogram name="Fingerprint.Unlock.Match.Duration.Capture" units="ms"
expires_after="2021-01-03">
<owner>rsorokin@chromium.org</owner>
<owner>jessejames@chromium.org</owner>
<owner>cros-oac@google.com</owner>
<summary>
Measures the time it took to capture the fingerprint image in the 'match'
case.
</summary>
</histogram>
<histogram name="Fingerprint.Unlock.Match.Duration.Matcher" units="ms"
expires_after="2021-01-03">
<owner>rsorokin@chromium.org</owner>
<owner>jessejames@chromium.org</owner>
<owner>cros-oac@google.com</owner>
<summary>
Measures the time it took to run matcher in the 'match' case.
</summary>
</histogram>
<histogram name="Fingerprint.Unlock.Match.Duration.Overall" units="ms"
expires_after="2021-01-03">
<owner>rsorokin@chromium.org</owner>
<owner>jessejames@chromium.org</owner>
<owner>cros-oac@google.com</owner>
<summary>
Measures the time it took between the detection of a finger and the 'match'
event being sent to the AP.
</summary>
</histogram>
<histogram name="Fingerprint.Unlock.Match.PositiveMatchSecretCorrect"
enum="BooleanCorrect" expires_after="2021-01-03">
<owner>yichengli@chromium.org</owner>
<owner>chromeos-fingerprint@google.com</owner>
<summary>
Whether the hash of the positive match secret read from FPMCU matches the
record.
</summary>
</histogram>
<histogram name="Fingerprint.Unlock.MatchIgnoredDueToPowerButtonPress"
enum="BooleanIgnored" expires_after="2020-11-02">
<owner>ravisadineni@chromium.org</owner>
<owner>chromeos-fingerprint@google.com</owner>
<summary>
Whether fingerprint touch was ignored due to parallel power button press.
</summary>
</histogram>
<histogram name="Fingerprint.Unlock.MigrationForPositiveMatchSecretResult"
enum="BooleanSuccess" expires_after="M85">
<owner>yichengli@chromium.org</owner>
<owner>chromeos-fingerprint@google.com</owner>
<summary>
Whether migrating a record to positive match secret succeeded.
</summary>
</histogram>
<histogram name="Fingerprint.Unlock.NoMatch.Duration.Capture" units="ms"
expires_after="2021-01-03">
<owner>rsorokin@chromium.org</owner>
<owner>jessejames@chromium.org</owner>
<owner>cros-oac@google.com</owner>
<summary>
Measures the time it took to capture the fingerprint image in the 'no-match'
case.
</summary>
</histogram>
<histogram name="Fingerprint.Unlock.NoMatch.Duration.Matcher" units="ms"
expires_after="2021-01-03">
<owner>rsorokin@chromium.org</owner>
<owner>jessejames@chromium.org</owner>
<owner>cros-oac@google.com</owner>
<summary>
Measures the time it took to run the matcher in the 'no-match' case.
</summary>
</histogram>
<histogram name="Fingerprint.Unlock.NoMatch.Duration.Overall" units="ms"
expires_after="2021-01-03">
<owner>rsorokin@chromium.org</owner>
<owner>jessejames@chromium.org</owner>
<owner>cros-oac@google.com</owner>
<summary>
Measures the time it took between the detection of a finger and the
'no-match' event being sent to the AP.
</summary>
</histogram>
<histogram name="Fingerprint.Unlock.ReadPositiveMatchSecret.Success"
enum="BooleanSuccess" expires_after="2021-01-03">
<owner>yichengli@chromium.org</owner>
<owner>chromeos-fingerprint@google.com</owner>
<summary>
Whether successfully read positive match secret from FPMCU when needed.
</summary>
</histogram>
<histogram name="Fingerprint.Unlock.RecordFormatVersion"
enum="FingerprintRecordFormatVersion" expires_after="2021-01-03">
<owner>yichengli@chromium.org</owner>
<owner>chromeos-fingerprint@google.com</owner>
<summary>
Format version of a fingerprint template record read from storage.
</summary>
</histogram>
<histogram name="Fingerprint.UnlockEnabled" enum="BooleanEnabled"
expires_after="2021-01-03">
<owner>rsorokin@chromium.org</owner>
<owner>jessejames@chromium.org</owner>
<owner>cros-oac@google.com</owner>
<summary>
Track whether fingerprint is enabled to unlock the screen, when the user
logs in.
</summary>
</histogram>
<histogram name="Fingerprint.Updater.NoUpdate.Duration.Overall" units="ms"
expires_after="2021-01-03">
<owner>tomhughes@chromium.org</owner>
<owner>hesling@chromium.org</owner>
<owner>chromeos-fingerprint@google.com</owner>
<summary>
Measures the total time it takes to run the fingerprint firmware updater
when an update was not necessary.
</summary>
</histogram>
<histogram name="Fingerprint.Updater.Reason" enum="FingerprintUpdaterReason"
expires_after="2021-01-03">
<owner>tomhughes@chromium.org</owner>
<owner>hesling@chromium.org</owner>
<owner>chromeos-fingerprint@google.com</owner>
<summary>
Tracks the fingerprint firmware updater's reason(s) for re-flashing.
</summary>
</histogram>
<histogram name="Fingerprint.Updater.Status" enum="FingerprintUpdaterStatus"
expires_after="2021-01-03">
<owner>tomhughes@chromium.org</owner>
<owner>hesling@chromium.org</owner>
<owner>chromeos-fingerprint@google.com</owner>
<summary>Tracks the fingerprint firmware updater's overall status.</summary>
</histogram>
<histogram name="Fingerprint.Updater.Update.Duration.Overall" units="ms"
expires_after="2021-01-03">
<owner>tomhughes@chromium.org</owner>
<owner>hesling@chromium.org</owner>
<owner>chromeos-fingerprint@google.com</owner>
<summary>
Measures the total time it takes to run the fingerprint firmware updater
when an update was necessary.
</summary>
</histogram>
</histograms>
</histogram-configuration>
This diff is collapsed.
<!--
Copyright 2013 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<!--
This file is used to generate a comprehensive list of Chrome histograms along
with a detailed description for each histogram.
For best practices on writing histogram descriptions, see
https://chromium.googlesource.com/chromium/src.git/+/HEAD/tools/metrics/histograms/README.md
For brief details on how to modify this file to add your description, see
https://chromium.googlesource.com/chromium/src.git/+/HEAD/tools/metrics/histograms/one-pager.md
Please pretty-print and validate your edits by running the pretty_print.py
and validate_format.py scripts in the same directory as this file before
uploading your change for review.
Please send CLs to chromium-metrics-reviews@google.com rather than to specific
individuals. These CLs will be automatically reassigned to a reviewer within
about 5 minutes. This approach helps the metrics team to load-balance incoming
reviews. Googlers can read more about this at go/gwsq-gerrit.
-->
<histogram-configuration>
<histogram_suffixes_list>
<histogram_suffixes name="PersistentMemoryAllocs" separator="."
ordering="prefix,2">
<obsolete>
Removed 2/2017 for Issue 689315 which indicated they weren't being used.
</obsolete>
<suffix name="BrowserMetrics" label="For browser process metrics."/>
<suffix name="FieldTrialAllocator" label="For field-trial allocator."/>
<suffix name="GpuMetrics" label="For GPU process metrics."/>
<suffix name="NotificationHelperMetrics"
label="For notification_helper process metrics."/>
<suffix name="PpapiBrokerMetrics"
label="For &quot;PPAPI broker&quot; process metrics."/>
<suffix name="PpapiPluginMetrics"
label="For &quot;PPAPI plugin&quot; process metrics."/>
<suffix name="RendererMetrics" label="For renderer process metrics."/>
<suffix name="SandboxHelperMetrics"
label="For &quot;sandbox helper&quot; process metrics."/>
<suffix name="SetupMetrics" label="For setup metrics."/>
<suffix name="UtilityMetrics"
label="For &quot;utility&quot; process metrics."/>
<suffix name="ZygoteMetrics" label="For &quot;zygote&quot; process metrics."/>
<affected-histogram name="UMA.PersistentAllocator.Allocs"/>
</histogram_suffixes>
<histogram_suffixes name="PersistentMemoryErrors" separator="."
ordering="prefix,2">
<suffix name="BrowserMetrics" label="For browser process metrics."/>
<suffix name="CrashpadMetrics" label="For metrics from Crashpad."/>
<suffix name="FieldTrialAllocator" label="For field-trial allocator."/>
<suffix name="GpuMetrics" label="For GPU process metrics."/>
<suffix name="NotificationHelperMetrics"
label="For notification_helper process metrics."/>
<suffix name="PpapiBrokerMetrics"
label="For &quot;PPAPI broker&quot; process metrics."/>
<suffix name="PpapiPluginMetrics"
label="For &quot;PPAPI plugin&quot; process metrics."/>
<suffix name="RendererMetrics" label="For renderer process metrics."/>
<suffix name="SandboxHelperMetrics"
label="For &quot;sandbox helper&quot; process metrics."/>
<suffix name="SetupMetrics" label="For setup metrics."/>
<suffix name="UtilityMetrics"
label="For &quot;utility&quot; process metrics."/>
<suffix name="ZygoteMetrics" label="For &quot;zygote&quot; process metrics."/>
<affected-histogram name="UMA.PersistentAllocator.Errors"/>
</histogram_suffixes>
<histogram_suffixes name="PersistentMemoryUsedPct" separator="."
ordering="prefix,2">
<suffix name="BrowserMetrics" label="For browser process metrics."/>
<suffix name="FieldTrialAllocator" label="For field-trial allocator."/>
<suffix name="GpuMetrics" label="For GPU process metrics."/>
<suffix name="NotificationHelperMetrics"
label="For notification_helper process metrics."/>
<suffix name="PpapiBrokerMetrics"
label="For &quot;PPAPI broker&quot; process metrics."/>
<suffix name="PpapiPluginMetrics"
label="For &quot;PPAPI plugin&quot; process metrics."/>
<suffix name="RendererMetrics" label="For renderer process metrics."/>
<suffix name="SandboxHelperMetrics"
label="For &quot;sandbox helper&quot; process metrics."/>
<suffix name="SetupMetrics" label="For setup metrics."/>
<suffix name="UtilityMetrics"
label="For &quot;utility&quot; process metrics."/>
<suffix name="ZygoteMetrics" label="For &quot;zygote&quot; process metrics."/>
<affected-histogram name="UMA.PersistentAllocator.UsedPct"/>
</histogram_suffixes>
</histogram_suffixes_list>
</histogram-configuration>
\ No newline at end of file
...@@ -16,17 +16,19 @@ import histogram_configuration_model ...@@ -16,17 +16,19 @@ import histogram_configuration_model
import populate_enums import populate_enums
def GetElementsByTagName(trees, tag): def GetElementsByTagName(trees, tag, depth=2):
"""Gets all elements with the specified tag from a set of DOM trees. """Gets all elements with the specified tag from a set of DOM trees.
Args: Args:
trees: A list of DOM trees. trees: A list of DOM trees.
tag: The tag of the elements to find. tag: The tag of the elements to find.
depth: The depth in the trees by which a match should be found.
Returns: Returns:
A list of DOM nodes with the specified tag. A list of DOM nodes with the specified tag.
""" """
iterator = extract_histograms.IterElementsWithTag iterator = extract_histograms.IterElementsWithTag
return list(e for t in trees for e in iterator(t, tag, 2)) return list(e for t in trees for e in iterator(t, tag, depth))
def GetEnumsNodes(doc, trees): def GetEnumsNodes(doc, trees):
...@@ -55,6 +57,28 @@ def GetEnumsNodes(doc, trees): ...@@ -55,6 +57,28 @@ def GetEnumsNodes(doc, trees):
return enums_list return enums_list
def CombineHistogramsSorted(doc, trees):
"""Sorts <histogram> nodes by name and returns a single <histograms> node.
Args:
doc: The document to create the node in.
trees: A list of DOM trees.
Returns:
A list containing a single <histograms> node.
"""
combined_histograms = doc.createElement('histograms')
histogram_nodes = GetElementsByTagName(trees, 'histogram', depth=3)
sorted_histograms = sorted(histogram_nodes,
key=lambda node: node.getAttribute('name').lower())
for histogram in sorted_histograms:
combined_histograms.appendChild(histogram)
return [combined_histograms]
def MakeNodeWithChildren(doc, tag, children): def MakeNodeWithChildren(doc, tag, children):
"""Creates a DOM node with specified tag and child nodes. """Creates a DOM node with specified tag and child nodes.
...@@ -82,12 +106,16 @@ def MergeTrees(trees): ...@@ -82,12 +106,16 @@ def MergeTrees(trees):
A merged DOM tree. A merged DOM tree.
""" """
doc = xml.dom.minidom.Document() doc = xml.dom.minidom.Document()
doc.appendChild(MakeNodeWithChildren(doc, 'histogram-configuration', doc.appendChild(
# This can result in the merged document having multiple <enums> and MakeNodeWithChildren(
# similar sections, but scripts ignore these anyway. doc,
GetEnumsNodes(doc, trees) + 'histogram-configuration',
GetElementsByTagName(trees, 'histograms') + # This can result in the merged document having multiple <enums> and
GetElementsByTagName(trees, 'histogram_suffixes_list'))) # similar sections, but scripts ignore these anyway.
GetEnumsNodes(doc, trees) +
# Sort the histograms by name and return a single <histograms> node.
CombineHistogramsSorted(doc, trees) +
GetElementsByTagName(trees, 'histogram_suffixes_list')))
return doc return doc
......
...@@ -59,7 +59,6 @@ import path_util ...@@ -59,7 +59,6 @@ import path_util
sys.path.append(os.path.join(os.path.dirname(__file__), 'histograms')) sys.path.append(os.path.join(os.path.dirname(__file__), 'histograms'))
import pretty_print import pretty_print
SupportedTags = [ SupportedTags = [
"added", "added",
"expires", "expires",
...@@ -142,12 +141,19 @@ def CreateNode(tree, tag, text): ...@@ -142,12 +141,19 @@ def CreateNode(tree, tag, text):
def main(): def main():
if len(sys.argv) != 2: """
sys.stderr.write('Usage: %s <path-to-md-file>\n' % (sys.argv[0])) argv[1]: The path to the md file.
argv[2]: The relative path of the xml file to be added.
"""
if len(sys.argv) != 3:
sys.stderr.write('Usage: %s <path-to-md-file> <path-to-histograms-file>\n' %
(sys.argv[0]))
sys.exit(1) sys.exit(1)
rel_path = sys.argv[2]
with Trace('Reading histograms.xml') as t: with Trace('Reading histograms.xml') as t:
xml_path = path_util.GetHistogramsFile() xml_path = path_util.GetInputFile(
os.path.join('tools', 'metrics', 'histograms', rel_path))
with open(xml_path, 'rb') as f: with open(xml_path, 'rb') as f:
raw_xml = f.read() raw_xml = f.read()
......
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