Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/toolkit/components/backgroundhangmonitor/HangAnnotations.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/HangAnnotations.h"
8
9
#include <vector>
10
11
#include "MainThreadUtils.h"
12
#include "mozilla/DebugOnly.h"
13
#include "nsXULAppAPI.h"
14
#include "mozilla/BackgroundHangMonitor.h"
15
16
namespace mozilla {
17
18
void
19
BackgroundHangAnnotations::AddAnnotation(const nsString& aName, const int32_t aData)
20
0
{
21
0
  nsAutoString dataString;
22
0
  dataString.AppendInt(aData);
23
0
  AppendElement(HangAnnotation(aName, dataString));
24
0
}
25
26
void
27
BackgroundHangAnnotations::AddAnnotation(const nsString& aName, const double aData)
28
0
{
29
0
  nsAutoString dataString;
30
0
  dataString.AppendFloat(aData);
31
0
  AppendElement(HangAnnotation(aName, dataString));
32
0
}
33
34
void
35
BackgroundHangAnnotations::AddAnnotation(const nsString& aName, const nsString& aData)
36
0
{
37
0
  AppendElement(HangAnnotation(aName, aData));
38
0
}
39
40
void
41
BackgroundHangAnnotations::AddAnnotation(const nsString& aName, const nsCString& aData)
42
0
{
43
0
  NS_ConvertUTF8toUTF16 dataString(aData);
44
0
  AppendElement(HangAnnotation(aName, dataString));
45
0
}
46
47
void
48
BackgroundHangAnnotations::AddAnnotation(const nsString& aName, const bool aData)
49
0
{
50
0
  if (aData) {
51
0
    AppendElement(HangAnnotation(aName, NS_LITERAL_STRING("true")));
52
0
  } else {
53
0
    AppendElement(HangAnnotation(aName, NS_LITERAL_STRING("false")));
54
0
  }
55
0
}
56
57
BackgroundHangAnnotators::BackgroundHangAnnotators()
58
  : mMutex("BackgroundHangAnnotators::mMutex")
59
3
{
60
3
  MOZ_COUNT_CTOR(BackgroundHangAnnotators);
61
3
}
62
63
BackgroundHangAnnotators::~BackgroundHangAnnotators()
64
0
{
65
0
  MOZ_ASSERT(mAnnotators.empty());
66
0
  MOZ_COUNT_DTOR(BackgroundHangAnnotators);
67
0
}
68
69
bool
70
BackgroundHangAnnotators::Register(BackgroundHangAnnotator& aAnnotator)
71
0
{
72
0
  MutexAutoLock lock(mMutex);
73
0
  auto result = mAnnotators.insert(&aAnnotator);
74
0
  return result.second;
75
0
}
76
77
bool
78
BackgroundHangAnnotators::Unregister(BackgroundHangAnnotator& aAnnotator)
79
0
{
80
0
  MutexAutoLock lock(mMutex);
81
0
  DebugOnly<std::set<BackgroundHangAnnotator*>::size_type> numErased;
82
0
  numErased = mAnnotators.erase(&aAnnotator);
83
0
  MOZ_ASSERT(numErased == 1);
84
0
  return mAnnotators.empty();
85
0
}
86
87
BackgroundHangAnnotations
88
BackgroundHangAnnotators::GatherAnnotations()
89
0
{
90
0
  BackgroundHangAnnotations annotations;
91
0
  { // Scope for lock
92
0
    MutexAutoLock lock(mMutex);
93
0
    for (std::set<BackgroundHangAnnotator*>::iterator i = mAnnotators.begin(),
94
0
         e = mAnnotators.end();
95
0
         i != e; ++i) {
96
0
      (*i)->AnnotateHang(annotations);
97
0
    }
98
0
  }
99
0
  return annotations;
100
0
}
101
102
} // namespace mozilla