summaryrefslogtreecommitdiffstats
path: root/tools/profiler/public/ProfilerCounts.h
diff options
context:
space:
mode:
Diffstat (limited to 'tools/profiler/public/ProfilerCounts.h')
-rw-r--r--tools/profiler/public/ProfilerCounts.h30
1 files changed, 27 insertions, 3 deletions
diff --git a/tools/profiler/public/ProfilerCounts.h b/tools/profiler/public/ProfilerCounts.h
index cebca81e2c..bdd2ddef9a 100644
--- a/tools/profiler/public/ProfilerCounts.h
+++ b/tools/profiler/public/ProfilerCounts.h
@@ -20,6 +20,7 @@
# include "mozilla/Assertions.h"
# include "mozilla/Atomics.h"
+# include "mozilla/DataMutex.h"
class BaseProfilerCount;
void profiler_add_sampled_counter(BaseProfilerCount* aCounter);
@@ -188,13 +189,33 @@ class ProfilerCounterTotal final : public BaseProfilerCount {
public:
ProfilerCounterTotal(const char* aLabel, const char* aCategory,
const char* aDescription)
- : BaseProfilerCount(aLabel, &mCounter, &mNumber, aCategory,
- aDescription) {
+ : BaseProfilerCount(aLabel, &mCounter, &mNumber, aCategory, aDescription),
+ mRegistered(false, "ProfilerCounterTotal::mRegistered") {
// Assume we're in libxul
+ Register();
+ }
+
+ virtual ~ProfilerCounterTotal() { Unregister(); }
+
+ void Register() {
+ auto registered = mRegistered.Lock();
+ if (*registered) {
+ return;
+ }
+
+ *registered = true;
profiler_add_sampled_counter(this);
}
- virtual ~ProfilerCounterTotal() { profiler_remove_sampled_counter(this); }
+ void Unregister() {
+ auto registered = mRegistered.Lock();
+ if (!*registered) {
+ return;
+ }
+
+ *registered = false;
+ profiler_remove_sampled_counter(this);
+ }
BaseProfilerCount& operator++() {
Add(1);
@@ -208,6 +229,9 @@ class ProfilerCounterTotal final : public BaseProfilerCount {
ProfilerAtomicSigned mCounter;
ProfilerAtomicUnsigned mNumber;
+ // Using OffTheBooksMutex here because we intentionally leak memory counters
+ // if they are initialized.
+ mozilla::DataMutexBase<bool, mozilla::OffTheBooksMutex> mRegistered;
};
// Defines a counter that is sampled on each profiler tick, with a running