DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Header

Mercurial (cdf352f02ac4)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
/* -*- 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/Atomics.h"
#include "mozilla/Logging.h"
#include "mozilla/PerformanceCounter.h"

static mozilla::LazyLogModule sPerformanceCounter("PerformanceCounter");
#ifdef LOG
#  undef LOG
#endif
#define LOG(args) MOZ_LOG(sPerformanceCounter, mozilla::LogLevel::Debug, args)

// Global counter used by PerformanceCounter CTOR via NextCounterID().
static Atomic<uint64_t> gNextCounterID(0);

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;
}

// 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(),
      mName(aName),
      mID(NextCounterID()) {
  LOG(("PerformanceCounter created with ID %" PRIu64, mID));
}

void PerformanceCounter::IncrementDispatchCounter(DispatchCategory aCategory) {
  mDispatchCounter[aCategory.GetValue()] += 1;
  mTotalDispatchCount += 1;
  LOG(("[%s][%" PRIu64 "] Total dispatch %" PRIu64, mName.get(), GetID(),
       uint64_t(mTotalDispatchCount)));
}

void PerformanceCounter::IncrementExecutionDuration(uint32_t aMicroseconds) {
  mExecutionDuration += aMicroseconds;
  LOG(("[%s][%" PRIu64 "] Total duration %" PRIu64, mName.get(), GetID(),
       uint64_t(mExecutionDuration)));
}

const DispatchCounter& PerformanceCounter::GetDispatchCounter() {
  return mDispatchCounter;
}

uint64_t PerformanceCounter::GetExecutionDuration() {
  return mExecutionDuration;
}

uint64_t PerformanceCounter::GetTotalDispatchCount() {
  return mTotalDispatchCount;
}

uint32_t PerformanceCounter::GetDispatchCount(DispatchCategory aCategory) {
  return mDispatchCounter[aCategory.GetValue()];
}

uint64_t PerformanceCounter::GetID() const { return mID; }