Bug 1500692 - Add an AUTO_PROFILER_LABEL_CATEGORY_PAIR macro. r=njn

This is similar to AUTO_PROFILER_LABEL, but with only one argument: a category pair.
This reduces duplication for label frames that want just the subcategory name as
their label: Instead of AUTO_PROFILER_LABEL("Layer building", GRAPHICS_LayerBuilding),
you can now just write AUTO_PROFILER_LABEL_CATEGORY_PAIR(GRAPHICS_LayerBuilding) and
the string will automatically be taken from the subcategory.

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Markus Stange 2019-02-16 17:37:58 +00:00
Родитель 0b151b8c2b
Коммит 99df373110
2 изменённых файлов: 29 добавлений и 6 удалений

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

@ -157,7 +157,7 @@ class ProfilingStackFrame {
mozilla::recordreplay::Behavior::DontPreserve>
pcOffsetIfJS_;
// Bits 0...7 hold the Flags. Bits 8...31 hold the category pair.
// Bits 0...8 hold the Flags. Bits 9...31 hold the category pair.
mozilla::Atomic<uint32_t, mozilla::ReleaseAcquire,
mozilla::recordreplay::Behavior::DontPreserve>
flagsAndCategoryPair_;
@ -178,8 +178,8 @@ class ProfilingStackFrame {
return *this;
}
// 8 bits for the flags.
// That leaves 32 - 8 = 25 bits for the category pair.
// 9 bits for the flags.
// That leaves 32 - 9 = 23 bits for the category pair.
enum class Flags : uint32_t {
// The first three flags describe the kind of the frame and are
// mutually exclusive. (We still give them individual bits for
@ -217,7 +217,11 @@ class ProfilingStackFrame {
// tree view.
RELEVANT_FOR_JS = 1 << 7,
FLAGS_BITCOUNT = 8,
// If set, causes the label on this ProfilingStackFrame to be ignored
// and to be replaced by the subcategory's label.
LABEL_DETERMINED_BY_CATEGORY_PAIR = 1 << 8,
FLAGS_BITCOUNT = 9,
FLAGS_MASK = (1 << FLAGS_BITCOUNT) - 1
};
@ -254,8 +258,16 @@ class ProfilingStackFrame {
}
}
void setLabel(const char* aLabel) { label_ = aLabel; }
const char* label() const { return label_; }
const char* label() const {
uint32_t flagsAndCategoryPair = flagsAndCategoryPair_;
if (flagsAndCategoryPair &
uint32_t(Flags::LABEL_DETERMINED_BY_CATEGORY_PAIR)) {
auto categoryPair = JS::ProfilingCategoryPair(
flagsAndCategoryPair >> uint32_t(Flags::FLAGS_BITCOUNT));
return JS::GetProfilingCategoryPairInfo(categoryPair).mLabel;
}
return label_;
}
const char* dynamicString() const { return dynamicString_; }

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

@ -42,6 +42,7 @@
# define PROFILER_CLEAR_JS_CONTEXT()
# define AUTO_PROFILER_LABEL(label, categoryPair)
# define AUTO_PROFILER_LABEL_CATEGORY_PAIR(categoryPair)
# define AUTO_PROFILER_LABEL_DYNAMIC_CSTR(label, categoryPair, cStr)
# define AUTO_PROFILER_LABEL_DYNAMIC_NSCSTRING(label, categoryPair, nsCStr)
# define AUTO_PROFILER_LABEL_DYNAMIC_LOSSY_NSSTRING(label, categoryPair, nsStr)
@ -522,6 +523,16 @@ mozilla::Maybe<ProfilerBufferInfo> profiler_get_buffer_info();
mozilla::AutoProfilerLabel PROFILER_RAII( \
label, nullptr, JS::ProfilingCategoryPair::categoryPair)
// Similar to AUTO_PROFILER_LABEL, but with only one argument: the category
// pair. The label string is taken from the category pair. This is convenient
// for labels like AUTO_PROFILER_LABEL_CATEGORY_PAIR(GRAPHICS_LayerBuilding)
// which would otherwise just repeat the string.
# define AUTO_PROFILER_LABEL_CATEGORY_PAIR(categoryPair) \
mozilla::AutoProfilerLabel PROFILER_RAII( \
"", nullptr, JS::ProfilingCategoryPair::categoryPair, \
uint32_t(js::ProfilingStackFrame::Flags:: \
LABEL_DETERMINED_BY_CATEGORY_PAIR))
// Similar to AUTO_PROFILER_LABEL, but with an additional string. The inserted
// RAII object stores the cStr pointer in a field; it does not copy the string.
//