forked from mirrors/gecko-dev
With the former 3 enabled we can enable labeled metrics as well, because they only exist for these 3. That also makes testing easier because we don't need to special case that. Differential Revision: https://phabricator.services.mozilla.com/D126800
333 lines
13 KiB
C++
333 lines
13 KiB
C++
// -*- mode: C++ -*-
|
|
|
|
// 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/. */
|
|
|
|
#ifndef mozilla_GleanJSMetricsLookup_h
|
|
#define mozilla_GleanJSMetricsLookup_h
|
|
|
|
#include "mozilla/PerfectHash.h"
|
|
#include "mozilla/Maybe.h"
|
|
#include "mozilla/glean/bindings/MetricTypes.h"
|
|
#include "mozilla/glean/fog_ffi_generated.h"
|
|
|
|
#define GLEAN_INDEX_BITS (32)
|
|
#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
|
|
using metric_entry_t = uint64_t;
|
|
|
|
static_assert(GLEAN_INDEX_BITS + GLEAN_ID_BITS < sizeof(metric_entry_t) * 8, "Index and ID bits need to fit into an category_entry_t");
|
|
static_assert(GLEAN_ID_BITS < sizeof(uint32_t) * 8, "Metric IDs need to fit into less than 32 bit");
|
|
static_assert(2 < UINT32_MAX, "Too many metric categories generated.");
|
|
static_assert(22 < 134217728, "Too many metrics generated.");
|
|
static_assert(18 < 32, "Too many different metric types.");
|
|
|
|
static already_AddRefed<nsISupports> NewMetricFromId(uint32_t id) {
|
|
uint32_t typeId = GLEAN_TYPE_ID(id);
|
|
uint32_t metricId = GLEAN_METRIC_ID(id);
|
|
|
|
switch (typeId) {
|
|
case 1: /* boolean */
|
|
{
|
|
return MakeAndAddRef<GleanBoolean>(metricId);
|
|
}
|
|
case 2: /* labeled_boolean */
|
|
{
|
|
return MakeAndAddRef<GleanLabeled>(metricId, 2);
|
|
}
|
|
case 3: /* counter */
|
|
{
|
|
return MakeAndAddRef<GleanCounter>(metricId);
|
|
}
|
|
case 4: /* labeled_counter */
|
|
{
|
|
return MakeAndAddRef<GleanLabeled>(metricId, 4);
|
|
}
|
|
case 5: /* string */
|
|
{
|
|
return MakeAndAddRef<GleanString>(metricId);
|
|
}
|
|
case 6: /* labeled_string */
|
|
{
|
|
return MakeAndAddRef<GleanLabeled>(metricId, 6);
|
|
}
|
|
case 7: /* string_list */
|
|
{
|
|
return MakeAndAddRef<GleanStringList>(metricId);
|
|
}
|
|
case 8: /* timespan */
|
|
{
|
|
return MakeAndAddRef<GleanTimespan>(metricId);
|
|
}
|
|
case 9: /* timing_distribution */
|
|
{
|
|
return MakeAndAddRef<GleanTimingDistribution>(metricId);
|
|
}
|
|
case 10: /* memory_distribution */
|
|
{
|
|
return MakeAndAddRef<GleanMemoryDistribution>(metricId);
|
|
}
|
|
case 11: /* custom_distribution */
|
|
{
|
|
return MakeAndAddRef<GleanCustomDistribution>(metricId);
|
|
}
|
|
case 12: /* uuid */
|
|
{
|
|
return MakeAndAddRef<GleanUuid>(metricId);
|
|
}
|
|
case 13: /* datetime */
|
|
{
|
|
return MakeAndAddRef<GleanDatetime>(metricId);
|
|
}
|
|
case 14: /* event */
|
|
{
|
|
return MakeAndAddRef<GleanEvent>(metricId);
|
|
}
|
|
case 15: /* quantity */
|
|
{
|
|
return MakeAndAddRef<GleanQuantity>(metricId);
|
|
}
|
|
case 16: /* rate */
|
|
{
|
|
return MakeAndAddRef<GleanRate>(metricId);
|
|
}
|
|
case 17: /* numerator */
|
|
{
|
|
return MakeAndAddRef<GleanNumerator>(metricId);
|
|
}
|
|
case 18: /* denominator */
|
|
{
|
|
return MakeAndAddRef<GleanDenominator>(metricId);
|
|
}
|
|
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.
|
|
*/
|
|
static already_AddRefed<nsISupports> NewSubMetricFromIds(uint32_t aParentTypeId, uint32_t aParentMetricId, const nsACString& aLabel, uint32_t* aSubmetricId) {
|
|
switch (aParentTypeId) {
|
|
case 2: { /* labeled_boolean */
|
|
auto id = impl::fog_labeled_boolean_get(aParentMetricId, &aLabel);
|
|
*aSubmetricId = id;
|
|
return MakeAndAddRef<GleanBoolean>(id);
|
|
}
|
|
case 4: { /* labeled_counter */
|
|
auto id = impl::fog_labeled_counter_get(aParentMetricId, &aLabel);
|
|
*aSubmetricId = id;
|
|
return MakeAndAddRef<GleanCounter>(id);
|
|
}
|
|
case 6: { /* labeled_string */
|
|
auto id = impl::fog_labeled_string_get(aParentMetricId, &aLabel);
|
|
*aSubmetricId = id;
|
|
return MakeAndAddRef<GleanString>(id);
|
|
}
|
|
default: {
|
|
MOZ_ASSERT_UNREACHABLE("Invalid type ID for submetric.");
|
|
return nullptr;
|
|
}
|
|
}
|
|
}
|
|
|
|
static Maybe<uint32_t> category_result_check(const nsACString& aKey, category_entry_t entry);
|
|
static Maybe<uint32_t> 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',
|
|
};
|
|
|
|
|
|
static_assert(sizeof(gCategoryStringTable) < UINT32_MAX, "Category string table is too large.");
|
|
|
|
const category_entry_t sCategoryByNameLookupEntries[] = {
|
|
5ul,
|
|
0ul
|
|
};
|
|
|
|
|
|
|
|
static Maybe<uint32_t>
|
|
CategoryByNameLookup(const nsACString& aKey)
|
|
{
|
|
static const uint8_t BASES[] = {
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
};
|
|
|
|
|
|
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.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',
|
|
/* 45 - "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',
|
|
/* 77 - "test.counterMetric" */ 't', 'e', 's', 't', '.', 'c', 'o', 'u', 'n', 't', 'e', 'r', 'M', 'e', 't', 'r', 'i', 'c', '\0',
|
|
/* 96 - "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',
|
|
/* 122 - "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',
|
|
/* 154 - "test.stringMetric" */ 't', 'e', 's', 't', '.', 's', 't', 'r', 'i', 'n', 'g', 'M', 'e', 't', 'r', 'i', 'c', '\0',
|
|
/* 172 - "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',
|
|
/* 197 - "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',
|
|
/* 228 - "test.stringListMetric" */ 't', 'e', 's', 't', '.', 's', 't', 'r', 'i', 'n', 'g', 'L', 'i', 's', 't', 'M', 'e', 't', 'r', 'i', 'c', '\0',
|
|
/* 250 - "test.timespanMetric" */ 't', 'e', 's', 't', '.', 't', 'i', 'm', 'e', 's', 'p', 'a', 'n', 'M', 'e', 't', 'r', 'i', 'c', '\0',
|
|
/* 270 - "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',
|
|
/* 300 - "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',
|
|
/* 330 - "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',
|
|
/* 360 - "testNested.uuidMetric" */ 't', 'e', 's', 't', 'N', 'e', 's', 't', 'e', 'd', '.', 'u', 'u', 'i', 'd', 'M', 'e', 't', 'r', 'i', 'c', '\0',
|
|
/* 382 - "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',
|
|
/* 408 - "testNested.eventMetric" */ 't', 'e', 's', 't', 'N', 'e', 's', 't', 'e', 'd', '.', 'e', 'v', 'e', 'n', 't', 'M', 'e', 't', 'r', 'i', 'c', '\0',
|
|
/* 431 - "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',
|
|
/* 463 - "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',
|
|
/* 489 - "testNested.rateMetric" */ 't', 'e', 's', 't', 'N', 'e', 's', 't', 'e', 'd', '.', 'r', 'a', 't', 'e', 'M', 'e', 't', 'r', 'i', 'c', '\0',
|
|
/* 511 - "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',
|
|
/* 550 - "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',
|
|
};
|
|
|
|
|
|
static_assert(sizeof(gMetricStringTable) < 4294967296, "Metric string table is too large.");
|
|
|
|
const metric_entry_t sMetricByNameLookupEntries[] = {
|
|
6341068335467200842ull,
|
|
1729382274090139725ull,
|
|
1152921513196781587ull,
|
|
2305843034983497850ull,
|
|
5764607578868810028ull,
|
|
8070450605262373272ull,
|
|
3458764548180279468ull,
|
|
10376293635950903846ull,
|
|
8646911366155731407ull,
|
|
9799832879352513023ull,
|
|
2882303791581888666ull,
|
|
1152921517491748909ull,
|
|
4035225309073637604ull,
|
|
6917529092065591656ull,
|
|
4611686065672028410ull,
|
|
7493989848663982462ull,
|
|
8070450609557340591ull,
|
|
3458764552475246789ull,
|
|
5188146822270419214ull,
|
|
576460756598390784ull,
|
|
2305843030688530528ull,
|
|
9223372122754122217ull
|
|
};
|
|
|
|
|
|
|
|
static Maybe<uint32_t>
|
|
MetricByNameLookup(const nsACString& aKey)
|
|
{
|
|
static const uint8_t BASES[] = {
|
|
0, 0, 0, 1, 0, 2, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0,
|
|
1, 1, 0, 0, 1, 0, 0, 1, 0, 4, 0, 0, 1, 0, 1, 0,
|
|
2, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 3, 0, 6, 0, 0,
|
|
0, 0, 10, 0, 0, 1, 0, 0, 0, 0, 4, 0, 0, 0, 0, 17,
|
|
};
|
|
|
|
|
|
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.
|
|
*/
|
|
static 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.
|
|
*/
|
|
static 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];
|
|
}
|
|
|
|
/**
|
|
* 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<uint32_t> 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<uint32_t> 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
|
|
#endif // mozilla_GleanJSMetricsLookup_h
|