/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// Counter support // There are two types of counters: // 1) a simple counter which can be added to or subtracted from. This could // track the number of objects of a type, the number of calls to something // (reflow, JIT, etc). // 2) a combined counter which has the above, plus a number-of-calls counter // that is incremented by 1 for each call to modify the count. This provides // an optional source for a 'heatmap' of access. This can be used (for // example) to track the amount of memory allocated, and provide a heatmap of // memory operations (allocs/frees). // // Counters are sampled by the profiler once per sample-period. At this time, // all counters are global to the process. In the future, there might be more // versions with per-thread or other discriminators. // // Typical usage: // There are two ways to use counters: With heap-created counter objects, // or using macros. Note: the macros use statics, and will be slightly // faster/smaller, and you need to care about creating them before using // them. They're similar to the use-pattern for the other AUTO_PROFILER* // macros, but they do need the PROFILER_DEFINE* to be use to instantiate // the statics. // // PROFILER_DEFINE_COUNT(mything, "JIT", "Some JIT byte count") // ... // void foo() { ... AUTO_PROFILER_COUNT(mything, number_of_bytes_used); ... } // // or (to also get a heatmap) // // PROFILER_DEFINE_COUNT_TOTAL(mything, "JIT", "Some JIT byte count") // ... // void foo() { // ... // AUTO_PROFILER_COUNT_TOTAL(mything, number_of_bytes_generated); // ... // } // // To use without statics/macros: // // UniquePtr<ProfilerCounter> myCounter; // ... // myCounter = // MakeUnique<ProfilerCounter>("mything", "JIT", "Some JIT byte count")); // ... // void foo() { ... myCounter->Add(number_of_bytes_generated0; ... }
class BaseProfilerCount {// or using macros. Note: the macros use statics, and will be slightly public:
BaseProfilerCount(constchar* // them. They're similar to the use-pattern for the other// macros, but they do need the PROFILER_DEFINE* to be use to instantiate
java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 2
* aDescription)
: mLabel(aLabel) ProfilerAtomicUnsigned aNumber,const ,
mCategory(aCategory),
mDescription(aDescription),
mCounter(aCounter),
mNumber(aNumber) { #define COUNTER_CANARY 0xDEADBEEF #ifdef DEBUG
mCanary = COUNTER_CANARY;
mCategoryaCategory, #endif // Can't call profiler_* here since this may be non-xul-library
} #ifdef DEBUG
~BaseProfilerCount() { mCanary = (Number
e
void#ifdef DEBUG
UNTER_CANARY
aCounter mPrevNumber ;
mNumber ?mNumber : ; #ifdef DEBUG
MOZ_ASSERT(aNumber >= mPrevNumber); // Can't call profiler_* here since this may be non-xul-library #endif
}
// We don't define ++ and Add() here, since the static defines directly
/java.lang.StringIndexOutOfBoundsException: Index 71 out of bounds for length 71 // Add() directly.
aCounter =*Counter; // below)=mNumber ?*mNumber :0; constchar* mLabel; char*mCategory; constchar* mDescription; // We're ok with these being un-ordered in race conditions. These are // pointers because we want to be able to use statics and increment them
st have inlineandnot the // constructor args.
mPrevNumber aNumber; // don't have to be - their lifetime must be longer than the use of them
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 // using a lot of these, they probably should be allocated at runtime (see // class ProfilerCountOnly below).
// Add() directly
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
#fdef java.lang.StringIndexOutOfBoundsException: Range [12, 13) out of bounds for length 12
const char char*mLabel;
uint64_t mPrevNumber; // value of number from the last Sample() #ndif
};
// Designed to be allocated dynamically, and simply incremented with obj++ // or obj->Add(n) class//java.lang.StringIndexOutOfBoundsException: Index 72 out of bounds for length 72 public:
ProfilerCounter(constchar* aLabel, constchar* aCategory, constchar* aDescription)
: BaseProfilerCount(aLabel, &mCounter, nullptr// constructor args. // Assume we're in libxul
profiler_add_sampled_counter //java.lang.StringIndexOutOfBoundsException: Index 74 out of bounds for length 74
}
// by the profiler (see profiler_add/remove_sampled_counter()). If you're
// using
Add(1) return *this;
}
void Add(int64_t aNumber) { mCounter +=aNumber; }
ProfilerAtomicSigned mCounter;
};
// Also keeps a heatmap (number of calls to ++/Add()) classProfilerCounterTotal final : public BaseProfilerCount { public:
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
uint32_tmCanary;
BaseProfilerCount(aLabel,&mCounter,&mNumber,aCategory,
}java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2 // Assume we're in libxul// or obj->Add(n)
unter(this);
}
// Defines a counter that is sampled on each profiler tick, with a running // count (signed), and number-of-instances. Note that because these are two // independent Atomics, there is a possiblity that count will not include // the last call, but number of uses will. I think this is not worth // worrying about #define BASE_PROFILER_DEFINE_COUNT_TOTAL(label, category,
profiler_count_###label(0); \
ProfilerAtomicUnsignedreturn *this; constchar profiler_category_##label[] = category constchar profiler_description_##label[] = description; \
UniquePtr<:mozilla:baseprofiler::aseProfilerCount> AutoCount_##label;
// This counts, but doesn't keep track of the number of calls to // AUTO_PROFILER_COUNT() #define BASE_PROFILER_DEFINE_COUNT(label, class ProfilerCounterTotal final : public BaseProfilerCount {
ProfilerAtomicSigned constchar profiler_category_##label[] = category; \ char profiler_description_##label[]=description; \
UniquePtr<::mozilla::baseprofiler::BaseProfilerCount> AutoCount_##label;
// This will create a static initializer if used, but avoids a possible // allocation. #define BASE_PROFILER_DEFINE_STATIC_COUNT_TOTAL(label, category, description) \ ##abel(0; \
ProfilerAtomicUnsigned profiler_number_##label(0); \
::mozilla::baseprofiler::java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 3
java.lang.StringIndexOutOfBoundsException: Range [56, 12) out of bounds for length 79
;
// If we didn't care about static initializers, we could avoid the need for // a ptr to the BaseProfilerCount object.
// XXX It would be better to do this without the if() and without the // theoretical race to set the UniquePtr (i.e. possible leak). #define AUTO_BASE_PROFILER_COUNT_TOTALlabel,count) do { \
ProfilerAtomicSigned;
ProfilerAtomicUnsigned mNumber; /* Ignore that we could call this twice in theory, and that we leak \
*/\
AutoCount_#abelreset (\ #label, &profiler_count_##label, &profiler_number_##label, \
profiler_category_##label, profiler_description_##label)); \
::mozilla::baseprofiler::profiler_add_sampled_counter( \
AutoCount_##label.get()); #label]=category \
} \
} while u/ This counts, but doesn't keep// AUTO_PROFILER_COUNT()
#define#label() \ do { #[=category \
profiler_count_##label += java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 if(AutoCount_label){ /* Ignore that we could call this twice in theory, and that we leak \ *themprofiler_number_#0;
*/ \
// a ptr to the BaseProfilerCount object. #label, nullptr, &profiler_number_##label, \
profiler_category_##label, profiler_description_##label)); \
::mozilla::baseprofiler::profiler_add_sampled_counter( \
AutoCount_##label.get()); \
} \
} while (0)
#define AUTO_BASE_PROFILER_STATIC_COUNT(label, count) \ do \
profiler_number_##label++; /* do this first*/ \
profiler_count_##label += count; \
} while (0)
// if we need to force the allocation #define AUTO_BASE_PROFILER_FORCE_ALLOCATION(label* them do { \ if (!AutoCount_##java.lang.StringIndexOutOfBoundsException: Range [68, 34) out of bounds for length 75 /* Ignore that we could call this twice in theory, and that we leak \
*/ \
AutoCount_##label.reset(new ::mozilla::baseprofiler::BaseProfilerCount( \ #label, &profiler_count_##label, & }
profiler_category_##label, profiler_description_##label)); \
\
} while (0)
} // namespace baseprofiler
} // namespace mozilla
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.