diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /dom/base/usecounters.py | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | dom/base/usecounters.py | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/dom/base/usecounters.py b/dom/base/usecounters.py new file mode 100644 index 0000000000..07e63278d4 --- /dev/null +++ b/dom/base/usecounters.py @@ -0,0 +1,92 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +import buildconfig +import collections +import re +from six import StringIO +import sys + + +def read_conf(conf_filename): + # Can't read/write from a single StringIO, so make a new one for reading. + stream = open(conf_filename, "rU") + + def parse_counters(stream): + for line_num, line in enumerate(stream): + line = line.rstrip("\n") + if not line or line.startswith("//"): + # empty line or comment + continue + m = re.match(r"method ([A-Za-z0-9]+)\.([A-Za-z0-9]+)$", line) + if m: + interface_name, method_name = m.groups() + yield { + "type": "method", + "interface_name": interface_name, + "method_name": method_name, + } + continue + m = re.match(r"attribute ([A-Za-z0-9]+)\.([A-Za-z0-9]+)$", line) + if m: + interface_name, attribute_name = m.groups() + yield { + "type": "attribute", + "interface_name": interface_name, + "attribute_name": attribute_name, + } + continue + m = re.match(r"custom ([A-Za-z0-9_]+) (.*)$", line) + if m: + name, desc = m.groups() + yield {"type": "custom", "name": name, "desc": desc} + continue + raise ValueError( + "error parsing %s at line %d" % (conf_filename, line_num + 1) + ) + + return parse_counters(stream) + + +def generate_histograms(filename, is_for_worker=False): + # The mapping for use counters to telemetry histograms depends on the + # ordering of items in the dictionary. + + # The ordering of the ending for workers depends on the WorkerType defined + # in WorkerPrivate.h. + endings = ( + ["DEDICATED_WORKER", "SHARED_WORKER", "SERVICE_WORKER"] + if is_for_worker + else ["DOCUMENT", "PAGE"] + ) + + items = collections.OrderedDict() + for counter in read_conf(filename): + + def append_counter(name, desc): + items[name] = { + "expires_in_version": "never", + "kind": "boolean", + "description": desc, + } + + def append_counters(name, desc): + for ending in endings: + append_counter( + "USE_COUNTER2_%s_%s" % (name, ending), + "Whether a %s %s" % (ending.replace("_", " ").lower(), desc), + ) + + if counter["type"] == "method": + method = "%s.%s" % (counter["interface_name"], counter["method_name"]) + append_counters(method.replace(".", "_").upper(), "called %s" % method) + elif counter["type"] == "attribute": + attr = "%s.%s" % (counter["interface_name"], counter["attribute_name"]) + counter_name = attr.replace(".", "_").upper() + append_counters("%s_getter" % counter_name, "got %s" % attr) + append_counters("%s_setter" % counter_name, "set %s" % attr) + elif counter["type"] == "custom": + append_counters(counter["name"].upper(), counter["desc"]) + + return items |