// AUTOGENERATED BY glean_parser. DO NOT EDIT. /* 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/. */ #include "mozilla/glean/bindings/GleanJSMetricsLookup.h" #include "mozilla/PerfectHash.h" #include "mozilla/Maybe.h" #include "mozilla/glean/bindings/MetricTypes.h" #include "mozilla/glean/fog_ffi_generated.h" #include "nsString.h" #define GLEAN_INDEX_BITS (32) #define GLEAN_TYPE_BITS (5) #define GLEAN_ID_BITS (27) #define GLEAN_TYPE_ID(id) ((id) >> GLEAN_ID_BITS) #define GLEAN_METRIC_ID(id) ((id) & ((1ULL << GLEAN_ID_BITS) - 1)) #define GLEAN_OFFSET(entry) (entry & ((1ULL << GLEAN_INDEX_BITS) - 1)) namespace mozilla::glean { // The category lookup table's entry type using category_entry_t = uint32_t; // The metric lookup table's entry type // This is a bitpacked type with 32 bits available to index into // the string table, 5 bits available to signify the metric type, // and the remaining 27 bits devoted to 2 "signal" // bits to signify important characteristics (metric's a labeled metric's // submetric, metric's been registered at runtime) and 25 bits // for built-in metric ids. // Gives room for 33554432 of each combination of // characteristics (which hopefully will prove to be enough). using metric_entry_t = uint64_t; static_assert(GLEAN_INDEX_BITS + GLEAN_TYPE_BITS + GLEAN_ID_BITS == sizeof(metric_entry_t) * 8, "Index, Type, and ID bits need to fit into a metric_entry_t"); static_assert(GLEAN_TYPE_BITS + GLEAN_ID_BITS <= sizeof(uint32_t) * 8, "Metric Types and IDs need to fit into at most 32 bits"); static_assert(4 < UINT32_MAX, "Too many metric categories generated."); static_assert(61 < 33554432, "Too many metrics generated. Need room for 2 signal bits."); static_assert(24 < 32, "Too many different metric types."); already_AddRefed NewMetricFromId(uint32_t id, nsISupports* aParent) { uint32_t typeId = GLEAN_TYPE_ID(id); uint32_t metricId = GLEAN_METRIC_ID(id); switch (typeId) { case 1: /* boolean */ { return MakeAndAddRef(metricId, aParent); } case 2: /* counter */ { return MakeAndAddRef(metricId, aParent); } case 3: /* custom_distribution */ { return MakeAndAddRef(metricId, aParent); } case 4: /* datetime */ { return MakeAndAddRef(metricId, aParent); } case 5: /* denominator */ { return MakeAndAddRef(metricId, aParent); } case 6: /* dual_labeled_counter */ { return MakeAndAddRef(metricId, aParent); } case 7: /* event */ { return MakeAndAddRef(metricId, aParent); } case 8: /* labeled_boolean */ { return MakeAndAddRef(metricId, 8, aParent); } case 9: /* labeled_counter */ { return MakeAndAddRef(metricId, 9, aParent); } case 10: /* labeled_custom_distribution */ { return MakeAndAddRef(metricId, 10, aParent); } case 11: /* labeled_memory_distribution */ { return MakeAndAddRef(metricId, 11, aParent); } case 12: /* labeled_string */ { return MakeAndAddRef(metricId, 12, aParent); } case 13: /* labeled_timing_distribution */ { return MakeAndAddRef(metricId, 13, aParent); } case 14: /* memory_distribution */ { return MakeAndAddRef(metricId, aParent); } case 15: /* numerator */ { return MakeAndAddRef(metricId, aParent); } case 16: /* object */ { return MakeAndAddRef(metricId, aParent); } case 17: /* quantity */ { return MakeAndAddRef(metricId, aParent); } case 18: /* rate */ { return MakeAndAddRef(metricId, aParent); } case 19: /* string */ { return MakeAndAddRef(metricId, aParent); } case 20: /* string_list */ { return MakeAndAddRef(metricId, aParent); } case 21: /* text */ { return MakeAndAddRef(metricId, aParent); } case 22: /* timespan */ { return MakeAndAddRef(metricId, aParent); } case 23: /* timing_distribution */ { return MakeAndAddRef(metricId, aParent); } case 24: /* uuid */ { return MakeAndAddRef(metricId, aParent); } default: MOZ_ASSERT_UNREACHABLE("Invalid type ID reached when trying to instantiate a new metric"); return nullptr; } } /** * Create a submetric instance for a labeled metric of the provided type and id for the given label. * Assigns or retrieves an id for the submetric from the SDK. * * @param aParentTypeId - The type of the parent labeled metric identified as a number generated during codegen. * Only used to identify which X of LabeledX you are so that X can be created here. * @param aParentMetricId - The metric id for the parent labeled metric. * @param aLabel - The label for the submetric. Might not adhere to the SDK label format. * @param aSubmetricId - an outparam which is assigned the submetric's SDK-generated submetric id. * Used only by GIFFT. */ already_AddRefed NewSubMetricFromIds(uint32_t aParentTypeId, uint32_t aParentMetricId, const nsACString& aLabel, uint32_t* aSubmetricId, nsISupports* aParent) { switch (aParentTypeId) { case 8: { /* labeled_boolean */ auto id = impl::fog_labeled_boolean_get(aParentMetricId, &aLabel); *aSubmetricId = id; return MakeAndAddRef(id, aParent); } case 9: { /* labeled_counter */ auto id = impl::fog_labeled_counter_get(aParentMetricId, &aLabel); *aSubmetricId = id; return MakeAndAddRef(id, aParent); } case 10: { /* labeled_custom_distribution */ auto id = impl::fog_labeled_custom_distribution_get(aParentMetricId, &aLabel); *aSubmetricId = id; return MakeAndAddRef(id, aParent); } case 11: { /* labeled_memory_distribution */ auto id = impl::fog_labeled_memory_distribution_get(aParentMetricId, &aLabel); *aSubmetricId = id; return MakeAndAddRef(id, aParent); } case 12: { /* labeled_string */ auto id = impl::fog_labeled_string_get(aParentMetricId, &aLabel); *aSubmetricId = id; return MakeAndAddRef(id, aParent); } case 13: { /* labeled_timing_distribution */ auto id = impl::fog_labeled_timing_distribution_get(aParentMetricId, &aLabel); *aSubmetricId = id; return MakeAndAddRef(id, aParent); } default: { MOZ_ASSERT_UNREACHABLE("Invalid type ID for submetric."); return nullptr; } } } static Maybe category_result_check(const nsACString& aKey, category_entry_t entry); static Maybe metric_result_check(const nsACString& aKey, metric_entry_t entry); #if defined(_MSC_VER) && !defined(__clang__) const char gCategoryStringTable[] = { #else constexpr char gCategoryStringTable[] = { #endif /* 0 - "test" */ 't', 'e', 's', 't', '\0', /* 5 - "testNested" */ 't', 'e', 's', 't', 'N', 'e', 's', 't', 'e', 'd', '\0', /* 16 - "test2" */ 't', 'e', 's', 't', '2', '\0', /* 22 - "test2Nested" */ 't', 'e', 's', 't', '2', 'N', 'e', 's', 't', 'e', 'd', '\0', }; static_assert(sizeof(gCategoryStringTable) < UINT32_MAX, "Category string table is too large."); const category_entry_t sCategoryByNameLookupEntries[] = { 16ul, 5ul, 0ul, 22ul }; Maybe CategoryByNameLookup(const nsACString& aKey) { static const uint8_t BASES[] = { 2, 2, }; const char* bytes = aKey.BeginReading(); size_t length = aKey.Length(); auto& entry = mozilla::perfecthash::Lookup(bytes, length, BASES, sCategoryByNameLookupEntries); return category_result_check(aKey, entry); } #if defined(_MSC_VER) && !defined(__clang__) const char gMetricStringTable[] = { #else constexpr char gMetricStringTable[] = { #endif /* 0 - "test.booleanMetric" */ 't', 'e', 's', 't', '.', 'b', 'o', 'o', 'l', 'e', 'a', 'n', 'M', 'e', 't', 'r', 'i', 'c', '\0', /* 19 - "test.counterMetric" */ 't', 'e', 's', 't', '.', 'c', 'o', 'u', 'n', 't', 'e', 'r', 'M', 'e', 't', 'r', 'i', 'c', '\0', /* 38 - "test.customDistributionMetric" */ 't', 'e', 's', 't', '.', 'c', 'u', 's', 't', 'o', 'm', 'D', 'i', 's', 't', 'r', 'i', 'b', 'u', 't', 'i', 'o', 'n', 'M', 'e', 't', 'r', 'i', 'c', '\0', /* 68 - "test.labeledBooleanMetric" */ 't', 'e', 's', 't', '.', 'l', 'a', 'b', 'e', 'l', 'e', 'd', 'B', 'o', 'o', 'l', 'e', 'a', 'n', 'M', 'e', 't', 'r', 'i', 'c', '\0', /* 94 - "test.labeledBooleanMetricLabels" */ 't', 'e', 's', 't', '.', 'l', 'a', 'b', 'e', 'l', 'e', 'd', 'B', 'o', 'o', 'l', 'e', 'a', 'n', 'M', 'e', 't', 'r', 'i', 'c', 'L', 'a', 'b', 'e', 'l', 's', '\0', /* 126 - "test.labeledCounterMetric" */ 't', 'e', 's', 't', '.', 'l', 'a', 'b', 'e', 'l', 'e', 'd', 'C', 'o', 'u', 'n', 't', 'e', 'r', 'M', 'e', 't', 'r', 'i', 'c', '\0', /* 152 - "test.labeledCounterMetricLabels" */ 't', 'e', 's', 't', '.', 'l', 'a', 'b', 'e', 'l', 'e', 'd', 'C', 'o', 'u', 'n', 't', 'e', 'r', 'M', 'e', 't', 'r', 'i', 'c', 'L', 'a', 'b', 'e', 'l', 's', '\0', /* 184 - "test.labeledStringMetric" */ 't', 'e', 's', 't', '.', 'l', 'a', 'b', 'e', 'l', 'e', 'd', 'S', 't', 'r', 'i', 'n', 'g', 'M', 'e', 't', 'r', 'i', 'c', '\0', /* 209 - "test.labeledStringMetricLabels" */ 't', 'e', 's', 't', '.', 'l', 'a', 'b', 'e', 'l', 'e', 'd', 'S', 't', 'r', 'i', 'n', 'g', 'M', 'e', 't', 'r', 'i', 'c', 'L', 'a', 'b', 'e', 'l', 's', '\0', /* 240 - "test.memoryDistributionMetric" */ 't', 'e', 's', 't', '.', 'm', 'e', 'm', 'o', 'r', 'y', 'D', 'i', 's', 't', 'r', 'i', 'b', 'u', 't', 'i', 'o', 'n', 'M', 'e', 't', 'r', 'i', 'c', '\0', /* 270 - "test.stringListMetric" */ 't', 'e', 's', 't', '.', 's', 't', 'r', 'i', 'n', 'g', 'L', 'i', 's', 't', 'M', 'e', 't', 'r', 'i', 'c', '\0', /* 292 - "test.stringMetric" */ 't', 'e', 's', 't', '.', 's', 't', 'r', 'i', 'n', 'g', 'M', 'e', 't', 'r', 'i', 'c', '\0', /* 310 - "test.textMetric" */ 't', 'e', 's', 't', '.', 't', 'e', 'x', 't', 'M', 'e', 't', 'r', 'i', 'c', '\0', /* 326 - "test.timespanMetric" */ 't', 'e', 's', 't', '.', 't', 'i', 'm', 'e', 's', 'p', 'a', 'n', 'M', 'e', 't', 'r', 'i', 'c', '\0', /* 346 - "test.timingDistributionMetric" */ 't', 'e', 's', 't', '.', 't', 'i', 'm', 'i', 'n', 'g', 'D', 'i', 's', 't', 'r', 'i', 'b', 'u', 't', 'i', 'o', 'n', 'M', 'e', 't', 'r', 'i', 'c', '\0', /* 376 - "test.unorderedBooleanMetric" */ 't', 'e', 's', 't', '.', 'u', 'n', 'o', 'r', 'd', 'e', 'r', 'e', 'd', 'B', 'o', 'o', 'l', 'e', 'a', 'n', 'M', 'e', 't', 'r', 'i', 'c', '\0', /* 404 - "test.unorderedLabeledBooleanMetric" */ 't', 'e', 's', 't', '.', 'u', 'n', 'o', 'r', 'd', 'e', 'r', 'e', 'd', 'L', 'a', 'b', 'e', 'l', 'e', 'd', 'B', 'o', 'o', 'l', 'e', 'a', 'n', 'M', 'e', 't', 'r', 'i', 'c', '\0', /* 439 - "testNested.aDualLabeledCounter" */ 't', 'e', 's', 't', 'N', 'e', 's', 't', 'e', 'd', '.', 'a', 'D', 'u', 'a', 'l', 'L', 'a', 'b', 'e', 'l', 'e', 'd', 'C', 'o', 'u', 'n', 't', 'e', 'r', '\0', /* 470 - "testNested.anObject" */ 't', 'e', 's', 't', 'N', 'e', 's', 't', 'e', 'd', '.', 'a', 'n', 'O', 'b', 'j', 'e', 'c', 't', '\0', /* 490 - "testNested.datetimeMetric" */ 't', 'e', 's', 't', 'N', 'e', 's', 't', 'e', 'd', '.', 'd', 'a', 't', 'e', 't', 'i', 'm', 'e', 'M', 'e', 't', 'r', 'i', 'c', '\0', /* 516 - "testNested.eventMetric" */ 't', 'e', 's', 't', 'N', 'e', 's', 't', 'e', 'd', '.', 'e', 'v', 'e', 'n', 't', 'M', 'e', 't', 'r', 'i', 'c', '\0', /* 539 - "testNested.eventMetricWithExtra" */ 't', 'e', 's', 't', 'N', 'e', 's', 't', 'e', 'd', '.', 'e', 'v', 'e', 'n', 't', 'M', 'e', 't', 'r', 'i', 'c', 'W', 'i', 't', 'h', 'E', 'x', 't', 'r', 'a', '\0', /* 571 - "testNested.externalDenominator" */ 't', 'e', 's', 't', 'N', 'e', 's', 't', 'e', 'd', '.', 'e', 'x', 't', 'e', 'r', 'n', 'a', 'l', 'D', 'e', 'n', 'o', 'm', 'i', 'n', 'a', 't', 'o', 'r', '\0', /* 602 - "testNested.labeledCustomDist" */ 't', 'e', 's', 't', 'N', 'e', 's', 't', 'e', 'd', '.', 'l', 'a', 'b', 'e', 'l', 'e', 'd', 'C', 'u', 's', 't', 'o', 'm', 'D', 'i', 's', 't', '\0', /* 631 - "testNested.labeledMemoryDist" */ 't', 'e', 's', 't', 'N', 'e', 's', 't', 'e', 'd', '.', 'l', 'a', 'b', 'e', 'l', 'e', 'd', 'M', 'e', 'm', 'o', 'r', 'y', 'D', 'i', 's', 't', '\0', /* 660 - "testNested.labeledTimingDist" */ 't', 'e', 's', 't', 'N', 'e', 's', 't', 'e', 'd', '.', 'l', 'a', 'b', 'e', 'l', 'e', 'd', 'T', 'i', 'm', 'i', 'n', 'g', 'D', 'i', 's', 't', '\0', /* 689 - "testNested.optimizableCounterMetric" */ 't', 'e', 's', 't', 'N', 'e', 's', 't', 'e', 'd', '.', 'o', 'p', 't', 'i', 'm', 'i', 'z', 'a', 'b', 'l', 'e', 'C', 'o', 'u', 'n', 't', 'e', 'r', 'M', 'e', 't', 'r', 'i', 'c', '\0', /* 725 - "testNested.optimizableDisabledCounterMetric" */ 't', 'e', 's', 't', 'N', 'e', 's', 't', 'e', 'd', '.', 'o', 'p', 't', 'i', 'm', 'i', 'z', 'a', 'b', 'l', 'e', 'D', 'i', 's', 'a', 'b', 'l', 'e', 'd', 'C', 'o', 'u', 'n', 't', 'e', 'r', 'M', 'e', 't', 'r', 'i', 'c', '\0', /* 769 - "testNested.quantityMetric" */ 't', 'e', 's', 't', 'N', 'e', 's', 't', 'e', 'd', '.', 'q', 'u', 'a', 'n', 't', 'i', 't', 'y', 'M', 'e', 't', 'r', 'i', 'c', '\0', /* 795 - "testNested.rateMetric" */ 't', 'e', 's', 't', 'N', 'e', 's', 't', 'e', 'd', '.', 'r', 'a', 't', 'e', 'M', 'e', 't', 'r', 'i', 'c', '\0', /* 817 - "testNested.rateWithExternalDenominator" */ 't', 'e', 's', 't', 'N', 'e', 's', 't', 'e', 'd', '.', 'r', 'a', 't', 'e', 'W', 'i', 't', 'h', 'E', 'x', 't', 'e', 'r', 'n', 'a', 'l', 'D', 'e', 'n', 'o', 'm', 'i', 'n', 'a', 't', 'o', 'r', '\0', /* 856 - "testNested.unorderedQuantityMetric" */ 't', 'e', 's', 't', 'N', 'e', 's', 't', 'e', 'd', '.', 'u', 'n', 'o', 'r', 'd', 'e', 'r', 'e', 'd', 'Q', 'u', 'a', 'n', 't', 'i', 't', 'y', 'M', 'e', 't', 'r', 'i', 'c', '\0', /* 891 - "testNested.uuidMetric" */ 't', 'e', 's', 't', 'N', 'e', 's', 't', 'e', 'd', '.', 'u', 'u', 'i', 'd', 'M', 'e', 't', 'r', 'i', 'c', '\0', /* 913 - "test2.booleanMetric" */ 't', 'e', 's', 't', '2', '.', 'b', 'o', 'o', 'l', 'e', 'a', 'n', 'M', 'e', 't', 'r', 'i', 'c', '\0', /* 933 - "test2.counterMetric" */ 't', 'e', 's', 't', '2', '.', 'c', 'o', 'u', 'n', 't', 'e', 'r', 'M', 'e', 't', 'r', 'i', 'c', '\0', /* 953 - "test2.customDistributionMetric" */ 't', 'e', 's', 't', '2', '.', 'c', 'u', 's', 't', 'o', 'm', 'D', 'i', 's', 't', 'r', 'i', 'b', 'u', 't', 'i', 'o', 'n', 'M', 'e', 't', 'r', 'i', 'c', '\0', /* 984 - "test2.labeledBooleanMetric" */ 't', 'e', 's', 't', '2', '.', 'l', 'a', 'b', 'e', 'l', 'e', 'd', 'B', 'o', 'o', 'l', 'e', 'a', 'n', 'M', 'e', 't', 'r', 'i', 'c', '\0', /* 1011 - "test2.labeledBooleanMetricLabels" */ 't', 'e', 's', 't', '2', '.', 'l', 'a', 'b', 'e', 'l', 'e', 'd', 'B', 'o', 'o', 'l', 'e', 'a', 'n', 'M', 'e', 't', 'r', 'i', 'c', 'L', 'a', 'b', 'e', 'l', 's', '\0', /* 1044 - "test2.labeledCounterMetric" */ 't', 'e', 's', 't', '2', '.', 'l', 'a', 'b', 'e', 'l', 'e', 'd', 'C', 'o', 'u', 'n', 't', 'e', 'r', 'M', 'e', 't', 'r', 'i', 'c', '\0', /* 1071 - "test2.labeledCounterMetricLabels" */ 't', 'e', 's', 't', '2', '.', 'l', 'a', 'b', 'e', 'l', 'e', 'd', 'C', 'o', 'u', 'n', 't', 'e', 'r', 'M', 'e', 't', 'r', 'i', 'c', 'L', 'a', 'b', 'e', 'l', 's', '\0', /* 1104 - "test2.labeledStringMetric" */ 't', 'e', 's', 't', '2', '.', 'l', 'a', 'b', 'e', 'l', 'e', 'd', 'S', 't', 'r', 'i', 'n', 'g', 'M', 'e', 't', 'r', 'i', 'c', '\0', /* 1130 - "test2.labeledStringMetricLabels" */ 't', 'e', 's', 't', '2', '.', 'l', 'a', 'b', 'e', 'l', 'e', 'd', 'S', 't', 'r', 'i', 'n', 'g', 'M', 'e', 't', 'r', 'i', 'c', 'L', 'a', 'b', 'e', 'l', 's', '\0', /* 1162 - "test2.memoryDistributionMetric" */ 't', 'e', 's', 't', '2', '.', 'm', 'e', 'm', 'o', 'r', 'y', 'D', 'i', 's', 't', 'r', 'i', 'b', 'u', 't', 'i', 'o', 'n', 'M', 'e', 't', 'r', 'i', 'c', '\0', /* 1193 - "test2.stringListMetric" */ 't', 'e', 's', 't', '2', '.', 's', 't', 'r', 'i', 'n', 'g', 'L', 'i', 's', 't', 'M', 'e', 't', 'r', 'i', 'c', '\0', /* 1216 - "test2.stringMetric" */ 't', 'e', 's', 't', '2', '.', 's', 't', 'r', 'i', 'n', 'g', 'M', 'e', 't', 'r', 'i', 'c', '\0', /* 1235 - "test2.textMetric" */ 't', 'e', 's', 't', '2', '.', 't', 'e', 'x', 't', 'M', 'e', 't', 'r', 'i', 'c', '\0', /* 1252 - "test2.timespanMetric" */ 't', 'e', 's', 't', '2', '.', 't', 'i', 'm', 'e', 's', 'p', 'a', 'n', 'M', 'e', 't', 'r', 'i', 'c', '\0', /* 1273 - "test2.timingDistributionMetric" */ 't', 'e', 's', 't', '2', '.', 't', 'i', 'm', 'i', 'n', 'g', 'D', 'i', 's', 't', 'r', 'i', 'b', 'u', 't', 'i', 'o', 'n', 'M', 'e', 't', 'r', 'i', 'c', '\0', /* 1304 - "test2.unorderedBooleanMetric" */ 't', 'e', 's', 't', '2', '.', 'u', 'n', 'o', 'r', 'd', 'e', 'r', 'e', 'd', 'B', 'o', 'o', 'l', 'e', 'a', 'n', 'M', 'e', 't', 'r', 'i', 'c', '\0', /* 1333 - "test2.unorderedLabeledBooleanMetric" */ 't', 'e', 's', 't', '2', '.', 'u', 'n', 'o', 'r', 'd', 'e', 'r', 'e', 'd', 'L', 'a', 'b', 'e', 'l', 'e', 'd', 'B', 'o', 'o', 'l', 'e', 'a', 'n', 'M', 'e', 't', 'r', 'i', 'c', '\0', /* 1369 - "test2Nested.anObject" */ 't', 'e', 's', 't', '2', 'N', 'e', 's', 't', 'e', 'd', '.', 'a', 'n', 'O', 'b', 'j', 'e', 'c', 't', '\0', /* 1390 - "test2Nested.datetimeMetric" */ 't', 'e', 's', 't', '2', 'N', 'e', 's', 't', 'e', 'd', '.', 'd', 'a', 't', 'e', 't', 'i', 'm', 'e', 'M', 'e', 't', 'r', 'i', 'c', '\0', /* 1417 - "test2Nested.eventMetric" */ 't', 'e', 's', 't', '2', 'N', 'e', 's', 't', 'e', 'd', '.', 'e', 'v', 'e', 'n', 't', 'M', 'e', 't', 'r', 'i', 'c', '\0', /* 1441 - "test2Nested.eventMetricWithExtra" */ 't', 'e', 's', 't', '2', 'N', 'e', 's', 't', 'e', 'd', '.', 'e', 'v', 'e', 'n', 't', 'M', 'e', 't', 'r', 'i', 'c', 'W', 'i', 't', 'h', 'E', 'x', 't', 'r', 'a', '\0', /* 1474 - "test2Nested.externalDenominator" */ 't', 'e', 's', 't', '2', 'N', 'e', 's', 't', 'e', 'd', '.', 'e', 'x', 't', 'e', 'r', 'n', 'a', 'l', 'D', 'e', 'n', 'o', 'm', 'i', 'n', 'a', 't', 'o', 'r', '\0', /* 1506 - "test2Nested.optimizableCounterMetric" */ 't', 'e', 's', 't', '2', 'N', 'e', 's', 't', 'e', 'd', '.', 'o', 'p', 't', 'i', 'm', 'i', 'z', 'a', 'b', 'l', 'e', 'C', 'o', 'u', 'n', 't', 'e', 'r', 'M', 'e', 't', 'r', 'i', 'c', '\0', /* 1543 - "test2Nested.optimizableDisabledCounterMetric" */ 't', 'e', 's', 't', '2', 'N', 'e', 's', 't', 'e', 'd', '.', 'o', 'p', 't', 'i', 'm', 'i', 'z', 'a', 'b', 'l', 'e', 'D', 'i', 's', 'a', 'b', 'l', 'e', 'd', 'C', 'o', 'u', 'n', 't', 'e', 'r', 'M', 'e', 't', 'r', 'i', 'c', '\0', /* 1588 - "test2Nested.quantityMetric" */ 't', 'e', 's', 't', '2', 'N', 'e', 's', 't', 'e', 'd', '.', 'q', 'u', 'a', 'n', 't', 'i', 't', 'y', 'M', 'e', 't', 'r', 'i', 'c', '\0', /* 1615 - "test2Nested.rateMetric" */ 't', 'e', 's', 't', '2', 'N', 'e', 's', 't', 'e', 'd', '.', 'r', 'a', 't', 'e', 'M', 'e', 't', 'r', 'i', 'c', '\0', /* 1638 - "test2Nested.rateWithExternalDenominator" */ 't', 'e', 's', 't', '2', 'N', 'e', 's', 't', 'e', 'd', '.', 'r', 'a', 't', 'e', 'W', 'i', 't', 'h', 'E', 'x', 't', 'e', 'r', 'n', 'a', 'l', 'D', 'e', 'n', 'o', 'm', 'i', 'n', 'a', 't', 'o', 'r', '\0', /* 1678 - "test2Nested.uuidMetric" */ 't', 'e', 's', 't', '2', 'N', 'e', 's', 't', 'e', 'd', '.', 'u', 'u', 'i', 'd', 'M', 'e', 't', 'r', 'i', 'c', '\0', }; static_assert(sizeof(gMetricStringTable) < 4294967296, "Metric string table is too large."); const metric_entry_t sMetricByNameLookupEntries[] = { 11529215235047031977ull, 10952754487038575808ull, 4611686039902224478ull, 6917529066295787729ull, 13258597509137171705ull, 576460962756822296ull, 9223372118459154902ull, 10376293794864694863ull, 1152921624865931989ull, 4611686233175754037ull, 576460821022900600ull, 6917529203734742096ull, 2882303860301365819ull, 6341068382711841399ull, 4611686177341178840ull, 12105675995940390099ull, 1152921740830049730ull, 5188146942529504303ull, 4611686035607257156ull, 8646911542249391718ull, 576460898332312465ull, 5188146796500615294ull, 2305843232551994734ull, 4611686091441832340ull, 1152921620570964657ull, 13835058197016085371ull, 13258597367403250010ull, 1152921513196781587ull, 576460756598390784ull, 12682136752538780900ull, 1152921749419984391ull, 4035225493757232521ull, 1152921654930703269ull, 10952754345304654116ull, 8070450716931523722ull, 9223372255898109273ull, 3458764591129952695ull, 6917529062000820408ull, 9799833038266304052ull, 8070450575197602032ull, 1152921745125017058ull, 5188146938234536980ull, 4035225498052199841ull, 6917529208029709418ull, 1729382269795172390ull, 12682136610804859206ull, 5764607626113450586ull, 4611686181636146163ull, 2305843095113040362ull, 1729382411529094073ull, 4035225356318278148ull, 12105675854206468406ull, 5188146800795582616ull, 4035225360613245467ull, 11529215093313110286ull, 9799832913712251649ull, 13835058317275170446ull, 7493989891613655700ull, 8646911417695339313ull, 10376293670310642459ull, 9799832926597153624ull }; Maybe MetricByNameLookup(const nsACString& aKey) { static const uint16_t BASES[] = { 1, 3, 90, 12, 7, 100, 32, 6, 2, 23, 18, 26, 195, 6, 189,1583, }; const char* bytes = aKey.BeginReading(); size_t length = aKey.Length(); auto& entry = mozilla::perfecthash::Lookup(bytes, length, BASES, sMetricByNameLookupEntries); return metric_result_check(aKey, entry); } /** * Get a category's name from the string table. */ const char* GetCategoryName(category_entry_t entry) { MOZ_ASSERT(entry < sizeof(gCategoryStringTable), "Entry identifier offset larger than string table"); return &gCategoryStringTable[entry]; } /** * Get a metric's identifier from the string table. */ const char* GetMetricIdentifier(metric_entry_t entry) { uint32_t offset = GLEAN_OFFSET(entry); MOZ_ASSERT(offset < sizeof(gMetricStringTable), "Entry identifier offset larger than string table"); return &gMetricStringTable[offset]; } // WARNING: This WILL break if the definition of a `metric_entry_t` changes. // This needs to be updated whenever the lookup macros in // GleanJSMetricsLookup.cpp change (i.e. at the top of this file). // // Looking up a metric name involved indexing into the `gMetricStringTable` with // a valid `metric_entry_t` index. A metric_id (32-bit int) is contained as a // subset of the bits within a `metric_entry_t`, so we enumerate over the list // of possible indicies, given in `sMetricNameByLookupEntries`. This is a little // brittle, as how a `metric_entry_t` encodes a metric_id is an implementation // detail that we shouldn't heavily rely on. However, if profiles start failing, // or giving nonsensical names, it's probably this relationship that needs to be // fixed. /** * Look up the string identifier of a metric by its 32-bit id. * Returns nullptr if we couldn't find a matching identifier for the id. */ extern "C" const char* FOG_GetMetricIdentifier( uint32_t metric_id) { for (metric_entry_t entry : sMetricByNameLookupEntries) { if (static_cast(GLEAN_METRIC_ID(entry >> GLEAN_INDEX_BITS)) == metric_id) { return GetMetricIdentifier(entry); } } // We didn't find our metric_id in the list of metric entries. return nullptr; } /** * Check that the found entry is pointing to the right key * and return it. * Or return `Nothing()` if the entry was not found. */ static Maybe category_result_check(const nsACString& aKey, category_entry_t entry) { if (MOZ_UNLIKELY(entry > sizeof(gCategoryStringTable))) { return Nothing(); } if (aKey.EqualsASCII(gCategoryStringTable + entry)) { return Some(entry); } return Nothing(); } /** * Check if the found entry index is pointing to the right key * and return the corresponding metric ID. * Or return `Nothing()` if the entry was not found. */ static Maybe metric_result_check(const nsACString& aKey, uint64_t entry) { uint32_t metricId = entry >> GLEAN_INDEX_BITS; uint32_t offset = GLEAN_OFFSET(entry); if (offset > sizeof(gMetricStringTable)) { return Nothing(); } if (aKey.EqualsASCII(gMetricStringTable + offset)) { return Some(metricId); } return Nothing(); } #undef GLEAN_INDEX_BITS #undef GLEAN_ID_BITS #undef GLEAN_TYPE_ID #undef GLEAN_METRIC_ID #undef GLEAN_OFFSET } // namespace mozilla::glean