Bug 1773205 [wpt PR 34343] - SVG Text NG: Improve performance on ancestor scaling...
[gecko.git] / mozglue / misc / AutoProfilerLabel.h
blob2cbd8252c91d607f82ba272a19df302da8d1d04e
1 /* -*- Mode: C++; tab-width: 2; 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/. */
7 #ifndef mozilla_AutoProfilerLabel_h
8 #define mozilla_AutoProfilerLabel_h
10 #include "mozilla/Attributes.h"
11 #include "mozilla/Tuple.h"
12 #include "mozilla/Types.h"
14 // The Gecko Profiler defines AutoProfilerLabel, an RAII class for
15 // pushing/popping frames to/from the ProfilingStack.
17 // This file defines a class of the same name that does much the same thing,
18 // but which can be used in (and only in) mozglue. A different class is
19 // necessary because mozglue cannot directly access sProfilingStack.
21 // Note that this class is slightly slower than the other AutoProfilerLabel,
22 // and it lacks the macro wrappers. It also is effectively hardwired to use
23 // JS::ProfilingCategory::OTHER as the category pair, because that's what
24 // the callbacks provided by the profiler use. (Specifying the categories in
25 // this file would require #including ProfilingCategory.h in mozglue, which we
26 // don't want to do.)
28 namespace mozilla {
30 // Enter should return a pointer that will be given to Exit.
31 typedef void* (*ProfilerLabelEnter)(const char* aLabel,
32 const char* aDynamicString, void* aSp);
33 typedef void (*ProfilerLabelExit)(void* EntryContext);
35 // Register callbacks that do the entry/exit work involving sProfilingStack.
36 MFBT_API void RegisterProfilerLabelEnterExit(ProfilerLabelEnter aEnter,
37 ProfilerLabelExit aExit);
39 // This #ifdef prevents this AutoProfilerLabel from being defined in libxul,
40 // which would conflict with the one in the profiler.
41 #ifdef IMPL_MFBT
43 class MOZ_RAII AutoProfilerLabel {
44 public:
45 AutoProfilerLabel(const char* aLabel, const char* aDynamicString);
46 ~AutoProfilerLabel();
48 private:
49 void* mEntryContext;
50 // Number of RegisterProfilerLabelEnterExit calls, to avoid giving an entry
51 // context from one generation to the next.
52 uint32_t mGeneration;
55 using ProfilerLabel = Tuple<void*, uint32_t>;
57 bool IsProfilerPresent();
58 ProfilerLabel ProfilerLabelBegin(const char* aLabelName,
59 const char* aDynamicString, void* aSp);
60 void ProfilerLabelEnd(const ProfilerLabel& aLabel);
62 inline bool IsValidProfilerLabel(const ProfilerLabel& aLabel) {
63 return !!Get<0>(aLabel);
66 #endif
68 } // namespace mozilla
70 #endif // mozilla_AutoProfilerLabel_h