ProfilingCategory.cpp (4251B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- 2 * vim: set ts=8 sts=2 et sw=2 tw=80: 3 * This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #include "mozilla/BaseProfilingCategory.h" 8 9 #include "mozilla/Assertions.h" 10 11 namespace mozilla { 12 namespace baseprofiler { 13 14 // clang-format off 15 16 // ProfilingSubcategory_X: 17 // One enum for each category X, listing that category's subcategories. This 18 // allows the sProfilingCategoryInfo macro construction below to look up a 19 // per-category index for a subcategory. 20 #define SUBCATEGORY_ENUMS_BEGIN_CATEGORY(name, labelAsString, color) \ 21 enum class ProfilingSubcategory_##name : uint32_t { 22 #define SUBCATEGORY_ENUMS_SUBCATEGORY(category, name, labelAsString) \ 23 name, 24 #define SUBCATEGORY_ENUMS_END_CATEGORY \ 25 }; 26 MOZ_PROFILING_CATEGORY_LIST(SUBCATEGORY_ENUMS_BEGIN_CATEGORY, 27 SUBCATEGORY_ENUMS_SUBCATEGORY, 28 SUBCATEGORY_ENUMS_END_CATEGORY) 29 #undef SUBCATEGORY_ENUMS_BEGIN_CATEGORY 30 #undef SUBCATEGORY_ENUMS_SUBCATEGORY 31 #undef SUBCATEGORY_ENUMS_END_CATEGORY 32 33 // sProfilingCategoryPairInfo: 34 // A list of ProfilingCategoryPairInfos with the same order as 35 // ProfilingCategoryPair, which can be used to map a ProfilingCategoryPair to 36 // its information. 37 #define CATEGORY_PAIR_INFO_BEGIN_CATEGORY(name, labelAsString, color) 38 #define CATEGORY_PAIR_INFO_SUBCATEGORY(category, name, labelAsString) \ 39 {ProfilingCategory::category, \ 40 uint32_t(ProfilingSubcategory_##category::name), labelAsString}, 41 #define CATEGORY_PAIR_INFO_END_CATEGORY 42 static constexpr ProfilingCategoryPairInfo sProfilingCategoryPairInfo[] = { 43 MOZ_PROFILING_CATEGORY_LIST(CATEGORY_PAIR_INFO_BEGIN_CATEGORY, 44 CATEGORY_PAIR_INFO_SUBCATEGORY, 45 CATEGORY_PAIR_INFO_END_CATEGORY) 46 }; 47 #undef CATEGORY_PAIR_INFO_BEGIN_CATEGORY 48 #undef CATEGORY_PAIR_INFO_SUBCATEGORY 49 #undef CATEGORY_PAIR_INFO_END_CATEGORY 50 51 // sSubcategoryNames_X: 52 // One array per category, listing the subcategory names of that category. 53 #define SUBCATEGORY_NAMES_BEGIN_CATEGORY(name, labelAsString, color) \ 54 static constexpr const char* sSubcategoryNames_##name[] = { 55 #define SUBCATEGORY_NAMES_SUBCATEGORY(supercategory, name, labelAsString) labelAsString, 56 #define SUBCATEGORY_NAMES_END_CATEGORY \ 57 }; 58 59 MOZ_PROFILING_CATEGORY_LIST(SUBCATEGORY_NAMES_BEGIN_CATEGORY, 60 SUBCATEGORY_NAMES_SUBCATEGORY, 61 SUBCATEGORY_NAMES_END_CATEGORY) 62 63 #undef SUBCATEGORY_NAMES_BEGIN_CATEGORY 64 #undef SUBCATEGORY_NAMES_SUBCATEGORY 65 #undef SUBCATEGORY_NAMES_END_CATEGORY 66 67 // sProfilingCategoryInfoList: 68 // A list of ProfilingCategoryInfo for all categories. 69 #define CATEGORY_INFO_LIST_BEGIN_CATEGORY(name, labelAsString, color) \ 70 {labelAsString, color, Span{sSubcategoryNames_##name}}, 71 #define CATEGORY_INFO_LIST_SUBCATEGORY(supercategory, name, labelAsString) 72 #define CATEGORY_INFO_LIST_END_CATEGORY 73 74 static constexpr ProfilingCategoryInfo sProfilingCategoryInfoList[] = { 75 MOZ_PROFILING_CATEGORY_LIST(CATEGORY_INFO_LIST_BEGIN_CATEGORY, 76 CATEGORY_INFO_LIST_SUBCATEGORY, 77 CATEGORY_INFO_LIST_END_CATEGORY) 78 }; 79 80 #undef CATEGORY_INFO_LIST_BEGIN_CATEGORY 81 #undef CATEGORY_INFO_LIST_SUBCATEGORY 82 #undef CATEGORY_INFO_LIST_END_CATEGORY 83 84 // clang-format on 85 86 Span<const ProfilingCategoryInfo> GetProfilingCategoryList() { 87 return Span{sProfilingCategoryInfoList}; 88 } 89 90 const ProfilingCategoryPairInfo& GetProfilingCategoryPairInfo( 91 ProfilingCategoryPair aCategoryPair) { 92 static_assert( 93 std::size(sProfilingCategoryPairInfo) == 94 uint32_t(ProfilingCategoryPair::COUNT), 95 "sProfilingCategoryPairInfo and ProfilingCategory need to have the " 96 "same order and the same length"); 97 98 uint32_t categoryPairIndex = uint32_t(aCategoryPair); 99 MOZ_RELEASE_ASSERT(categoryPairIndex <= 100 uint32_t(ProfilingCategoryPair::LAST)); 101 return sProfilingCategoryPairInfo[categoryPairIndex]; 102 } 103 104 } // namespace baseprofiler 105 } // namespace mozilla