Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/tools/profiler/gecko/ProfilerChild.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 "GeckoProfiler.h"
8
#include "ProfilerChild.h"
9
#include "nsThreadUtils.h"
10
11
namespace mozilla {
12
13
ProfilerChild::ProfilerChild()
14
  : mThread(NS_GetCurrentThread())
15
  , mDestroyed(false)
16
0
{
17
0
  MOZ_COUNT_CTOR(ProfilerChild);
18
0
}
19
20
ProfilerChild::~ProfilerChild()
21
0
{
22
0
  MOZ_COUNT_DTOR(ProfilerChild);
23
0
}
24
25
mozilla::ipc::IPCResult
26
ProfilerChild::RecvStart(const ProfilerInitParams& params)
27
0
{
28
0
  nsTArray<const char*> filterArray;
29
0
  for (size_t i = 0; i < params.filters().Length(); ++i) {
30
0
    filterArray.AppendElement(params.filters()[i].get());
31
0
  }
32
0
33
0
  profiler_start(params.entries(), params.interval(),
34
0
                 params.features(),
35
0
                 filterArray.Elements(),
36
0
                 filterArray.Length());
37
0
38
0
  return IPC_OK();
39
0
}
40
41
mozilla::ipc::IPCResult
42
ProfilerChild::RecvEnsureStarted(const ProfilerInitParams& params)
43
0
{
44
0
  nsTArray<const char*> filterArray;
45
0
  for (size_t i = 0; i < params.filters().Length(); ++i) {
46
0
    filterArray.AppendElement(params.filters()[i].get());
47
0
  }
48
0
49
0
  profiler_ensure_started(params.entries(), params.interval(),
50
0
                          params.features(),
51
0
                          filterArray.Elements(), filterArray.Length());
52
0
53
0
  return IPC_OK();
54
0
}
55
56
mozilla::ipc::IPCResult
57
ProfilerChild::RecvStop()
58
0
{
59
0
  profiler_stop();
60
0
  return IPC_OK();
61
0
}
62
63
mozilla::ipc::IPCResult
64
ProfilerChild::RecvPause()
65
0
{
66
0
  profiler_pause();
67
0
  return IPC_OK();
68
0
}
69
70
mozilla::ipc::IPCResult
71
ProfilerChild::RecvResume()
72
0
{
73
0
  profiler_resume();
74
0
  return IPC_OK();
75
0
}
76
77
static nsCString
78
CollectProfileOrEmptyString(bool aIsShuttingDown)
79
0
{
80
0
  nsCString profileCString;
81
0
  UniquePtr<char[]> profile =
82
0
    profiler_get_profile(/* aSinceTime */ 0, aIsShuttingDown);
83
0
  if (profile) {
84
0
    profileCString = nsCString(profile.get(), strlen(profile.get()));
85
0
  } else {
86
0
    profileCString = EmptyCString();
87
0
  }
88
0
  return profileCString;
89
0
}
90
91
mozilla::ipc::IPCResult
92
ProfilerChild::RecvGatherProfile(GatherProfileResolver&& aResolve)
93
0
{
94
0
  mozilla::ipc::Shmem shmem;
95
0
  profiler_get_profile_json_into_lazily_allocated_buffer(
96
0
    [&](size_t allocationSize) -> char* {
97
0
      if (AllocShmem(allocationSize,
98
0
                     mozilla::ipc::Shmem::SharedMemory::TYPE_BASIC,
99
0
                     &shmem)) {
100
0
        return shmem.get<char>();
101
0
      }
102
0
      return nullptr;
103
0
    },
104
0
    /* aSinceTime */ 0,
105
0
    /* aIsShuttingDown */ false);
106
0
  aResolve(std::move(shmem));
107
0
  return IPC_OK();
108
0
}
109
110
void
111
ProfilerChild::ActorDestroy(ActorDestroyReason aActorDestroyReason)
112
0
{
113
0
  mDestroyed = true;
114
0
}
115
116
void
117
ProfilerChild::Destroy()
118
0
{
119
0
  if (!mDestroyed) {
120
0
    Close();
121
0
  }
122
0
}
123
124
nsCString
125
ProfilerChild::GrabShutdownProfile()
126
0
{
127
0
  return CollectProfileOrEmptyString(/* aIsShuttingDown */ true);
128
0
}
129
130
} // namespace mozilla