Remove magic number 5 in severity eventsCount

This commit is contained in:
Xiaoge Su 2020-11-01 22:13:24 -08:00
parent 8f432406f0
commit ac4bebbfad
2 changed files with 9 additions and 5 deletions

View File

@ -1039,12 +1039,11 @@ TraceEvent& TraceEvent::GetLastError() {
#endif
}
// We're cheating in counting, as in practice, we only use {10,20,30,40}.
static_assert(SevMaxUsed / 10 + 1 == 5, "Please bump eventCounts[5] to SevMaxUsed/10+1");
unsigned long TraceEvent::eventCounts[5] = {0,0,0,0,0};
unsigned long TraceEvent::eventCounts[NUM_MAJOR_LEVELS_OF_EVENTS] = {0, 0, 0, 0, 0};
unsigned long TraceEvent::CountEventsLoggedAt(Severity sev) {
return TraceEvent::eventCounts[sev/10];
ASSERT(sev <= SevMaxUsed);
return TraceEvent::eventCounts[sev/10];
}
TraceEvent& TraceEvent::backtrace(const std::string& prefix) {

View File

@ -47,6 +47,9 @@ inline static bool TRACE_SAMPLE() { return false; }
extern thread_local int g_allocation_tracing_disabled;
// Each major level of severity has 10 levels of minor levels, which are not all
// used. when the numbers of severity events in each level are counted, they are
// grouped by the major level.
enum Severity {
SevVerbose = 0,
SevSample = 1,
@ -59,6 +62,8 @@ enum Severity {
SevMax = 1000000
};
const int NUM_MAJOR_LEVELS_OF_EVENTS = SevMaxUsed / 10 + 1;
class TraceEventFields {
public:
constexpr static FileIdentifier file_identifier = 11262274;
@ -510,7 +515,7 @@ private:
void setSizeLimits();
static unsigned long eventCounts[5];
static unsigned long eventCounts[NUM_MAJOR_LEVELS_OF_EVENTS];
static thread_local bool networkThread;
bool init();