Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/xpcom/threads/PerformanceCounter.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#include "mozilla/Atomics.h"
8
#include "mozilla/Logging.h"
9
#include "mozilla/PerformanceCounter.h"
10
11
static mozilla::LazyLogModule sPerformanceCounter("PerformanceCounter");
12
#ifdef LOG
13
#undef LOG
14
#endif
15
0
#define LOG(args) MOZ_LOG(sPerformanceCounter, mozilla::LogLevel::Debug, args)
16
17
// Global counter used by PerformanceCounter CTOR via NextCounterID().
18
static Atomic<uint64_t> gNextCounterID(0);
19
20
static uint64_t
21
NextCounterID()
22
0
{
23
0
  // This can return the same value on different processes but
24
0
  // we're fine with this behavior because consumers can use a (pid, counter_id)
25
0
  // tuple to make instances globally unique in a browser session.
26
0
  return ++gNextCounterID;
27
0
}
28
29
30
// this instance is the extension for the worker
31
const DispatchCategory DispatchCategory::Worker = DispatchCategory((uint32_t)TaskCategory::Count);
32
33
PerformanceCounter::PerformanceCounter(const nsACString& aName)
34
  : mExecutionDuration(0),
35
    mTotalDispatchCount(0),
36
    mDispatchCounter(),
37
    mName(aName),
38
    mID(NextCounterID())
39
0
{
40
0
  LOG(("PerformanceCounter created with ID %" PRIu64, mID));
41
0
}
42
43
void
44
PerformanceCounter::IncrementDispatchCounter(DispatchCategory aCategory)
45
0
{
46
0
  mDispatchCounter[aCategory.GetValue()] += 1;
47
0
  mTotalDispatchCount += 1;
48
0
  LOG(("[%s][%" PRIu64 "] Total dispatch %" PRIu64, mName.get(),
49
0
      GetID(), uint64_t(mTotalDispatchCount)));
50
0
}
51
52
void
53
PerformanceCounter::IncrementExecutionDuration(uint32_t aMicroseconds)
54
0
{
55
0
  mExecutionDuration += aMicroseconds;
56
0
  LOG(("[%s][%" PRIu64 "] Total duration %" PRIu64, mName.get(),
57
0
      GetID(), uint64_t(mExecutionDuration)));
58
0
}
59
60
const DispatchCounter&
61
PerformanceCounter::GetDispatchCounter()
62
0
{
63
0
  return mDispatchCounter;
64
0
}
65
66
uint64_t
67
PerformanceCounter::GetExecutionDuration()
68
0
{
69
0
  return mExecutionDuration;
70
0
}
71
72
uint64_t
73
PerformanceCounter::GetTotalDispatchCount()
74
0
{
75
0
  return mTotalDispatchCount;
76
0
}
77
78
uint32_t
79
PerformanceCounter::GetDispatchCount(DispatchCategory aCategory)
80
0
{
81
0
  return mDispatchCounter[aCategory.GetValue()];
82
0
}
83
84
uint64_t
85
PerformanceCounter::GetID() const
86
0
{
87
0
  return mID;
88
0
}