This was previously discussed in issue 705169, and has recently come up in https://chromium-review.googlesource.com/c/569002/ and https://chromium-review.googlesource.com/c/566764/: both CLs want to plumb a mojo enum value to UMA it.
However, it would be better if the enum itself didn't define a kCount enumerator, as:
- this forces all switch statements to handle a sentinel case that should "never happen"
- Mojo enum validation will accept the sentinel value, even though it would be better to reject it
As mojo enums are just generated, it should be easy to generate something like:
static constexpr EnumType EnumType_COUNT =
static_cast<EnumType>(static_cast<int32_t>(EnumType::max_value()) + 1);
And then this value can just be used in the histogram macros.
Comment 1 by yzshen@chromium.org
, Jul 14 2017Enum values could be set: enum Foo { a = 3, b = 4 } In this case, will Foo_COUNT be 5? That might be confusing. Foo_max (= b) seems more clear IMO.