Bug 1646266 - Marker option: MarkerCategory - r=gregtatum

The main, and only compulsory, marker option is the `MarkerCategory`, which captures the "category pair", as well as the parent category.

Differential Revision: https://phabricator.services.mozilla.com/D88154
This commit is contained in:
Gerald Squelart 2020-09-01 01:32:35 +00:00
Родитель 56dc2f7c14
Коммит f1e3a40788
2 изменённых файлов: 87 добавлений и 0 удалений

Просмотреть файл

@ -131,6 +131,42 @@ struct ProfileBufferEntryReader::Deserializer<ProfilerStringView<CHAR>> {
}
};
// ----------------------------------------------------------------------------
// Serializer, Deserializer: MarkerCategory
// The serialization contains both category numbers encoded as ULEB128.
template <>
struct ProfileBufferEntryWriter::Serializer<MarkerCategory> {
static Length Bytes(const MarkerCategory& aCategory) {
return ULEB128Size(static_cast<uint32_t>(aCategory.CategoryPair())) +
ULEB128Size(static_cast<uint32_t>(aCategory.Category()));
}
static void Write(ProfileBufferEntryWriter& aEW,
const MarkerCategory& aCategory) {
aEW.WriteULEB128(static_cast<uint32_t>(aCategory.CategoryPair()));
aEW.WriteULEB128(static_cast<uint32_t>(aCategory.Category()));
}
};
template <>
struct ProfileBufferEntryReader::Deserializer<MarkerCategory> {
static void ReadInto(ProfileBufferEntryReader& aER,
MarkerCategory& aCategory) {
aCategory.mCategoryPair = static_cast<baseprofiler::ProfilingCategoryPair>(
aER.ReadULEB128<uint32_t>());
aCategory.mCategory = static_cast<baseprofiler::ProfilingCategory>(
aER.ReadULEB128<uint32_t>());
}
static MarkerCategory Read(ProfileBufferEntryReader& aER) {
return MarkerCategory(static_cast<baseprofiler::ProfilingCategoryPair>(
aER.ReadULEB128<uint32_t>()),
static_cast<baseprofiler::ProfilingCategory>(
aER.ReadULEB128<uint32_t>()));
}
};
} // namespace mozilla
#endif // MOZ_GECKO_PROFILER

Просмотреть файл

@ -199,6 +199,57 @@ class MOZ_STACK_CLASS ProfilerStringView {
using ProfilerString8View = ProfilerStringView<char>;
using ProfilerString16View = ProfilerStringView<char16_t>;
// The classes below are all embedded in a `MarkerOptions` object.
class MarkerOptions;
// This compulsory marker option contains the required category information.
class MarkerCategory {
public:
// Constructor from category pair (aka sub-category) and category.
constexpr MarkerCategory(baseprofiler::ProfilingCategoryPair aCategoryPair,
baseprofiler::ProfilingCategory aCategory)
: mCategoryPair(aCategoryPair), mCategory(aCategory) {}
constexpr baseprofiler::ProfilingCategoryPair CategoryPair() const {
return mCategoryPair;
}
constexpr baseprofiler::ProfilingCategory Category() const {
return mCategory;
}
private:
// The default constructor is only used during deserialization of
// MarkerOptions.
friend MarkerOptions;
constexpr MarkerCategory() = default;
friend ProfileBufferEntryReader::Deserializer<MarkerCategory>;
baseprofiler::ProfilingCategoryPair mCategoryPair =
baseprofiler::ProfilingCategoryPair::OTHER;
baseprofiler::ProfilingCategory mCategory =
baseprofiler::ProfilingCategory::OTHER;
};
namespace baseprofiler::category {
// Each category-pair (aka subcategory) name constructs a MarkerCategory.
// E.g.: mozilla::baseprofiler::category::OTHER_Profiling
// Profiler macros will take the category name alone.
// E.g.: `PROFILER_MARKER_UNTYPED("name", OTHER_Profiling)`
# define CATEGORY_ENUM_BEGIN_CATEGORY(name, labelAsString, color)
# define CATEGORY_ENUM_SUBCATEGORY(supercategory, name, labelAsString) \
static constexpr MarkerCategory name{ProfilingCategoryPair::name, \
ProfilingCategory::supercategory};
# define CATEGORY_ENUM_END_CATEGORY
MOZ_PROFILING_CATEGORY_LIST(CATEGORY_ENUM_BEGIN_CATEGORY,
CATEGORY_ENUM_SUBCATEGORY,
CATEGORY_ENUM_END_CATEGORY)
# undef CATEGORY_ENUM_BEGIN_CATEGORY
# undef CATEGORY_ENUM_SUBCATEGORY
# undef CATEGORY_ENUM_END_CATEGORY
} // namespace baseprofiler::category
} // namespace mozilla
#endif // MOZ_GECKO_PROFILER