bug 1440673 - Summarize events to a keyed scalar r=Dexter

Telemetry Events will now be counted in the keyed scalar
"telemetry.event_counts" even if their category is not enabled for recording.

The keys will be category#method#object and a follow-up commit will expand the
process limit of the number of these from 100 to 500, configurable by pref.

Unfortunately Event Telemetry needs a special API so that an event recorded in
multiple processes will be summarized to those processes separately.

MozReview-Commit-ID: 7dKcM3SXO6r

--HG--
extra : rebase_source : 42af54472ac648165ac64bc5ab5a5a666830efe8
This commit is contained in:
Chris H-C 2018-03-16 15:56:16 -04:00
Родитель e84b79469a
Коммит e8937f9832
4 изменённых файлов: 69 добавлений и 4 удалений

Просмотреть файл

@ -1033,6 +1033,23 @@ telemetry:
record_in_processes:
- 'main'
event_counts:
bug_numbers:
- 1440673
description: >
The counts of events recorded in the process, category, method, and
object of the key, even if event recording for the category was not
enabled.
expires: never
kind: uint
keyed: true
notification_emails:
- telemetry-client-dev@mozilla.com
- chutten@mozilla.com
release_channel_collection: opt-out
record_in_processes:
- 'all'
telemetry.discarded:
accumulations:
bug_numbers:

Просмотреть файл

@ -25,6 +25,7 @@
#include "TelemetryCommon.h"
#include "TelemetryEvent.h"
#include "TelemetryEventData.h"
#include "TelemetryScalar.h"
#include "ipc/TelemetryIPCAccumulator.h"
using mozilla::StaticMutex;
@ -380,7 +381,7 @@ CanRecordEvent(const StaticMutexAutoLock& lock, const EventKey& eventKey,
}
}
return gEnabledCategories.GetEntry(GetCategory(lock, eventKey));
return true;
}
bool
@ -469,14 +470,24 @@ RecordEvent(const StaticMutexAutoLock& lock, ProcessID processType,
return RecordEventResult::ExpiredEvent;
}
// Check whether the extra keys passed are valid.
if (!CheckExtraKeysValid(*eventKey, extra)) {
return RecordEventResult::InvalidExtraKey;
}
// Check whether we can record this event.
if (!CanRecordEvent(lock, *eventKey, processType)) {
return RecordEventResult::Ok;
}
// Check whether the extra keys passed are valid.
if (!CheckExtraKeysValid(*eventKey, extra)) {
return RecordEventResult::InvalidExtraKey;
// Count the number of times this event has been recorded, even if its
// category does not have recording enabled.
TelemetryScalar::SummarizeEvent(UniqueEventName(category, method, object),
processType, eventKey->dynamic);
// Check whether this event's category has recording enabled
if (!gEnabledCategories.GetEntry(GetCategory(lock, *eventKey))) {
return RecordEventResult::Ok;
}
// Add event record.

Просмотреть файл

@ -2513,6 +2513,39 @@ TelemetryScalar::RegisterScalars(const nsACString& aCategoryName,
return NS_OK;
}
/**
* Count in Scalars how many of which events were recorded. See bug 1440673
*
* Event Telemetry unfortunately cannot use vanilla ScalarAdd because it needs
* to summarize events recorded in different processes to the
* telemetry.event_counts of the same process. Including "dynamic".
*
* @param aUniqueEventName - expected to be category#object#method
* @param aProcessType - the process of the event being summarized
* @param aDynamic - whether the event being summarized was dynamic
*/
void
TelemetryScalar::SummarizeEvent(const nsCString& aUniqueEventName,
ProcessID aProcessType, bool aDynamic)
{
MOZ_ASSERT(XRE_IsParentProcess(), "Only summarize events in the parent process");
if (!XRE_IsParentProcess()) {
return;
}
StaticMutexAutoLock lock(gTelemetryScalarsMutex);
ScalarKey scalarKey{static_cast<uint32_t>(ScalarID::TELEMETRY_EVENT_COUNTS), aDynamic};
KeyedScalar* scalar = nullptr;
nsresult rv = internal_GetKeyedScalarByEnum(lock, scalarKey, aProcessType, &scalar);
if (NS_FAILED(rv)) {
NS_WARNING("NS_FAILED getting keyed scalar telemetry.event_counts. Wut.");
return;
}
scalar->AddValue(NS_ConvertASCIItoUTF16(aUniqueEventName), 1);
}
/**
* Resets all the stored scalars. This is intended to be only used in tests.
*/

Просмотреть файл

@ -66,6 +66,10 @@ void SetMaximum(mozilla::Telemetry::ScalarID aId, const nsAString& aKey, uint32_
nsresult RegisterScalars(const nsACString& aCategoryName, JS::Handle<JS::Value> aScalarData,
bool aBuiltin, JSContext* cx);
// Event Summary
void SummarizeEvent(const nsCString& aUniqueEventName,
mozilla::Telemetry::ProcessID aProcessType, bool aDynamic);
// Only to be used for testing.
void ClearScalars();