Skip to content

Commit

Permalink
Bug 1187760 - Add telemetry to record navigator.requestMediaKeySystem…
Browse files Browse the repository at this point in the history
…Access latency. r=edwin,vladan
  • Loading branch information
Chris Pearce committed Sep 23, 2015
1 parent 4ebdbb1 commit 1dce7bc
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 6 deletions.
7 changes: 5 additions & 2 deletions dom/base/Navigator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2841,8 +2841,11 @@ Navigator::RequestMediaKeySystemAccess(const nsAString& aKeySystem,
EME_LOG(logMsg.get());

nsCOMPtr<nsIGlobalObject> go = do_QueryInterface(mWindow);
nsRefPtr<DetailedPromise> promise = DetailedPromise::Create(go, aRv,
NS_LITERAL_CSTRING("navigator.requestMediaKeySystemAccess"));
nsRefPtr<DetailedPromise> promise =
DetailedPromise::Create(go, aRv,
NS_LITERAL_CSTRING("navigator.requestMediaKeySystemAccess"),
Telemetry::VIDEO_EME_REQUEST_SUCCESS_LATENCY_MS,
Telemetry::VIDEO_EME_REQUEST_FAILURE_LATENCY_MS);
if (aRv.Failed()) {
return nullptr;
}
Expand Down
44 changes: 43 additions & 1 deletion dom/media/eme/DetailedPromise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,24 @@ DetailedPromise::DetailedPromise(nsIGlobalObject* aGlobal,
: Promise(aGlobal)
, mName(aName)
, mResponded(false)
, mStartTime(TimeStamp::Now())
{
}

DetailedPromise::DetailedPromise(nsIGlobalObject* aGlobal,
const nsACString& aName,
Telemetry::ID aSuccessLatencyProbe,
Telemetry::ID aFailureLatencyProbe)
: DetailedPromise(aGlobal, aName)
{
mSuccessLatencyProbe.Construct(aSuccessLatencyProbe);
mFailureLatencyProbe.Construct(aFailureLatencyProbe);
}

DetailedPromise::~DetailedPromise()
{
MOZ_ASSERT(mResponded == IsPending());
MaybeReportTelemetry(Failed);
}

void
Expand All @@ -31,7 +43,7 @@ DetailedPromise::MaybeReject(nsresult aArg, const nsACString& aReason)
PromiseFlatCString(aReason).get());
EME_LOG(msg.get());

mResponded = true;
MaybeReportTelemetry(Failed);

LogToBrowserConsole(NS_ConvertUTF8toUTF16(msg));

Expand All @@ -56,5 +68,35 @@ DetailedPromise::Create(nsIGlobalObject* aGlobal,
return aRv.Failed() ? nullptr : promise.forget();
}

/* static */ already_AddRefed<DetailedPromise>
DetailedPromise::Create(nsIGlobalObject* aGlobal,
ErrorResult& aRv,
const nsACString& aName,
Telemetry::ID aSuccessLatencyProbe,
Telemetry::ID aFailureLatencyProbe)
{
nsRefPtr<DetailedPromise> promise = new DetailedPromise(aGlobal, aName, aSuccessLatencyProbe, aFailureLatencyProbe);
promise->CreateWrapper(nullptr, aRv);
return aRv.Failed() ? nullptr : promise.forget();
}

void
DetailedPromise::MaybeReportTelemetry(Status aStatus)
{
if (mResponded) {
return;
}
mResponded = true;
if (!mSuccessLatencyProbe.WasPassed() || !mFailureLatencyProbe.WasPassed()) {
return;
}
uint32_t latency = (TimeStamp::Now() - mStartTime).ToMilliseconds();
EME_LOG("%s %s latency %ums reported via telemetry", mName.get(),
((aStatus == Succeeded) ? "succcess" : "failure"), latency);
Telemetry::ID tid = (aStatus == Succeeded) ? mSuccessLatencyProbe.Value()
: mFailureLatencyProbe.Value();
Telemetry::Accumulate(tid, latency);
}

} // namespace dom
} // namespace mozilla
27 changes: 24 additions & 3 deletions dom/media/eme/DetailedPromise.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#define __DetailedPromise_h__

#include "mozilla/dom/Promise.h"
#include "mozilla/Telemetry.h"
#include "EMEUtils.h"

namespace mozilla {
Expand All @@ -22,13 +23,21 @@ class DetailedPromise : public Promise
{
public:
static already_AddRefed<DetailedPromise>
Create(nsIGlobalObject* aGlobal, ErrorResult& aRv, const nsACString& aName);
Create(nsIGlobalObject* aGlobal,
ErrorResult& aRv,
const nsACString& aName);

static already_AddRefed<DetailedPromise>
Create(nsIGlobalObject* aGlobal, ErrorResult& aRv,
const nsACString& aName,
Telemetry::ID aSuccessLatencyProbe,
Telemetry::ID aFailureLatencyProbe);

template <typename T>
void MaybeResolve(const T& aArg)
{
EME_LOG("%s promise resolved", mName.get());
mResponded = true;
MaybeReportTelemetry(Succeeded);
Promise::MaybeResolve<T>(aArg);
}

Expand All @@ -39,11 +48,23 @@ class DetailedPromise : public Promise
void MaybeReject(ErrorResult&, const nsACString& aReason);

private:
explicit DetailedPromise(nsIGlobalObject* aGlobal, const nsACString& aName);
explicit DetailedPromise(nsIGlobalObject* aGlobal,
const nsACString& aName);

explicit DetailedPromise(nsIGlobalObject* aGlobal,
const nsACString& aName,
Telemetry::ID aSuccessLatencyProbe,
Telemetry::ID aFailureLatencyProbe);
virtual ~DetailedPromise();

enum Status { Succeeded, Failed };
void MaybeReportTelemetry(Status aStatus);

nsCString mName;
bool mResponded;
TimeStamp mStartTime;
Optional<Telemetry::ID> mSuccessLatencyProbe;
Optional<Telemetry::ID> mFailureLatencyProbe;
};

} // namespace dom
Expand Down
18 changes: 18 additions & 0 deletions toolkit/components/telemetry/Histograms.json
Original file line number Diff line number Diff line change
Expand Up @@ -9383,6 +9383,24 @@
"releaseChannelCollection": "opt-out",
"description": "Reason for reporting the Adobe CDM to be unsupported. (1 = NOT_WINDOWS; 2 = WINDOWS_VERSION)"
},
"VIDEO_EME_REQUEST_SUCCESS_LATENCY_MS": {
"alert_emails": ["[email protected]"],
"expires_in_version": "50",
"kind": "exponential",
"high": "60000",
"n_buckets": 60,
"releaseChannelCollection": "opt-out",
"description": "Time spent waiting for a navigator.requestMediaKeySystemAccess call to succeed."
},
"VIDEO_EME_REQUEST_FAILURE_LATENCY_MS": {
"alert_emails": ["[email protected]"],
"expires_in_version": "50",
"kind": "exponential",
"high": "60000",
"n_buckets": 60,
"releaseChannelCollection": "opt-out",
"description": "Time spent waiting for a navigator.requestMediaKeySystemAccess call to fail."
},
"FXA_CONFIGURED": {
"alert_emails": ["[email protected]"],
"expires_in_version": "45",
Expand Down

0 comments on commit 1dce7bc

Please sign in to comment.