Bug 1375392 - Tweak the PROFILER_LABEL* macros. r=mstange.
This patch makes the following changes to the macros.
- Removes PROFILER_LABEL_FUNC. It's only suitable for use in functions outside
classes, due to PROFILER_FUNCTION_NAME not getting class names, and it was
mostly misused.
- Removes PROFILER_FUNCTION_NAME. It's no longer used, and __func__ is
universally available now anyway.
- Combines the first two string literal arguments of PROFILER_LABEL and
PROFILER_LABEL_DYNAMIC into a single argument. There was no good reason for
them to be separate, and it forced a '::' in the label, which isn't always
appropriate. Also, the meaning of the "name_space" argument was interpreted
in an interesting variety of ways.
- Adds an "AUTO_" prefix to PROFILER_LABEL and PROFILER_LABEL_DYNAMIC, to make
it clearer they construct RAII objects rather than just being function calls.
(I myself have screwed up the scoping because of this in the past.)
- Fills in the 'js::ProfileEntry::Category::' qualifier within the macro, so
the caller doesn't need to. This makes a *lot* more of the uses fit onto a
single line.
The patch also makes the following changes to the macro uses (beyond those
required by the changes described above).
- Fixes a bunch of labels that had gotten out of sync with the name of the
class and/or function that encloses them.
- Removes a useless PROFILER_LABEL use within a trivial scope in
EventStateManager::DispatchMouseOrPointerEvent(). It clearly wasn't serving
any useful purpose. It also serves as extra evidence that the AUTO_ prefix is
a good idea.
- Tweaks DecodePool::SyncRunIf{Preferred,Possible} so that the labelling is
done within them, instead of at their callsites, because that's a more
standard way of doing things.

--- a/layout/base/nsRefreshDriver.cpp+++ b/layout/base/nsRefreshDriver.cpp@@ -1740,18 +1740,17 @@ nsRefreshDriver::Tick(int64_t aNowEpoch, "Shouldn't have a JSContext on the stack"); if (nsNPAPIPluginInstance::InPluginCallUnsafeForReentry()) { NS_ERROR("Refresh driver should not run during plugin call!"); // Try to survive this by just ignoring the refresh tick. return; }- PROFILER_LABEL("nsRefreshDriver", "Tick",- js::ProfileEntry::Category::GRAPHICS);+ AUTO_PROFILER_LABEL("nsRefreshDriver::Tick", GRAPHICS); // We're either frozen or we were disconnected (likely in the middle // of a tick iteration). Just do nothing here, since our // prescontext went away. if (IsFrozen() || !mPresContext) { return; }

--- a/layout/painting/nsCSSRendering.cpp+++ b/layout/painting/nsCSSRendering.cpp@@ -631,18 +631,17 @@ nsCSSRendering::PaintBorder(nsPresContex gfxContext& aRenderingContext, nsIFrame* aForFrame, const nsRect& aDirtyRect, const nsRect& aBorderArea, nsStyleContext* aStyleContext, PaintBorderFlags aFlags, Sides aSkipSides) {- PROFILER_LABEL("nsCSSRendering", "PaintBorder",- js::ProfileEntry::Category::GRAPHICS);+ AUTO_PROFILER_LABEL("nsCSSRendering::PaintBorder", GRAPHICS); nsStyleContext *styleIfVisited = aStyleContext->GetStyleIfVisited(); const nsStyleBorder *styleBorder = aStyleContext->StyleBorder(); // Don't check RelevantLinkVisited here, since we want to take the // same amount of time whether or not it's true. if (!styleIfVisited) { return PaintBorderWithStyleBorder(aPresContext, aRenderingContext, aForFrame, aDirtyRect, aBorderArea, *styleBorder,@@ -1906,21 +1905,20 @@ nsCSSRendering::PaintBGParams::ForSingle return result; } DrawResult nsCSSRendering::PaintStyleImageLayer(const PaintBGParams& aParams, gfxContext& aRenderingCtx) {- PROFILER_LABEL("nsCSSRendering", "PaintBackground",- js::ProfileEntry::Category::GRAPHICS);+ AUTO_PROFILER_LABEL("nsCSSRendering::PaintStyleImageLayer", GRAPHICS); NS_PRECONDITION(aParams.frame,- "Frame is expected to be provided to PaintBackground");+ "Frame is expected to be provided to PaintStyleImageLayer"); nsStyleContext *sc; if (!FindBackground(aParams.frame, &sc)) { // We don't want to bail out if moz-appearance is set on a root // node. If it has a parent content node, bail because it's not // a root, otherwise keep going in order to let the theme stuff // draw the background. The canvas really should be drawing the // bg, but there's no way to hook that up via css.@@ -2502,17 +2500,17 @@ DetermineCompositionOp(const nsCSSRender DrawResult nsCSSRendering::PaintStyleImageLayerWithSC(const PaintBGParams& aParams, gfxContext& aRenderingCtx, nsStyleContext *aBackgroundSC, const nsStyleBorder& aBorder) { NS_PRECONDITION(aParams.frame,- "Frame is expected to be provided to PaintBackground");+ "Frame is expected to be provided to PaintStyleImageLayerWithSC"); // If we're drawing all layers, aCompositonOp is ignored, so make sure that // it was left at its default value. MOZ_ASSERT(aParams.layer != -1 || aParams.compositionOp == CompositionOp::OP_OVER); // Check to see if we have an appearance defined. If so, we let the theme // renderer draw the background and bail out.

--- a/layout/painting/nsCSSRenderingBorders.cpp+++ b/layout/painting/nsCSSRenderingBorders.cpp@@ -3368,18 +3368,17 @@ nsCSSBorderRenderer::DrawBorders() PrintAsFormatString(" allBordersSame: %d dashedSides: 0x%02x\n", allBordersSame, dashedSides); if (allBordersSame && !forceSeparateCorners) { /* Draw everything in one go */ DrawBorderSides(eSideBitsAll); PrintAsStringNewline("---------------- (1)"); } else {- PROFILER_LABEL("nsCSSBorderRenderer", "DrawBorders::multipass",- js::ProfileEntry::Category::GRAPHICS);+ AUTO_PROFILER_LABEL("nsCSSBorderRenderer::DrawBorders:multipass", GRAPHICS); /* We have more than one pass to go. Draw the corners separately from the sides. */ /* * If we have a 1px-wide border, the corners are going to be * negligible, so don't bother doing anything fancy. Just extend * the top and bottom borders to the right 1px and the left border * to the bottom 1px. We do this by twiddling the corner dimensions,

--- a/tools/profiler/public/GeckoProfiler.h+++ b/tools/profiler/public/GeckoProfiler.h@@ -319,60 +319,51 @@ PROFILER_FUNC(PseudoStack* profiler_get_ //--------------------------------------------------------------------------- #define PROFILER_APPEND_LINE_NUMBER_PASTE(id, line) id ## line #define PROFILER_APPEND_LINE_NUMBER_EXPAND(id, line) \ PROFILER_APPEND_LINE_NUMBER_PASTE(id, line) #define PROFILER_APPEND_LINE_NUMBER(id) \ PROFILER_APPEND_LINE_NUMBER_EXPAND(id, __LINE__)-#if defined(__GNUC__) || defined(_MSC_VER)-# define PROFILER_FUNCTION_NAME __FUNCTION__-#else- // From C99, supported by some C++ compilers. Just the raw function name.-# define PROFILER_FUNCTION_NAME __func__-#endif- // Insert an RAII object in this scope to enter a pseudo stack frame. Any // samples collected in this scope will contain this label in their pseudo-// stack. The name_space and info arguments must be string literals.-// Use PROFILER_LABEL_DYNAMIC if you want to add additional / dynamic+// stack. The label argument must be a string literal. It is usually of the+// form "ClassName::FunctionName". (Ideally we'd use the compiler to provide+// that for us, but __func__ gives us the function name without the class+// name.) If the label applies to only part of a function, you can qualify it+// like this: "ClassName::FunctionName:PartName".+//+// Use AUTO_PROFILER_LABEL_DYNAMIC if you want to add additional / dynamic // information to the pseudo stack frame.-#define PROFILER_LABEL(name_space, info, category) \+#define AUTO_PROFILER_LABEL(label, category) \ mozilla::AutoProfilerLabel \- PROFILER_APPEND_LINE_NUMBER(profiler_raii)(name_space "::" info, nullptr, \- __LINE__, category)+ PROFILER_APPEND_LINE_NUMBER(profiler_raii)( \+ label, nullptr, __LINE__, js::ProfileEntry::Category::category)-// Similar to PROFILER_LABEL, PROFILER_LABEL_FUNC will push/pop the enclosing-// functon name as the pseudostack label.-#define PROFILER_LABEL_FUNC(category) \- mozilla::AutoProfilerLabel \- PROFILER_APPEND_LINE_NUMBER(profiler_raii)(PROFILER_FUNCTION_NAME, nullptr, \- __LINE__, category)--// Similar to PROFILER_LABEL, but with an additional string. The inserted RAII-// object stores the dynamicStr pointer in a field; it does not copy the string.-// This means that the string you pass to this macro needs to live at least-// until the end of the current scope.+// Similar to AUTO_PROFILER_LABEL, but with an additional string. The inserted+// RAII object stores the dynamicStr pointer in a field; it does not copy the+// string. This means that the string you pass to this macro needs to live at+// least until the end of the current scope. // // If the profiler samples the current thread and walks the pseudo stack while // this RAII object is on the stack, it will copy the supplied string into the // profile buffer. So there's one string copy operation, and it happens at // sample time. //-// Compare this to the plain PROFILER_LABEL macro, which only accepts literal-// strings: When the pseudo stack frames generated by PROFILER_LABEL are-// sampled, no string copy needs to be made because the profile buffer can-// just store the raw pointers to the literal strings. Consequently,-// PROFILER_LABEL frames take up considerably less space in the profile buffer-// than PROFILER_LABEL_DYNAMIC frames.-#define PROFILER_LABEL_DYNAMIC(name_space, info, category, dynamicStr) \+// Compare this to the plain AUTO_PROFILER_LABEL macro, which only accepts+// literal strings: When the pseudo stack frames generated by+// AUTO_PROFILER_LABEL are sampled, no string copy needs to be made because the+// profile buffer can just store the raw pointers to the literal strings.+// Consequently, AUTO_PROFILER_LABEL frames take up considerably less space in+// the profile buffer than AUTO_PROFILER_LABEL_DYNAMIC frames.+#define AUTO_PROFILER_LABEL_DYNAMIC(label, category, dynamicStr) \ mozilla::AutoProfilerLabel \- PROFILER_APPEND_LINE_NUMBER(profiler_raii)(name_space "::" info, dynamicStr, \- __LINE__, category)+ PROFILER_APPEND_LINE_NUMBER(profiler_raii)( \+ label, dynamicStr, __LINE__, js::ProfileEntry::Category::category) // Insert a marker in the profile timeline. This is useful to delimit something // important happening such as the first paint. Unlike labels, which are only // recorded in the profile buffer if a sample is collected while the label is // on the pseudostack, markers will always be recorded in the profile buffer. // A no-op if the profiler is inactive or in privacy mode. PROFILER_FUNC_VOID(profiler_add_marker(const char* aMarkerName)) PROFILER_FUNC_VOID(

--- a/widget/windows/nsFilePicker.cpp+++ b/widget/windows/nsFilePicker.cpp@@ -419,17 +419,17 @@ nsFilePicker::ShowFolderPicker(const nsS * * @param aInitialDir The initial directory, the last used directory will be * used if left blank. * @return true if a file was selected successfully. */ bool nsFilePicker::ShowFilePicker(const nsString& aInitialDir) {- PROFILER_LABEL_FUNC(js::ProfileEntry::Category::OTHER);+ AUTO_PROFILER_LABEL("nsFilePicker::ShowFilePicker", OTHER); if (!IsWin8OrLater()) { // Some Windows 7 users are experiencing a race condition when some dlls // that are loaded by the file picker cause a crash while attempting to shut // down the COM multithreaded apartment. By instantiating EnsureMTA, we hold // an additional reference to the MTA that should prevent this race, since // the MTA will remain alive until shutdown. EnsureMTA ensureMTA;