зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1470151 - Make dumpCoverage and resetCoverage return a Promise that is resolved when the parent process and all content processes are done with dumping or resetting coverage counters. r=froydnj
--HG-- extra : rebase_source : 1c6e668346b49a409b6271b9b51b731784a57cf5
This commit is contained in:
Родитель
ef998f1b54
Коммит
2a4568f6f1
|
@ -3696,10 +3696,11 @@ ContentChild::RecvShareCodeCoverageMutex(const CrossProcessMutexHandle& aHandle)
|
|||
}
|
||||
|
||||
mozilla::ipc::IPCResult
|
||||
ContentChild::RecvDumpCodeCoverageCounters()
|
||||
ContentChild::RecvDumpCodeCoverageCounters(DumpCodeCoverageCountersResolver&& aResolver)
|
||||
{
|
||||
#ifdef MOZ_CODE_COVERAGE
|
||||
CodeCoverageHandler::DumpCounters(0);
|
||||
CodeCoverageHandler::DumpCounters();
|
||||
aResolver(/* unused */ true);
|
||||
return IPC_OK();
|
||||
#else
|
||||
MOZ_CRASH("Shouldn't receive this message in non-code coverage builds!");
|
||||
|
@ -3707,10 +3708,11 @@ ContentChild::RecvDumpCodeCoverageCounters()
|
|||
}
|
||||
|
||||
mozilla::ipc::IPCResult
|
||||
ContentChild::RecvResetCodeCoverageCounters()
|
||||
ContentChild::RecvResetCodeCoverageCounters(ResetCodeCoverageCountersResolver&& aResolver)
|
||||
{
|
||||
#ifdef MOZ_CODE_COVERAGE
|
||||
CodeCoverageHandler::ResetCounters(0);
|
||||
CodeCoverageHandler::ResetCounters();
|
||||
aResolver(/* unused */ true);
|
||||
return IPC_OK();
|
||||
#else
|
||||
MOZ_CRASH("Shouldn't receive this message in non-code coverage builds!");
|
||||
|
|
|
@ -624,10 +624,10 @@ public:
|
|||
RecvShareCodeCoverageMutex(const CrossProcessMutexHandle& aHandle) override;
|
||||
|
||||
virtual mozilla::ipc::IPCResult
|
||||
RecvDumpCodeCoverageCounters() override;
|
||||
RecvDumpCodeCoverageCounters(DumpCodeCoverageCountersResolver&& aResolver) override;
|
||||
|
||||
virtual mozilla::ipc::IPCResult
|
||||
RecvResetCodeCoverageCounters() override;
|
||||
RecvResetCodeCoverageCounters(ResetCodeCoverageCountersResolver&& aResolver) override;
|
||||
|
||||
virtual mozilla::ipc::IPCResult
|
||||
RecvSetInputEventQueueEnabled() override;
|
||||
|
|
|
@ -633,8 +633,8 @@ child:
|
|||
async SetPluginList(uint32_t pluginEpoch, PluginTag[] plugins, FakePluginTag[] fakePlugins);
|
||||
|
||||
async ShareCodeCoverageMutex(CrossProcessMutexHandle handle);
|
||||
async DumpCodeCoverageCounters();
|
||||
async ResetCodeCoverageCounters();
|
||||
async DumpCodeCoverageCounters() returns (bool unused);
|
||||
async ResetCodeCoverageCounters() returns (bool unused);
|
||||
|
||||
/*
|
||||
* IPC message to enable the input event queue on the main thread of the
|
||||
|
|
|
@ -44,7 +44,7 @@ void counters_reset() {
|
|||
|
||||
StaticAutoPtr<CodeCoverageHandler> CodeCoverageHandler::instance;
|
||||
|
||||
void CodeCoverageHandler::DumpCounters(int)
|
||||
void CodeCoverageHandler::DumpCounters()
|
||||
{
|
||||
CrossProcessMutexAutoLock lock(*CodeCoverageHandler::Get()->GetMutex());
|
||||
|
||||
|
@ -53,7 +53,12 @@ void CodeCoverageHandler::DumpCounters(int)
|
|||
printf_stderr("[CodeCoverage] Dump completed.\n");
|
||||
}
|
||||
|
||||
void CodeCoverageHandler::ResetCounters(int)
|
||||
void CodeCoverageHandler::DumpCountersSignalHandler(int)
|
||||
{
|
||||
DumpCounters();
|
||||
}
|
||||
|
||||
void CodeCoverageHandler::ResetCounters()
|
||||
{
|
||||
CrossProcessMutexAutoLock lock(*CodeCoverageHandler::Get()->GetMutex());
|
||||
|
||||
|
@ -62,20 +67,25 @@ void CodeCoverageHandler::ResetCounters(int)
|
|||
printf_stderr("[CodeCoverage] Reset completed.\n");
|
||||
}
|
||||
|
||||
void CodeCoverageHandler::ResetCountersSignalHandler(int)
|
||||
{
|
||||
ResetCounters();
|
||||
}
|
||||
|
||||
void CodeCoverageHandler::SetSignalHandlers()
|
||||
{
|
||||
#ifndef XP_WIN
|
||||
printf_stderr("[CodeCoverage] Setting handlers for process %d.\n", getpid());
|
||||
|
||||
struct sigaction dump_sa;
|
||||
dump_sa.sa_handler = CodeCoverageHandler::DumpCounters;
|
||||
dump_sa.sa_handler = CodeCoverageHandler::DumpCountersSignalHandler;
|
||||
dump_sa.sa_flags = SA_RESTART;
|
||||
sigemptyset(&dump_sa.sa_mask);
|
||||
DebugOnly<int> r1 = sigaction(SIGUSR1, &dump_sa, nullptr);
|
||||
MOZ_ASSERT(r1 == 0, "Failed to install GCOV SIGUSR1 handler");
|
||||
|
||||
struct sigaction reset_sa;
|
||||
reset_sa.sa_handler = CodeCoverageHandler::ResetCounters;
|
||||
reset_sa.sa_handler = CodeCoverageHandler::ResetCountersSignalHandler;
|
||||
reset_sa.sa_flags = SA_RESTART;
|
||||
sigemptyset(&reset_sa.sa_mask);
|
||||
DebugOnly<int> r2 = sigaction(SIGUSR2, &reset_sa, nullptr);
|
||||
|
|
|
@ -18,8 +18,10 @@ public:
|
|||
static CodeCoverageHandler* Get();
|
||||
CrossProcessMutex* GetMutex();
|
||||
CrossProcessMutexHandle GetMutexHandle(int aProcId);
|
||||
static void DumpCounters(int);
|
||||
static void ResetCounters(int);
|
||||
static void DumpCounters();
|
||||
static void DumpCountersSignalHandler(int);
|
||||
static void ResetCounters();
|
||||
static void ResetCountersSignalHandler(int);
|
||||
|
||||
private:
|
||||
CodeCoverageHandler();
|
||||
|
|
|
@ -7,9 +7,11 @@
|
|||
#include "mozilla/CodeCoverageHandler.h"
|
||||
#include "mozilla/Unused.h"
|
||||
#include "mozilla/dom/ContentParent.h"
|
||||
#include "mozilla/dom/Promise.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::dom;
|
||||
using namespace mozilla::ipc;
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsCodeCoverage,
|
||||
nsICodeCoverage)
|
||||
|
@ -22,28 +24,82 @@ nsCodeCoverage::~nsCodeCoverage()
|
|||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsCodeCoverage::DumpCounters()
|
||||
enum RequestType { Dump, Reset };
|
||||
|
||||
class ProcessCount final {
|
||||
NS_INLINE_DECL_REFCOUNTING(ProcessCount);
|
||||
|
||||
public:
|
||||
ProcessCount(uint32_t c) : mCount(c) {}
|
||||
operator uint32_t() const { return mCount; }
|
||||
ProcessCount& operator--() { mCount--; return *this; }
|
||||
|
||||
private:
|
||||
~ProcessCount() {}
|
||||
uint32_t mCount;
|
||||
};
|
||||
|
||||
nsresult Request(JSContext* cx, Promise** aPromise, RequestType requestType)
|
||||
{
|
||||
MOZ_ASSERT(XRE_IsParentProcess());
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
CodeCoverageHandler::DumpCounters(0);
|
||||
for (auto* cp : ContentParent::AllProcesses(ContentParent::eLive)) {
|
||||
Unused << cp->SendDumpCodeCoverageCounters();
|
||||
nsIGlobalObject* global = xpc::NativeGlobal(JS::CurrentGlobalOrNull(cx));
|
||||
if (NS_WARN_IF(!global)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
ErrorResult result;
|
||||
RefPtr<Promise> promise = Promise::Create(global, result);
|
||||
if (NS_WARN_IF(result.Failed())) {
|
||||
return result.StealNSResult();
|
||||
}
|
||||
|
||||
uint32_t processCount = 0;
|
||||
for (auto* cp : ContentParent::AllProcesses(ContentParent::eLive)) {
|
||||
++processCount;
|
||||
}
|
||||
|
||||
if (requestType == RequestType::Dump) {
|
||||
CodeCoverageHandler::DumpCounters();
|
||||
} else if (requestType == RequestType::Reset) {
|
||||
CodeCoverageHandler::ResetCounters();
|
||||
}
|
||||
|
||||
if (processCount == 0) {
|
||||
promise->MaybeResolveWithUndefined();
|
||||
} else {
|
||||
RefPtr<ProcessCount> processCountHolder(new ProcessCount(processCount));
|
||||
|
||||
auto resolve = [processCountHolder, promise](bool unused) {
|
||||
if (--(*processCountHolder) == 0) {
|
||||
promise->MaybeResolveWithUndefined();
|
||||
}
|
||||
};
|
||||
|
||||
auto reject = [promise](ResponseRejectReason aReason) {
|
||||
promise->MaybeReject(NS_ERROR_FAILURE);
|
||||
};
|
||||
|
||||
for (auto* cp : ContentParent::AllProcesses(ContentParent::eLive)) {
|
||||
if (requestType == RequestType::Dump) {
|
||||
cp->SendDumpCodeCoverageCounters(resolve, reject);
|
||||
} else if (requestType == RequestType::Reset) {
|
||||
cp->SendResetCodeCoverageCounters(resolve, reject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
promise.forget(aPromise);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsCodeCoverage::ResetCounters()
|
||||
NS_IMETHODIMP nsCodeCoverage::DumpCounters(JSContext *cx, Promise** aPromise)
|
||||
{
|
||||
MOZ_ASSERT(XRE_IsParentProcess());
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
CodeCoverageHandler::ResetCounters(0);
|
||||
for (auto* cp : ContentParent::AllProcesses(ContentParent::eLive)) {
|
||||
Unused << cp->SendResetCodeCoverageCounters();
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
return Request(cx, aPromise, RequestType::Dump);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsCodeCoverage::ResetCounters(JSContext *cx, Promise** aPromise)
|
||||
{
|
||||
return Request(cx, aPromise, RequestType::Reset);
|
||||
}
|
||||
|
|
|
@ -19,10 +19,12 @@ interface nsICodeCoverage : nsISupports
|
|||
/**
|
||||
* Write the coverage counters to disk.
|
||||
*/
|
||||
void dumpCounters();
|
||||
[implicit_jscontext]
|
||||
Promise dumpCounters();
|
||||
|
||||
/**
|
||||
* Reset the coverage counters to 0 (as if nothing was executed).
|
||||
*/
|
||||
void resetCounters();
|
||||
[implicit_jscontext]
|
||||
Promise resetCounters();
|
||||
};
|
||||
|
|
Загрузка…
Ссылка в новой задаче