From 3f131cf7b3663990eb7df3296b806c3b3ea3535e Mon Sep 17 00:00:00 2001 From: Gerald Squelart Date: Thu, 13 Aug 2020 03:28:11 +0000 Subject: [PATCH] Bug 1658232 - ProfileBufferEntryKinds.h - r=gregtatum Backtraces and other marker data will be stored directly into a ProfileChunkedBuffer from public code in both profilers, so we will need to have the entry "kinds" available outside of the profiler directories. This also helps with de-duplicating, since the kinds will now be in one spot and shared by both profilers. Differential Revision: https://phabricator.services.mozilla.com/D86508 --- .../baseprofiler/core/ProfileBufferEntry.h | 65 +------------- mozglue/baseprofiler/moz.build | 1 + .../public/ProfileBufferEntryKinds.h | 90 +++++++++++++++++++ tools/profiler/core/ProfileBufferEntry.h | 74 +-------------- 4 files changed, 99 insertions(+), 131 deletions(-) create mode 100644 mozglue/baseprofiler/public/ProfileBufferEntryKinds.h diff --git a/mozglue/baseprofiler/core/ProfileBufferEntry.h b/mozglue/baseprofiler/core/ProfileBufferEntry.h index cd622ad2c439..33b93d059860 100644 --- a/mozglue/baseprofiler/core/ProfileBufferEntry.h +++ b/mozglue/baseprofiler/core/ProfileBufferEntry.h @@ -13,6 +13,7 @@ #include "mozilla/HashFunctions.h" #include "mozilla/HashTable.h" #include "mozilla/Maybe.h" +#include "mozilla/ProfileBufferEntryKinds.h" #include "mozilla/UniquePtr.h" #include "mozilla/Variant.h" #include "mozilla/Vector.h" @@ -22,72 +23,14 @@ namespace mozilla { namespace baseprofiler { -// NOTE! If you add entries, you need to verify if they need to be added to the -// switch statement in DuplicateLastSample! -// This will evaluate the MACRO with (KIND, TYPE, SIZE) -#define FOR_EACH_PROFILE_BUFFER_ENTRY_KIND(MACRO) \ - MACRO(CategoryPair, int, sizeof(int)) \ - MACRO(CollectionStart, double, sizeof(double)) \ - MACRO(CollectionEnd, double, sizeof(double)) \ - MACRO(Label, const char*, sizeof(const char*)) \ - MACRO(FrameFlags, uint64_t, sizeof(uint64_t)) \ - MACRO(DynamicStringFragment, char*, ProfileBufferEntry::kNumChars) \ - MACRO(JitReturnAddr, void*, sizeof(void*)) \ - MACRO(InnerWindowID, uint64_t, sizeof(uint64_t)) \ - MACRO(LineNumber, int, sizeof(int)) \ - MACRO(ColumnNumber, int, sizeof(int)) \ - MACRO(NativeLeafAddr, void*, sizeof(void*)) \ - MACRO(Pause, double, sizeof(double)) \ - MACRO(Resume, double, sizeof(double)) \ - MACRO(PauseSampling, double, sizeof(double)) \ - MACRO(ResumeSampling, double, sizeof(double)) \ - MACRO(Responsiveness, double, sizeof(double)) \ - MACRO(ThreadId, int, sizeof(int)) \ - MACRO(Time, double, sizeof(double)) \ - MACRO(CounterId, void*, sizeof(void*)) \ - MACRO(CounterKey, uint64_t, sizeof(uint64_t)) \ - MACRO(Number, uint64_t, sizeof(uint64_t)) \ - MACRO(Count, int64_t, sizeof(int64_t)) \ - MACRO(ProfilerOverheadTime, double, sizeof(double)) \ - MACRO(ProfilerOverheadDuration, double, sizeof(double)) - class ProfileBufferEntry { public: - // The `Kind` is a single byte identifying the type of data that is actually - // stored in a `ProfileBufferEntry`, as per the list in - // `FOR_EACH_PROFILE_BUFFER_ENTRY_KIND`. - // - // This byte is also used to identify entries in ProfileChunkedBuffer blocks, - // for both "legacy" entries that do contain a `ProfileBufferEntry`, and for - // new types of entries that may carry more data of different types. - // TODO: Eventually each type of "legacy" entry should be replaced with newer, - // more efficient kinds of entries (e.g., stack frames could be stored in one - // bigger entry, instead of multiple `ProfileBufferEntry`s); then we could - // discard `ProfileBufferEntry` and move this enum to a more appropriate spot. - using KindUnderlyingType = uint8_t; - enum class Kind : KindUnderlyingType { - INVALID = 0, -#define KIND(KIND, TYPE, SIZE) KIND, - FOR_EACH_PROFILE_BUFFER_ENTRY_KIND(KIND) -#undef KIND - - // Any value under `LEGACY_LIMIT` represents a `ProfileBufferEntry`. - LEGACY_LIMIT, - - // Any value starting here does *not* represent a `ProfileBufferEntry` and - // requires separate decoding and handling. - - // Marker data, including payload. - MarkerData = LEGACY_LIMIT, - - MODERN_LIMIT - }; + using KindUnderlyingType = ::mozilla::ProfileBufferEntryKindUnderlyingType; + using Kind = ::mozilla::ProfileBufferEntryKind; ProfileBufferEntry(); - // This is equal to sizeof(double), which is the largest non-char variant in - // |u|. - static const size_t kNumChars = 8; + static constexpr size_t kNumChars = ::mozilla::ProfileBufferEntryNumChars; private: // aString must be a static string. diff --git a/mozglue/baseprofiler/moz.build b/mozglue/baseprofiler/moz.build index 29cbb03c6b1d..229b858cd74d 100644 --- a/mozglue/baseprofiler/moz.build +++ b/mozglue/baseprofiler/moz.build @@ -91,6 +91,7 @@ EXPORTS.mozilla += [ 'public/ProfileBufferChunkManagerSingle.h', 'public/ProfileBufferChunkManagerWithLocalLimit.h', 'public/ProfileBufferControlledChunkManager.h', + 'public/ProfileBufferEntryKinds.h', 'public/ProfileBufferEntrySerialization.h', 'public/ProfileBufferIndex.h', 'public/ProfileChunkedBuffer.h', diff --git a/mozglue/baseprofiler/public/ProfileBufferEntryKinds.h b/mozglue/baseprofiler/public/ProfileBufferEntryKinds.h new file mode 100644 index 000000000000..523ba0c9d6e2 --- /dev/null +++ b/mozglue/baseprofiler/public/ProfileBufferEntryKinds.h @@ -0,0 +1,90 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* 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 ProfileBufferEntryKinds_h +#define ProfileBufferEntryKinds_h + +#include + +namespace mozilla { + +// This is equal to sizeof(double), which is the largest non-char variant in +// |u|. +static constexpr size_t ProfileBufferEntryNumChars = 8; + +// NOTE! If you add entries, you need to verify if they need to be added to the +// switch statement in DuplicateLastSample! +// This will evaluate the MACRO with (KIND, TYPE, SIZE) +#define FOR_EACH_PROFILE_BUFFER_ENTRY_KIND(MACRO) \ + MACRO(CategoryPair, int, sizeof(int)) \ + MACRO(CollectionStart, double, sizeof(double)) \ + MACRO(CollectionEnd, double, sizeof(double)) \ + MACRO(Label, const char*, sizeof(const char*)) \ + MACRO(FrameFlags, uint64_t, sizeof(uint64_t)) \ + MACRO(DynamicStringFragment, char*, ProfileBufferEntryNumChars) \ + MACRO(JitReturnAddr, void*, sizeof(void*)) \ + MACRO(InnerWindowID, uint64_t, sizeof(uint64_t)) \ + MACRO(LineNumber, int, sizeof(int)) \ + MACRO(ColumnNumber, int, sizeof(int)) \ + MACRO(NativeLeafAddr, void*, sizeof(void*)) \ + MACRO(Pause, double, sizeof(double)) \ + MACRO(Resume, double, sizeof(double)) \ + MACRO(PauseSampling, double, sizeof(double)) \ + MACRO(ResumeSampling, double, sizeof(double)) \ + MACRO(Responsiveness, double, sizeof(double)) \ + MACRO(ThreadId, int, sizeof(int)) \ + MACRO(Time, double, sizeof(double)) \ + MACRO(TimeBeforeCompactStack, double, sizeof(double)) \ + MACRO(CounterId, void*, sizeof(void*)) \ + MACRO(CounterKey, uint64_t, sizeof(uint64_t)) \ + MACRO(Number, uint64_t, sizeof(uint64_t)) \ + MACRO(Count, int64_t, sizeof(int64_t)) \ + MACRO(ProfilerOverheadTime, double, sizeof(double)) \ + MACRO(ProfilerOverheadDuration, double, sizeof(double)) + +// The `Kind` is a single byte identifying the type of data that is actually +// stored in a `ProfileBufferEntry`, as per the list in +// `FOR_EACH_PROFILE_BUFFER_ENTRY_KIND`. +// +// This byte is also used to identify entries in ProfileChunkedBuffer blocks, +// for both "legacy" entries that do contain a `ProfileBufferEntry`, and for +// new types of entries that may carry more data of different types. +// TODO: Eventually each type of "legacy" entry should be replaced with newer, +// more efficient kinds of entries (e.g., stack frames could be stored in one +// bigger entry, instead of multiple `ProfileBufferEntry`s); then we could +// discard `ProfileBufferEntry` and move this enum to a more appropriate spot. +using ProfileBufferEntryKindUnderlyingType = uint8_t; + +enum class ProfileBufferEntryKind : ProfileBufferEntryKindUnderlyingType { + INVALID = 0, +#define KIND(KIND, TYPE, SIZE) KIND, + FOR_EACH_PROFILE_BUFFER_ENTRY_KIND(KIND) +#undef KIND + + // Any value under `LEGACY_LIMIT` represents a `ProfileBufferEntry`. + LEGACY_LIMIT, + + // Any value starting here does *not* represent a `ProfileBufferEntry` and + // requires separate decoding and handling. + + // Marker data, including payload. + MarkerData = LEGACY_LIMIT, + + // Optional between TimeBeforeCompactStack and CompactStack. + UnresponsiveDurationMs, + + // Collection of legacy stack entries, must follow a ThreadId and + // TimeBeforeCompactStack (which are not included in the CompactStack; + // TimeBeforeCompactStack is equivalent to Time, but indicates that a + // CompactStack follows shortly afterwards). + CompactStack, + + MODERN_LIMIT +}; + +} // namespace mozilla + +#endif // ProfileBufferEntryKinds_h diff --git a/tools/profiler/core/ProfileBufferEntry.h b/tools/profiler/core/ProfileBufferEntry.h index 2d2307dbb822..125b26be3c9f 100644 --- a/tools/profiler/core/ProfileBufferEntry.h +++ b/tools/profiler/core/ProfileBufferEntry.h @@ -13,6 +13,7 @@ #include "mozilla/HashFunctions.h" #include "mozilla/HashTable.h" #include "mozilla/Maybe.h" +#include "mozilla/ProfileBufferEntryKinds.h" #include "mozilla/ProfileJSONWriter.h" #include "mozilla/UniquePtr.h" #include "mozilla/Variant.h" @@ -21,81 +22,14 @@ class ProfilerCodeAddressService; -// NOTE! If you add entries, you need to verify if they need to be added to the -// switch statement in DuplicateLastSample! -// This will evaluate the MACRO with (KIND, TYPE, SIZE) -#define FOR_EACH_PROFILE_BUFFER_ENTRY_KIND(MACRO) \ - MACRO(CategoryPair, int, sizeof(int)) \ - MACRO(CollectionStart, double, sizeof(double)) \ - MACRO(CollectionEnd, double, sizeof(double)) \ - MACRO(Label, const char*, sizeof(const char*)) \ - MACRO(FrameFlags, uint64_t, sizeof(uint64_t)) \ - MACRO(DynamicStringFragment, char*, ProfileBufferEntry::kNumChars) \ - MACRO(JitReturnAddr, void*, sizeof(void*)) \ - MACRO(InnerWindowID, uint64_t, sizeof(uint64_t)) \ - MACRO(LineNumber, int, sizeof(int)) \ - MACRO(ColumnNumber, int, sizeof(int)) \ - MACRO(NativeLeafAddr, void*, sizeof(void*)) \ - MACRO(Pause, double, sizeof(double)) \ - MACRO(Resume, double, sizeof(double)) \ - MACRO(PauseSampling, double, sizeof(double)) \ - MACRO(ResumeSampling, double, sizeof(double)) \ - MACRO(ThreadId, int, sizeof(int)) \ - MACRO(Time, double, sizeof(double)) \ - MACRO(TimeBeforeCompactStack, double, sizeof(double)) \ - MACRO(CounterId, void*, sizeof(void*)) \ - MACRO(CounterKey, uint64_t, sizeof(uint64_t)) \ - MACRO(Number, uint64_t, sizeof(uint64_t)) \ - MACRO(Count, int64_t, sizeof(int64_t)) \ - MACRO(ProfilerOverheadTime, double, sizeof(double)) \ - MACRO(ProfilerOverheadDuration, double, sizeof(double)) - class ProfileBufferEntry { public: - // The `Kind` is a single byte identifying the type of data that is actually - // stored in a `ProfileBufferEntry`, as per the list in - // `FOR_EACH_PROFILE_BUFFER_ENTRY_KIND`. - // - // This byte is also used to identify entries in ProfileChunkedBuffer blocks, - // for both "legacy" entries that do contain a `ProfileBufferEntry`, and for - // new types of entries that may carry more data of different types. - // TODO: Eventually each type of "legacy" entry should be replaced with newer, - // more efficient kinds of entries (e.g., stack frames could be stored in one - // bigger entry, instead of multiple `ProfileBufferEntry`s); then we could - // discard `ProfileBufferEntry` and move this enum to a more appropriate spot. - using KindUnderlyingType = uint8_t; - enum class Kind : KindUnderlyingType { - INVALID = 0, -#define KIND(KIND, TYPE, SIZE) KIND, - FOR_EACH_PROFILE_BUFFER_ENTRY_KIND(KIND) -#undef KIND - - // Any value under `LEGACY_LIMIT` represents a `ProfileBufferEntry`. - LEGACY_LIMIT, - - // Any value starting here does *not* represent a `ProfileBufferEntry` and - // requires separate decoding and handling. - - // Marker data, including payload. - MarkerData = LEGACY_LIMIT, - - // Optional between TimeBeforeCompactStack and CompactStack. - UnresponsiveDurationMs, - - // Collection of legacy stack entries, must follow a ThreadId and - // TimeBeforeCompactStack (which are not included in the CompactStack; - // TimeBeforeCompactStack is equivalent to Time, but indicates that a - // CompactStack follows shortly afterwards). - CompactStack, - - MODERN_LIMIT - }; + using KindUnderlyingType = mozilla::ProfileBufferEntryKindUnderlyingType; + using Kind = mozilla::ProfileBufferEntryKind; ProfileBufferEntry(); - // This is equal to sizeof(double), which is the largest non-char variant in - // |u|. - static const size_t kNumChars = 8; + static constexpr size_t kNumChars = mozilla::ProfileBufferEntryNumChars; private: // aString must be a static string.