Bug 1313327 - Flatten the Telemetry Event enums. r=janerik

To support a non-templated API for recording events by enum, all the enum
values must be of the same type. Inheritence doesn't really seem to be a thing
in C++ enums, so that means flattening them all into a single, big enum the
way Scalars and Histograms work.

Alas.

Differential Revision: https://phabricator.services.mozilla.com/D18691

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Chris H-C 2019-02-08 11:32:44 +00:00
parent fc8592cd08
commit e2b7d6e230
2 changed files with 9 additions and 13 deletions

View File

@ -21,11 +21,11 @@ file_header = """\
#define mozilla_TelemetryEventEnums_h
namespace mozilla {
namespace Telemetry {
namespace EventID {
enum class EventID : uint32_t {\
"""
file_footer = """\
} // namespace EventID
};
} // namespace mozilla
} // namespace Telemetry
#endif // mozilla_TelemetryEventEnums_h
@ -60,20 +60,15 @@ def main(output, *filenames):
category_cpp = indexed[0][1].category_cpp
print(" // category: %s" % category, file=output)
print("enum class %s : uint32_t {" % category_cpp, file=output)
for event_index, e in indexed:
if e.record_on_os(buildconfig.substs["OS_TARGET"]):
for offset, label in enumerate(e.enum_labels):
print(" %s = %d," % (label, event_index + offset), file=output)
print(" %s_%s = %d,"
% (category_cpp, label, event_index + offset), file=output)
print("};\n", file=output)
print("#if defined(_MSC_VER) && !defined(__clang__)", file=output)
print("const uint32_t EventCount = %d;" % index, file=output)
print("#else", file=output)
print("constexpr uint32_t EventCount = %d;" % index, file=output)
print("#endif\n", file=output)
print(" // meta", file=output)
print(" EventCount = %d," % index, file=output)
print(file_footer, file=output)

View File

@ -99,7 +99,8 @@ namespace TelemetryIPCAccumulator = mozilla::TelemetryIPCAccumulator;
namespace {
const uint32_t kEventCount = mozilla::Telemetry::EventID::EventCount;
const uint32_t kEventCount =
static_cast<uint32_t>(mozilla::Telemetry::EventID::EventCount);
// This is a special event id used to mark expired events, to make expiry checks
// cheap at runtime.
const uint32_t kExpiredEventId = std::numeric_limits<uint32_t>::max();