2018-03-06 09:19:19 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "mozilla/Logging.h"
|
|
|
|
#include "mozilla/PerformanceCounter.h"
|
|
|
|
|
2020-04-07 22:10:29 +00:00
|
|
|
using mozilla::DispatchCategory;
|
|
|
|
using mozilla::DispatchCounter;
|
|
|
|
using mozilla::PerformanceCounter;
|
|
|
|
|
2018-03-06 09:19:19 +00:00
|
|
|
static mozilla::LazyLogModule sPerformanceCounter("PerformanceCounter");
|
|
|
|
#ifdef LOG
|
|
|
|
# undef LOG
|
|
|
|
#endif
|
|
|
|
#define LOG(args) MOZ_LOG(sPerformanceCounter, mozilla::LogLevel::Debug, args)
|
|
|
|
|
2018-07-27 09:44:22 +00:00
|
|
|
// Global counter used by PerformanceCounter CTOR via NextCounterID().
|
2020-04-07 22:10:29 +00:00
|
|
|
static mozilla::Atomic<uint64_t> gNextCounterID(0);
|
2018-07-27 09:44:22 +00:00
|
|
|
|
|
|
|
static uint64_t NextCounterID() {
|
|
|
|
// This can return the same value on different processes but
|
|
|
|
// we're fine with this behavior because consumers can use a (pid, counter_id)
|
|
|
|
// tuple to make instances globally unique in a browser session.
|
|
|
|
return ++gNextCounterID;
|
|
|
|
}
|
|
|
|
|
2018-03-06 09:19:19 +00:00
|
|
|
// this instance is the extension for the worker
|
|
|
|
const DispatchCategory DispatchCategory::Worker =
|
|
|
|
DispatchCategory((uint32_t)TaskCategory::Count);
|
|
|
|
|
|
|
|
PerformanceCounter::PerformanceCounter(const nsACString& aName)
|
|
|
|
: mExecutionDuration(0),
|
|
|
|
mTotalDispatchCount(0),
|
|
|
|
mDispatchCounter(),
|
2018-07-27 09:44:22 +00:00
|
|
|
mName(aName),
|
|
|
|
mID(NextCounterID()) {
|
|
|
|
LOG(("PerformanceCounter created with ID %" PRIu64, mID));
|
2018-03-06 09:19:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PerformanceCounter::IncrementDispatchCounter(DispatchCategory aCategory) {
|
|
|
|
mDispatchCounter[aCategory.GetValue()] += 1;
|
|
|
|
mTotalDispatchCount += 1;
|
2018-07-27 09:44:22 +00:00
|
|
|
LOG(("[%s][%" PRIu64 "] Total dispatch %" PRIu64, mName.get(), GetID(),
|
|
|
|
uint64_t(mTotalDispatchCount)));
|
2018-03-06 09:19:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PerformanceCounter::IncrementExecutionDuration(uint32_t aMicroseconds) {
|
|
|
|
mExecutionDuration += aMicroseconds;
|
2018-07-27 09:44:22 +00:00
|
|
|
LOG(("[%s][%" PRIu64 "] Total duration %" PRIu64, mName.get(), GetID(),
|
|
|
|
uint64_t(mExecutionDuration)));
|
2018-03-06 09:19:19 +00:00
|
|
|
}
|
|
|
|
|
2020-07-09 05:23:14 +00:00
|
|
|
const DispatchCounter& PerformanceCounter::GetDispatchCounter() const {
|
2018-03-06 09:19:19 +00:00
|
|
|
return mDispatchCounter;
|
|
|
|
}
|
|
|
|
|
2020-07-09 05:23:14 +00:00
|
|
|
uint64_t PerformanceCounter::GetExecutionDuration() const {
|
2018-03-06 09:19:19 +00:00
|
|
|
return mExecutionDuration;
|
|
|
|
}
|
|
|
|
|
2020-07-09 05:23:14 +00:00
|
|
|
uint64_t PerformanceCounter::GetTotalDispatchCount() const {
|
2018-03-06 09:19:19 +00:00
|
|
|
return mTotalDispatchCount;
|
|
|
|
}
|
|
|
|
|
2020-07-09 05:23:14 +00:00
|
|
|
uint32_t PerformanceCounter::GetDispatchCount(
|
|
|
|
DispatchCategory aCategory) const {
|
2018-03-06 09:19:19 +00:00
|
|
|
return mDispatchCounter[aCategory.GetValue()];
|
|
|
|
}
|
2018-07-27 09:44:22 +00:00
|
|
|
|
|
|
|
uint64_t PerformanceCounter::GetID() const { return mID; }
|