From 51a9283984b05511bd98f9bcbd1f2f18900239cc Mon Sep 17 00:00:00 2001 From: Eric Holk Date: Mon, 7 Dec 2020 15:07:00 -0800 Subject: [metrics] Add file output support Adds a new command line option, -Xwrite-metrics-to-file=_, which specifies a file for writing metrics to. This can be used in conjunction with -Xwrite-metrics-to-log, which will cause the output to go to both logcat and the file. Writing metrics to a file can be helpful for testing or benchmarking environments. Access to the file is protected using advisory locking, so it is safe to have multiple processes write metrics to the same file. Test: test/run-test --host test/2234-write-metrics-to-file Bug: 175025360, 170149255 Change-Id: I83a4f959cbb96847dc71188035c050a73b915064 --- libartbase/base/variant_map.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'libartbase/base/variant_map.h') diff --git a/libartbase/base/variant_map.h b/libartbase/base/variant_map.h index 581bc234cc..7349bbc046 100644 --- a/libartbase/base/variant_map.h +++ b/libartbase/base/variant_map.h @@ -229,6 +229,14 @@ struct VariantMap { return GetValuePtr(key); } + // Look up the value from the key and return the value wrapped in a std::optional. If it was not + // set in the map, return an empty std::optional. + template + std::optional GetOptional(const TKey& key) const { + auto* ptr = Get(key); + return (ptr == nullptr) ? std::optional{} : std::make_optional(*ptr); + } + // Lookup the value from the key. If it was not set in the map, return the default value. // The default value is either the key's default, or TValue{} if the key doesn't have a default. template -- cgit v1.2.3-59-g8ed1b